# Deep network: src/layers/activation.hpp Source File

activation.hpp
Go to the documentation of this file.
#ifndef ACTIVATION_LAYER_HPP
#define ACTIVATION_LAYER_HPP
#include "layer.hpp"
#include "math.hpp"
namespace Layer{
enum ActivationMap{
Sigmoid
};
template<ActivationMap A> Real activation_map(Real);
template<ActivationMap A> Real activation_diff_map(Real);
template<ActivationMap A> class ActivationLayer:public Layer{
public:
ActivationLayer(const size_t);
~ActivationLayer(){};
Vector feed_forward(Vector x) override;
void init_nabla() override {};
Vector back_propagation(Vector e) override;
void update(Real eta) override{};
};
template<ActivationMap A>
inline
ActivationLayer<A>::ActivationLayer(size_t n):Layer(n,n){
}
template<ActivationMap A>
inline Vector
ActivationLayer<A>::feed_forward(Vector x_){
x=x_;
for(size_t i=0;i<n;++i){
y[i]=activation_map<A>(x[i]);
}
return y;
}
template<ActivationMap A>
inline Vector
ActivationLayer<A>::back_propagation(Vector e){
for(size_t i=0;i<n;++i){
d[i]=activation_diff_map<A>(x[i])*e[i];
}
return d;
}
template<>
inline Real
activation_map<Sigmoid>(Real x){
return 1.0/(1.0+exp(-x));
}
template<>
inline Real
activation_diff_map<Sigmoid>(Real x){
Real t=activation_map<Sigmoid>(x);
return t*(1.0-t);
}
}
#endif
Layer::ActivationLayer
Definition: activation.hpp:23
Layer::ActivationLayer::init_nabla
void init_nabla() override
Definition: activation.hpp:30
Layer::ActivationLayer::ActivationLayer
ActivationLayer(const size_t)
Definition: activation.hpp:39
Layer::ActivationLayer::feed_forward
Vector feed_forward(Vector x) override
Definition: activation.hpp:44
Layer::ActivationLayer::~ActivationLayer
~ActivationLayer()
Definition: activation.hpp:26
Layer::ActivationLayer::back_propagation
Vector back_propagation(Vector e) override
Definition: activation.hpp:54
Layer::ActivationLayer::update
void update(Real eta) override
Definition: activation.hpp:34
Layer::Layer::x
Vector x
Definition: layer.hpp:32
layer.hpp
math.hpp
Layer
Definition: activation.hpp:7
Layer::ActivationMap
ActivationMap
Definition: activation.hpp:9
Layer::Sigmoid
@ Sigmoid
Definition: activation.hpp:10
Layer::activation_map< Sigmoid >
Real activation_map< Sigmoid >(Real x)
Definition: activation.hpp:63
Layer::activation_diff_map< Sigmoid >
Real activation_diff_map< Sigmoid >(Real x)
Definition: activation.hpp:69
Layer::activation_map
Real activation_map(Real)
Layer::activation_diff_map
Real activation_diff_map(Real)
Math::exp
Real exp(Real x)
Definition: math.hpp:5
Real
double Real
Definition: vector.hpp:9
Vector
Real * Vector
Definition: vector.hpp:45