NNFS
Neural network library from scratch
Loading...
Searching...
No Matches
Metrics.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Dense>
4#include "../Utilities/clue.hpp"
5
6namespace NNFS
7{
13 class Metrics
14 {
15 public:
23 static void accuracy(double &accuracy, const Eigen::MatrixXd &predicted,
24 const Eigen::MatrixXd &labels)
25 {
26 Eigen::VectorXi absolute_predictions;
27 onehotdecode(absolute_predictions, predicted);
28
29 Eigen::VectorXi class_labels;
30 onehotdecode(class_labels, labels);
31
32 accuracy = (absolute_predictions.array() == class_labels.array()).cast<double>().mean();
33 }
34
41 static void onehotdecode(Eigen::VectorXi &decoded, const Eigen::MatrixXd &onehot)
42 {
43 decoded.resize(onehot.rows());
44 for (int i = 0; i < onehot.rows(); ++i)
45 {
46 onehot.row(i).maxCoeff(&decoded[i]);
47 };
48 }
49 };
50} // namespace NNFS
Metrics class.
Definition Metrics.hpp:14
static void accuracy(double &accuracy, const Eigen::MatrixXd &predicted, const Eigen::MatrixXd &labels)
Calculates the accuracy of the model.
Definition Metrics.hpp:23
static void onehotdecode(Eigen::VectorXi &decoded, const Eigen::MatrixXd &onehot)
Decodes one-hot encoded data.
Definition Metrics.hpp:41
Definition Activation.hpp:6