mlpack
score_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_AUGMENTED_TASKS_SCORE_IMPL_HPP
13 #define MLPACK_METHODS_AUGMENTED_TASKS_SCORE_IMPL_HPP
14 
15 // In case it hasn't been included yet.
16 #include "score.hpp"
17 
18 namespace mlpack {
19 namespace ann /* Artificial Neural Network */ {
20 namespace augmented /* Augmented neural network */ {
21 namespace scorers /* Scoring utilities for augmented */ {
22 
23 template<typename MatType>
24 double SequencePrecision(arma::field<MatType> trueOutputs,
25  arma::field<MatType> predOutputs,
26  double tol)
27 {
28  double score = 0;
29  size_t testSize = trueOutputs.n_elem;
30  if (trueOutputs.n_elem != predOutputs.n_elem)
31  {
32  std::ostringstream oss;
33  oss << "SequencePrecision(): number of predicted sequences ("
34  << predOutputs.n_elem << ") should be equal to the number "
35  << "of ground-truth sequences ("
36  << trueOutputs.n_elem << ")"
37  << std::endl;
38  throw std::invalid_argument(oss.str());
39  }
40 
41  for (size_t i = 0; i < testSize; ++i)
42  {
43  arma::vec delta = arma::vectorise(arma::abs(
44  trueOutputs.at(i) - predOutputs.at(i)));
45  double maxDelta = arma::max(delta);
46  if (maxDelta < tol)
47  {
48  score++;
49  }
50  }
51  score /= testSize;
52  return score;
53 }
54 
55 } // namespace scorers
56 } // namespace augmented
57 } // namespace ann
58 } // namespace mlpack
59 
60 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
double SequencePrecision(arma::field< MatType > trueOutputs, arma::field< MatType > predOutputs, double tol=1e-4)
Function that computes the sequences precision (number of correct sequences / number of sequences) of...
Definition: score_impl.hpp:24