4#include "../Activation/Softmax.hpp"
31 void forward(Eigen::MatrixXd &sample_losses,
const Eigen::MatrixXd &predictions,
const Eigen::MatrixXd &labels)
const
35 _softmax->forward(out, predictions);
37 _cce->forward(sample_losses, out, labels);
47 void backward(Eigen::MatrixXd &out,
const Eigen::MatrixXd &predictions,
const Eigen::MatrixXd &labels)
const
50 int samples = predictions.rows();
52 Eigen::VectorXi class_labels(labels.rows());
53 for (
int k = 0; k < labels.rows(); ++k)
55 labels.row(k).maxCoeff(&class_labels[k]);
61 for (
int i = 0; i < samples; i++)
63 int index = class_labels(i);
78 return _softmax->_forward_output;
82 std::shared_ptr<Softmax> _softmax;
83 std::shared_ptr<CCE> _cce;
84 Eigen::MatrixXd _softmax_out;
Cross-entropy loss function with softmax activation.
Definition CCE_Softmax.hpp:14
CCESoftmax(std::shared_ptr< Softmax > softmax, std::shared_ptr< CCE > cce)
Construct a new CCESoftmax object.
Definition CCE_Softmax.hpp:22
Eigen::MatrixXd & softmax_out() const
Get the softmax output.
Definition CCE_Softmax.hpp:76
void forward(Eigen::MatrixXd &sample_losses, const Eigen::MatrixXd &predictions, const Eigen::MatrixXd &labels) const
Forward pass of the CCE loss function with softmax activation.
Definition CCE_Softmax.hpp:31
void backward(Eigen::MatrixXd &out, const Eigen::MatrixXd &predictions, const Eigen::MatrixXd &labels) const
Backward pass of the CCE loss function with softmax activation.
Definition CCE_Softmax.hpp:47
Base class for all loss functions.
Definition Loss.hpp:24
Definition Activation.hpp:6
LossType
Enum class for loss types.
Definition Loss.hpp:13