107 derivative.resize(input.size());
115 std::size_t batchesPerThread = numBatches/numThreads;
116 std::size_t leftOver = numBatches - batchesPerThread*numThreads;
118 double minProb = 1e-100;
122 std::size_t start = t*batchesPerThread+std::min(t,leftOver);
123 std::size_t end = (t+1)*batchesPerThread+std::min(t+1,leftOver);
127 double threadError = 0;
128 boost::shared_ptr<State> state = mep_model->
createState();
129 RealVector batchDerivative;
130 RealMatrix predictions;
131 for(std::size_t i = start; i != end; ++i){
132 mep_model->
eval(m_data.
batch(i),predictions,*state);
134 threadError += sum(log(max(predictions,minProb)));
135 RealMatrix coeffs(predictions.size1(),predictions.size2(),0.0);
137 for(std::size_t j = 0; j != predictions.size1(); ++j){
138 for(std::size_t k = 0; k != predictions.size2(); ++k){
139 if(predictions(j,k) >= minProb){
140 coeffs(j,k) = 1.0/predictions(j,k);
145 m_data.
batch(i),predictions, coeffs,*state,batchDerivative
147 threadDerivative += batchDerivative;
152 error += threadError;
153 noalias(derivative) += threadDerivative;
157 error /= numElements;
158 derivative /= numElements;