30 #ifndef MODELS_DROPOUTLAYER_H 31 #define MODELS_DROPOUTLAYER_H 38 template <
class VectorType = RealVector>
42 typedef blas::matrix<int, blas::row_major, typename VectorType::device_type> MatrixType;
43 struct InternalState:
public State{
47 random::rng_type* mep_rng;
48 double m_dropoutProbability;
56 : m_shape(inputShape), mep_rng(&rng), m_dropoutProbability(probability){
63 {
return "DropoutLayer"; }
90 return boost::shared_ptr<State>(
new InternalState());
95 void eval(BatchInputType
const& inputs, BatchOutputType& outputs)
const{
96 outputs.resize(inputs.size1(),inputs.size2());
97 noalias(outputs) = inputs;
98 for(std::size_t i = 0; i != outputs.size1(); ++i){
99 for(std::size_t j = 0; j != outputs.size2(); ++j){
108 output.resize(input.size());
109 noalias(output) = input;
110 for(std::size_t j = 0; j != output.size(); ++j){
116 void eval(BatchInputType
const& inputs, BatchOutputType& outputs,
State& state)
const{
117 MatrixType& mask = state.
toState<InternalState>().mask;
118 outputs.resize(inputs.size1(),inputs.size2());
119 mask.resize(inputs.size1(),inputs.size2());
120 for(std::size_t i = 0; i != outputs.size1(); ++i){
121 for(std::size_t j = 0; j != outputs.size2(); ++j){
125 noalias(outputs) = inputs * mask;
130 BatchInputType
const& patterns,
131 BatchOutputType
const& outputs,
132 BatchOutputType
const& coefficients,
134 ParameterVectorType& gradient
136 SIZE_CHECK(coefficients.size1()==patterns.size1());
137 SIZE_CHECK(coefficients.size2()==patterns.size2());
141 BatchInputType
const & patterns,
142 BatchOutputType
const & outputs,
143 BatchOutputType
const & coefficients,
145 BatchInputType& derivative
147 SIZE_CHECK(coefficients.size1() == patterns.size1());
148 SIZE_CHECK(coefficients.size2() == patterns.size2());
150 MatrixType
const& mask = state.
toState<InternalState>().mask;
151 derivative.resize(coefficients.size1(),coefficients.size2());
152 noalias(derivative) = coefficients * mask;