The prob_grad class represents densities with fixed numbers of discrete and scalar parameters and the gradient with respet to the scalar parameters.
More...
#include <prob_grad.hpp>
|
| | prob_grad (size_t num_params_r) |
| |
| | prob_grad (size_t num_params_r, std::vector< std::pair< int, int > > ¶m_ranges_i) |
| |
| virtual | ~prob_grad () |
| |
| void | set_num_params_r (size_t num_params_r) |
| |
| void | setparam_ranges_i__ (std::vector< std::pair< int, int > > param_ranges_i) |
| |
| virtual size_t | num_params_r () |
| |
| virtual size_t | num_params_i () |
| |
| std::pair< int, int > | param_range_i (size_t idx) |
| |
| void | set_param_range_i_lower (size_t idx, int low) |
| |
| void | set_param_range_i_upper (size_t idx, int up) |
| |
| int | param_range_i_lower (size_t idx) |
| |
| int | param_range_i_upper (size_t idx) |
| |
| virtual void | init (std::vector< double > ¶ms_r, std::vector< int > ¶ms_i) |
| |
| virtual double | grad_log_prob (std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::vector< double > &gradient, std::ostream *output_stream=0)=0 |
| |
| virtual double | log_prob (std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::ostream *output_stream=0)=0 |
| |
| virtual double | log_prob_star (size_t idx, int val, std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::ostream *output_stream=0) |
| |
| virtual void | write_csv (std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::ostream &o, std::ostream *output_stream=0) |
| | Write the parameters on a single line in CSV format.
|
| |
| void | finite_diff_grad (std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::vector< double > &grad, double epsilon=1e-6, std::ostream *output_stream=0) |
| | Compute the gradient using finite differences for the specified parameters, writing the result into the specified gradient, using the specified perturbation.
|
| |
| int | test_gradients (std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, double epsilon=1e-6, double error=1e-6, std::ostream &o=std::cout, std::ostream *output_stream=0) |
| | Test the grad_log_prob() function's ability to produce accurate gradients using finite differences.
|
| |
The prob_grad class represents densities with fixed numbers of discrete and scalar parameters and the gradient with respet to the scalar parameters.
Definition at line 24 of file prob_grad.hpp.
| stan::model::prob_grad::prob_grad |
( |
size_t |
num_params_r | ) |
|
|
inline |
| stan::model::prob_grad::prob_grad |
( |
size_t |
num_params_r, |
|
|
std::vector< std::pair< int, int > > & |
param_ranges_i |
|
) |
| |
|
inline |
| virtual stan::model::prob_grad::~prob_grad |
( |
| ) |
|
|
inlinevirtual |
| void stan::model::prob_grad::finite_diff_grad |
( |
std::vector< double > & |
params_r, |
|
|
std::vector< int > & |
params_i, |
|
|
std::vector< double > & |
grad, |
|
|
double |
epsilon = 1e-6, |
|
|
std::ostream * |
output_stream = 0 |
|
) |
| |
|
inline |
Compute the gradient using finite differences for the specified parameters, writing the result into the specified gradient, using the specified perturbation.
- Parameters
-
| params_r | Real-valued parameters. |
| params_i | Integer-valued parameters. |
| [out] | grad | Vector into which gradient is written. |
| epsilon | |
| [in,out] | output_stream | |
Definition at line 154 of file prob_grad.hpp.
| virtual double stan::model::prob_grad::grad_log_prob |
( |
std::vector< double > & |
params_r, |
|
|
std::vector< int > & |
params_i, |
|
|
std::vector< double > & |
gradient, |
|
|
std::ostream * |
output_stream = 0 |
|
) |
| |
|
pure virtual |
| virtual void stan::model::prob_grad::init |
( |
std::vector< double > & |
params_r, |
|
|
std::vector< int > & |
params_i |
|
) |
| |
|
inlinevirtual |
| virtual double stan::model::prob_grad::log_prob |
( |
std::vector< double > & |
params_r, |
|
|
std::vector< int > & |
params_i, |
|
|
std::ostream * |
output_stream = 0 |
|
) |
| |
|
pure virtual |
| virtual double stan::model::prob_grad::log_prob_star |
( |
size_t |
idx, |
|
|
int |
val, |
|
|
std::vector< double > & |
params_r, |
|
|
std::vector< int > & |
params_i, |
|
|
std::ostream * |
output_stream = 0 |
|
) |
| |
|
inlinevirtual |
| virtual size_t stan::model::prob_grad::num_params_i |
( |
| ) |
|
|
inlinevirtual |
| virtual size_t stan::model::prob_grad::num_params_r |
( |
| ) |
|
|
inlinevirtual |
| std::pair<int,int> stan::model::prob_grad::param_range_i |
( |
size_t |
idx | ) |
|
|
inline |
| int stan::model::prob_grad::param_range_i_lower |
( |
size_t |
idx | ) |
|
|
inline |
| int stan::model::prob_grad::param_range_i_upper |
( |
size_t |
idx | ) |
|
|
inline |
| void stan::model::prob_grad::set_num_params_r |
( |
size_t |
num_params_r | ) |
|
|
inline |
| void stan::model::prob_grad::set_param_range_i_lower |
( |
size_t |
idx, |
|
|
int |
low |
|
) |
| |
|
inline |
| void stan::model::prob_grad::set_param_range_i_upper |
( |
size_t |
idx, |
|
|
int |
up |
|
) |
| |
|
inline |
| void stan::model::prob_grad::setparam_ranges_i__ |
( |
std::vector< std::pair< int, int > > |
param_ranges_i | ) |
|
|
inline |
| int stan::model::prob_grad::test_gradients |
( |
std::vector< double > & |
params_r, |
|
|
std::vector< int > & |
params_i, |
|
|
double |
epsilon = 1e-6, |
|
|
double |
error = 1e-6, |
|
|
std::ostream & |
o = std::cout, |
|
|
std::ostream * |
output_stream = 0 |
|
) |
| |
|
inline |
Test the grad_log_prob() function's ability to produce accurate gradients using finite differences.
This shouldn't be necessary when using autodiff, but is useful for finding bugs in hand-written code (or agrad).
- Parameters
-
| params_r | Real-valued parameter vector. |
| params_i | Integer-valued parameter vector. |
| epsilon | Real-valued scalar saying how much to perturb |
| error | Real-valued scalar saying how much error to allow |
| o | Output stream for messages. params_r. Defaults to 1e-6. |
| output_stream | Stream to which Stan programs write. |
- Returns
- number of failed gradient comparisons versus allowed error, so 0 if all gradients pass
Definition at line 189 of file prob_grad.hpp.
| virtual void stan::model::prob_grad::write_csv |
( |
std::vector< double > & |
params_r, |
|
|
std::vector< int > & |
params_i, |
|
|
std::ostream & |
o, |
|
|
std::ostream * |
output_stream = 0 |
|
) |
| |
|
inlinevirtual |
Write the parameters on a single line in CSV format.
The implementation in this abstract base class writes out the free parameters as viwed by HMC. Subclasses may extend this class and override this implementation to return constrained values which may differ in both number and scale from the raw unconstrained parameters.
- Parameters
-
| params_r | Real-valued parameter vector. |
| params_i | Integer-valued parameter vector. o Stream to which CSV file is written |
| output_stream | Stream to which print statements in Stan programs are written, default is 0 |
Definition at line 130 of file prob_grad.hpp.
| size_t stan::model::prob_grad::num_params_r__ |
|
protected |
| std::vector<std::pair<int,int> > stan::model::prob_grad::param_ranges_i__ |
|
protected |
The documentation for this class was generated from the following file: