NNFS
Neural network library from scratch
Loading...
Searching...
No Matches
Sigmoid.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Activation.hpp"
4
5namespace NNFS
6{
12 class Sigmoid : public Activation
13 {
14 public:
19
26 void forward(Eigen::MatrixXd &out, const Eigen::MatrixXd &x) override
27 {
29
30 out = 1 / (1 + (-x).array().exp());
31
32 _forward_output = out;
33 }
34
41 void backward(Eigen::MatrixXd &out, const Eigen::MatrixXd &dx) override
42 {
43 out = _forward_output.array() * (1 - _forward_output.array()) * dx.array();
44 }
45
46 private:
47 Eigen::MatrixXd _forward_output; // Output data for forward pass
48 };
49} // namespace NNFS
Base class for all activation functions.
Definition Activation.hpp:24
Eigen::MatrixXd _forward_input
Definition Activation.hpp:37
Sigmoid activation function.
Definition Sigmoid.hpp:13
Sigmoid()
Construct a new Sigmoid object.
Definition Sigmoid.hpp:18
void forward(Eigen::MatrixXd &out, const Eigen::MatrixXd &x) override
Forward pass of the sigmoid activation function.
Definition Sigmoid.hpp:26
void backward(Eigen::MatrixXd &out, const Eigen::MatrixXd &dx) override
Backward pass of the sigmoid activation function.
Definition Sigmoid.hpp:41
Definition Activation.hpp:6
ActivationType
Enum class for activation types.
Definition Activation.hpp:11