mirror of
https://github.com/Sosokker/CPP-Neural-Network.git
synced 2025-12-18 18:14:04 +01:00
Modify Activation Func
This commit is contained in:
parent
dd9eb55d40
commit
beb966cbb6
33
src/Activation/ActivationFunc.cpp
Normal file
33
src/Activation/ActivationFunc.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <cmath>
|
||||
#include <Layers/Layers.hpp>
|
||||
#include "Activation.hpp"
|
||||
#include <Eigen/Dense>
|
||||
|
||||
class TanhActivation : public Activation {
|
||||
public:
|
||||
TanhActivation() : Activation(tanh, tanh_prime) {}
|
||||
|
||||
private:
|
||||
static Eigen::VectorXd tanh(const Eigen::VectorXd& x) {
|
||||
return x.array().tanh();
|
||||
}
|
||||
|
||||
static Eigen::VectorXd tanh_prime(const Eigen::VectorXd& x) {
|
||||
return 1 - x.array().tanh().square();
|
||||
}
|
||||
};
|
||||
|
||||
class SigmoidActivation : public Activation {
|
||||
public:
|
||||
SigmoidActivation() : Activation(sigmoid, sigmoid_prime) {}
|
||||
|
||||
private:
|
||||
static Eigen::VectorXd sigmoid(const Eigen::VectorXd& x) {
|
||||
return 1.0 / (1.0 + (-x.array()).exp());
|
||||
}
|
||||
|
||||
static Eigen::VectorXd sigmoid_prime(const Eigen::VectorXd& x) {
|
||||
Eigen::VectorXd s = sigmoid(x);
|
||||
return s.array() * (1.0 - s.array());
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user