Exemplo n.º 1
0
 virtual void update(P& z) {
   
   std::vector<double> grad_lp(this->_model.num_params_r());
   
   try {
     z.V = - this->_model.grad_log_prob(z.q, z.r, grad_lp, _err_stream);
   } catch (std::domain_error e) {
     this->_write_error_msg(_err_stream, e);
     z.V = std::numeric_limits<double>::infinity();
   }
   
   Eigen::Map<Eigen::VectorXd> eigen_g(&(grad_lp[0]), grad_lp.size());
   z.g = - eigen_g;
   
 }
 // z: layer-size x num-examples
 shared_ptr<arma::cube> grad_lq_matrix(shared_ptr<arma::mat> z,
                                       const ExampleIds& example_ids) {
   size_t n_params = param_matrices.size();
   shared_ptr<arma::cube> grad_lp( new arma::cube(z->n_rows, z->n_cols, n_params) );
   arma::uword ind = 0;
   for(auto j : example_ids) {
     for(arma::uword i=0; i<z->n_rows; ++i) {
       for(size_t k=0; k<score_funcs.size(); ++k) {
         (*grad_lp)(i, ind, k) = score_funcs[k]((*z)(i,ind), i, j);
       }
     }
     ++ind;
   }
   return grad_lp;
 }