30 #ifndef MODELS_NEURONS_H 31 #define MODELS_NEURONS_H 49 template<
class Derived>
55 typedef T argument_type;
56 typedef argument_type result_type;
57 static const bool zero_identity =
false;
59 Function(NeuronBase<Derived>
const*
self):m_self(static_cast<Derived const*>(self)){}
61 result_type operator()(argument_type x)
const{
62 return m_self->function(x);
64 Derived
const* m_self;
67 struct FunctionDerivative{
68 typedef T argument_type;
69 typedef argument_type result_type;
70 static const bool zero_identity =
false;
72 FunctionDerivative(NeuronBase<Derived>
const*
self):m_self(static_cast<Derived const*>(self)){}
74 result_type operator()(argument_type x)
const{
75 return m_self->functionDerivative(x);
77 Derived
const* m_self;
82 template<
class E,
class Device>
83 blas::vector_unary<E, Function<typename E::value_type> > operator()(blas::vector_expression<E, Device>
const& x)
const{
84 typedef Function<typename E::value_type> functor_type;
85 return blas::vector_unary<E, functor_type >(x(),functor_type(
this));
88 template<
class E,
class Device>
89 blas::matrix_unary<E, Function<typename E::value_type> > operator()(blas::matrix_expression<E, Device>
const& x)
const{
90 typedef Function<typename E::value_type> functor_type;
91 return blas::matrix_unary<E, functor_type >(x(),functor_type(
this));
95 template<
class E,
class Device>
96 blas::vector_unary<E, FunctionDerivative<typename E::value_type> > derivative(blas::vector_expression<E, Device>
const& x)
const{
97 typedef FunctionDerivative<typename E::value_type> functor_type;
98 return blas::vector_unary<E, functor_type >(x(),functor_type(
this));
102 template<
class E,
class Device>
103 blas::matrix_unary<E, FunctionDerivative<typename E::value_type> > derivative(blas::matrix_expression<E, Device>
const& x)
const{
104 typedef FunctionDerivative<typename E::value_type> functor_type;
105 return blas::matrix_unary<E, functor_type >(x(),functor_type(
this));
118 T
function(T x)
const{
134 T
function(T x)
const{
145 T
function(T x)
const{
157 T
function(T x)
const{
158 return std::max<T>(0,x);
176 T
function(T x)
const{
177 return x/(1+std::abs(x));
181 return sqr(1.0 - std::abs(y));
192 template<
class Neuron>
196 T
function(T x)
const{
200 else if(!m_stochastic){
201 return (1-m_probability)*m_neuron.function(x);
203 return m_neuron.function(x);
209 return (1-m_probability)*m_neuron.functionDerivative(y/ (1-m_probability));
211 return m_neuron.functionDerivative(y);
219 double m_probability;