Stan  2.14.0
probability, sampling & optimization
gradient.hpp
Go to the documentation of this file.
1 #ifndef STAN_MODEL_GRADIENT_HPP
2 #define STAN_MODEL_GRADIENT_HPP
3 
5 #include <stan/math/rev/mat.hpp>
7 #include <sstream>
8 #include <stdexcept>
9 
10 namespace stan {
11  namespace model {
12 
13  template <class M>
14  void gradient(const M& model,
15  const Eigen::Matrix<double, Eigen::Dynamic, 1>& x,
16  double& f,
17  Eigen::Matrix<double, Eigen::Dynamic, 1>& grad_f,
18  std::ostream* msgs = 0) {
19  stan::math::gradient(model_functional<M>(model, msgs), x, f, grad_f);
20  }
21 
22  template <class M>
23  void gradient(const M& model,
24  const Eigen::Matrix<double, Eigen::Dynamic, 1>& x,
25  double& f,
26  Eigen::Matrix<double, Eigen::Dynamic, 1>& grad_f,
28  std::stringstream ss;
29  try {
30  stan::math::gradient(model_functional<M>(model, &ss), x, f, grad_f);
31  } catch (std::exception& e) {
32  if (ss.str().length() > 0)
33  writer(ss.str());
34  throw;
35  }
36  if (ss.str().length() > 0)
37  writer(ss.str());
38  }
39 
40  }
41 }
42 #endif
Probability, optimization and sampling library.
void gradient(const M &model, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, double &f, Eigen::Matrix< double, Eigen::Dynamic, 1 > &grad_f, std::ostream *msgs=0)
Definition: gradient.hpp:14
base_writer is an abstract base class defining the interface for Stan writer callbacks.
Definition: base_writer.hpp:20
void gradient(const M &model, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, double &f, Eigen::Matrix< double, Eigen::Dynamic, 1 > &grad_f, stan::interface_callbacks::writer::base_writer &writer)
Definition: gradient.hpp:23

     [ Stan Home Page ] © 2011–2016, Stan Development Team.