29 void forward(Eigen::MatrixXd &out,
const Eigen::MatrixXd &x)
override
42 void backward(Eigen::MatrixXd &out,
const Eigen::MatrixXd &dx)
override
55 jacobian_matrix(j, j) = single_output(j, 0);
57 jacobian_matrix -= single_output * single_output.transpose();
59 out.row(i) = jacobian_matrix * dx.row(i).transpose();
69 void equation(Eigen::MatrixXd &out,
const Eigen::MatrixXd &x)
71 Eigen::MatrixXd expX = x;
72 for (
int i = 0; i < expX.rows(); i++)
74 double max_val = expX.row(i).maxCoeff();
75 expX.row(i) -= Eigen::VectorXd::Constant(expX.cols(), max_val);
78 expX = expX.array().exp();
80 for (
int row = 0; row < x.rows(); ++row)
82 out.row(row) = expX.row(row) / expX.row(row).sum();
Base class for all activation functions.
Definition Activation.hpp:24
Eigen::MatrixXd _forward_input
Definition Activation.hpp:37
Softmax activation function.
Definition Softmax.hpp:13
void equation(Eigen::MatrixXd &out, const Eigen::MatrixXd &x)
Softmax equation.
Definition Softmax.hpp:69
void backward(Eigen::MatrixXd &out, const Eigen::MatrixXd &dx) override
Backward pass of the softmax activation function.
Definition Softmax.hpp:42
Softmax()
Construct a new Softmax object.
Definition Softmax.hpp:21
void forward(Eigen::MatrixXd &out, const Eigen::MatrixXd &x) override
Forward pass of the softmax activation function.
Definition Softmax.hpp:29
Eigen::MatrixXd _forward_output
Definition Softmax.hpp:15
Definition Activation.hpp:6
ActivationType
Enum class for activation types.
Definition Activation.hpp:11