NNFS
Neural network library from scratch
Loading...
Searching...
No Matches
ReLU.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Activation.hpp"
4
5namespace NNFS
6{
12 class ReLU : public Activation
13 {
14 public:
19
26 void forward(Eigen::MatrixXd &out, const Eigen::MatrixXd &x) override
27 {
29
30 out = (x.array() < 0.0).select(0.0, x);
31 }
32
39 void backward(Eigen::MatrixXd &out, const Eigen::MatrixXd &dx) override
40 {
41 out = dx.array() * (_forward_input.array() > 0).cast<double>();
42 }
43 };
44} // namespace NNFS
Base class for all activation functions.
Definition Activation.hpp:24
Eigen::MatrixXd _forward_input
Definition Activation.hpp:37
ReLU activation function.
Definition ReLU.hpp:13
void backward(Eigen::MatrixXd &out, const Eigen::MatrixXd &dx) override
Backward pass of the ReLU activation function.
Definition ReLU.hpp:39
void forward(Eigen::MatrixXd &out, const Eigen::MatrixXd &x) override
Forward pass of the ReLU activation function.
Definition ReLU.hpp:26
ReLU()
Construct a new ReLU object.
Definition ReLU.hpp:18
Definition Activation.hpp:6
ActivationType
Enum class for activation types.
Definition Activation.hpp:11