The class Sampler.
More...
#include "Headers/Sampler.h"
|
double | operator() (std::vector< double > &pp) |
| evaluate the function More...
|
|
double | get_chain (const int par, const int chain, const int step) |
| get the chain value More...
|
|
std::vector< std::vector< std::vector< double > > > | get_chain () |
| return the chains More...
|
|
double | get_function (const int chain, const int step) |
| get the function value More...
|
|
void | get_chain_function_acceptance (std::vector< std::vector< double >> &chains, std::vector< double > &function, std::vector< double > &acceptance, const int start=0, const int thin=1) |
| get the chain values and the function More...
|
|
void | set_chain (const int npar, const int npar_free, const int chain_size, const int nwalkers) |
| function to set the chains More...
|
|
void | set_function (const std::function< double(std::vector< double > &)> function) |
| set the function More...
|
|
void | sample_stretch_move (const int chain_size, const int nwalkers, const std::vector< std::vector< double >> start, const int seed=4241, const double aa=2, const std::string outputFile=cbl::par::defaultString) |
| sample the input function using the stretch-move algorithm on n-dimensional parameter space More...
|
|
void | sample_stretch_move_parallel (const int chain_size, const int nwalkers, const std::vector< std::vector< double >> start, const int seed=4241, const double aa=2) |
| sample the input function using the stretch-move algorithm on n-dimensional parameter space - parallel version More...
|
|
void | write_chain (const std::string dir_output, const std::string file, const int start, const int thin) |
| write the chains in an output file More...
|
|
|
| Sampler ()=default |
| default constructor
|
|
| Sampler (const int npar, const std::function< double(std::vector< double > &)> function) |
| constructor More...
|
|
| Sampler (const int npar, const int npar_free, const std::function< double(std::vector< double > &)> function) |
| constructor More...
|
|
| ~Sampler ()=default |
| default destructor
|
|
|
std::shared_ptr< random::DistributionRandomNumbers > | m_set_gz (const int seed, const double aa=2) |
| return the random generator for the stretch-move More...
|
|
void | m_initialize_chains (const std::vector< std::vector< double >> start) |
| initialize chains More...
|
|
void | m_initialize_chains_parallel (const std::vector< std::vector< double >> start) |
| initialize chains More...
|
|
void | m_sample_stretch_move_parallel_cpp (const int chain_size, const int nwalkers, const std::vector< std::vector< double >> start, const int seed=4241, const double aa=2) |
| sample the input function using the stretch-move algorithm on n-dimensional parameter space. Parallel version More...
|
|
void | m_sample_stretch_move_parallel_py (const int chain_size, const int nwalkers, const std::vector< std::vector< double >> start, const int seed=4241, const double aa=2) |
| sample the input function using the stretch-move algorithm on n-dimensional parameter space - parallel version; it is used for functions written in python More...
|
|
|
int | m_nwalkers |
| number of chains
|
|
int | m_chain_size |
| size of the chains
|
|
int | m_npar |
| number of parameters
|
|
int | m_npar_free |
| number of free parameters
|
|
std::function< double(std::vector< double > &)> | m_function |
| the function to be sampled
|
|
std::vector< double > | m_acceptance |
| chain acceptance ratio
|
|
bool | m_use_python |
| use python-defined function
|
|
std::vector< std::vector< double > > | m_function_chain |
| value of the function at sampled points
|
|
std::vector< std::vector< std::vector< double > > > | m_chains |
| the chains
|
|
The class Sampler.
This class is used to handle objects of type sample. It samples generic functions
- Examples
- sampler.cpp.
Definition at line 114 of file Sampler.h.
◆ Sampler() [1/2]
cbl::statistics::Sampler::Sampler |
( |
const int |
npar, |
|
|
const std::function< double(std::vector< double > &)> |
function |
|
) |
| |
|
inline |
constructor
- Parameters
-
npar | the number of parameters |
function | the function to sample |
Definition at line 229 of file Sampler.h.
◆ Sampler() [2/2]
cbl::statistics::Sampler::Sampler |
( |
const int |
npar, |
|
|
const int |
npar_free, |
|
|
const std::function< double(std::vector< double > &)> |
function |
|
) |
| |
|
inline |
constructor
- Parameters
-
npar | the number of parameters |
npar_free | the number of free parameters |
function | the function to sample |
Definition at line 237 of file Sampler.h.
◆ get_chain() [1/2]
std::vector<std::vector<std::vector<double> > > cbl::statistics::Sampler::get_chain |
( |
| ) |
|
|
inline |
return the chains
- Returns
- vector containing the chains
Definition at line 277 of file Sampler.h.
◆ get_chain() [2/2]
double cbl::statistics::Sampler::get_chain |
( |
const int |
par, |
|
|
const int |
chain, |
|
|
const int |
step |
|
) |
| |
|
inline |
get the chain value
- Parameters
-
par | the parameter |
chain | the chain number |
step | the step in the chain |
- Returns
- the chain value
Definition at line 270 of file Sampler.h.
◆ get_chain_function_acceptance()
void cbl::statistics::Sampler::get_chain_function_acceptance |
( |
std::vector< std::vector< double >> & |
chains, |
|
|
std::vector< double > & |
function, |
|
|
std::vector< double > & |
acceptance, |
|
|
const int |
start = 0 , |
|
|
const int |
thin = 1 |
|
) |
| |
get the chain values and the function
- Parameters
-
[out] | chains | vector containing the chains |
[out] | function | the function computed at each step of the chain |
[out] | acceptance | the acceptance rate |
| start | the starting position for each chain |
| thin | the position step
|
Definition at line 411 of file Sampler.cpp.
◆ get_function()
double cbl::statistics::Sampler::get_function |
( |
const int |
chain, |
|
|
const int |
step |
|
) |
| |
|
inline |
get the function value
- Parameters
-
chain | the chain number |
step | the step in the chain |
- Returns
- the function value
Definition at line 288 of file Sampler.h.
◆ m_initialize_chains()
void cbl::statistics::Sampler::m_initialize_chains |
( |
const std::vector< std::vector< double >> |
start | ) |
|
|
protected |
initialize chains
- Parameters
-
start | vector containing the starting position for the parameters |
Definition at line 62 of file Sampler.cpp.
◆ m_initialize_chains_parallel()
void cbl::statistics::Sampler::m_initialize_chains_parallel |
( |
const std::vector< std::vector< double >> |
start | ) |
|
|
protected |
initialize chains
- Parameters
-
start | vector containing the starting position for the parameters |
Definition at line 76 of file Sampler.cpp.
◆ m_sample_stretch_move_parallel_cpp()
void cbl::statistics::Sampler::m_sample_stretch_move_parallel_cpp |
( |
const int |
chain_size, |
|
|
const int |
nwalkers, |
|
|
const std::vector< std::vector< double >> |
start, |
|
|
const int |
seed = 4241 , |
|
|
const double |
aa = 2 |
|
) |
| |
|
protected |
sample the input function using the stretch-move algorithm on n-dimensional parameter space. Parallel version
- Parameters
-
chain_size | number of step in each chain |
nwalkers | number of parallel walkers |
start | vector containing the starting position for the parameters |
seed | the seed for random number generator |
aa | the stretch-move distribution parameter |
- Warning
- pointers cannot be used inside the input function
Definition at line 225 of file Sampler.cpp.
◆ m_sample_stretch_move_parallel_py()
void cbl::statistics::Sampler::m_sample_stretch_move_parallel_py |
( |
const int |
chain_size, |
|
|
const int |
nwalkers, |
|
|
const std::vector< std::vector< double >> |
start, |
|
|
const int |
seed = 4241 , |
|
|
const double |
aa = 2 |
|
) |
| |
|
protected |
sample the input function using the stretch-move algorithm on n-dimensional parameter space - parallel version; it is used for functions written in python
- Parameters
-
chain_size | number of step in each chain |
nwalkers | number of parallel walkers
|
start | vector containing the starting position for the parameters |
seed | the seed for random number generator |
aa | the stretch-move distribution parameter |
- Warning
- pointers cannot be used inside the input function
Definition at line 312 of file Sampler.cpp.
◆ m_set_gz()
return the random generator for the stretch-move
- Parameters
-
seed | the random generator seed |
aa | the stretch-move distribution parameter |
- Returns
- pointer to the random number generator
Definition at line 43 of file Sampler.cpp.
◆ operator()()
double cbl::statistics::Sampler::operator() |
( |
std::vector< double > & |
pp | ) |
|
|
inline |
evaluate the function
- Parameters
-
pp | the function parameters |
- Returns
- the function value and derived parameters
Definition at line 254 of file Sampler.h.
◆ sample_stretch_move()
void cbl::statistics::Sampler::sample_stretch_move |
( |
const int |
chain_size, |
|
|
const int |
nwalkers, |
|
|
const std::vector< std::vector< double >> |
start, |
|
|
const int |
seed = 4241 , |
|
|
const double |
aa = 2 , |
|
|
const std::string |
outputFile = cbl::par::defaultString |
|
) |
| |
sample the input function using the stretch-move algorithm on n-dimensional parameter space
- Parameters
-
chain_size | number of step in each chain |
nwalkers | number of parallel walkers
|
start | vector containing the starting position for the parameters |
seed | the seed for random number generator |
aa | the stretch-move distribution parameter |
outputFile | output file where the chains are written while running |
Definition at line 133 of file Sampler.cpp.
◆ sample_stretch_move_parallel()
void cbl::statistics::Sampler::sample_stretch_move_parallel |
( |
const int |
chain_size, |
|
|
const int |
nwalkers, |
|
|
const std::vector< std::vector< double >> |
start, |
|
|
const int |
seed = 4241 , |
|
|
const double |
aa = 2 |
|
) |
| |
sample the input function using the stretch-move algorithm on n-dimensional parameter space - parallel version
- Parameters
-
chain_size | number of step in each chain |
nwalkers | number of parallel walkers
|
start | vector containing the starting position for the parameters |
seed | the seed for random number generator |
aa | the stretch-move distribution parameter |
- Warning
- pointers cannot be used inside the input function
Definition at line 396 of file Sampler.cpp.
◆ set_chain()
void cbl::statistics::Sampler::set_chain |
( |
const int |
npar, |
|
|
const int |
npar_free, |
|
|
const int |
chain_size, |
|
|
const int |
nwalkers |
|
) |
| |
function to set the chains
- Parameters
-
npar | the number of parameters |
npar_free | the number of free parameters |
chain_size | number of step in each chain |
nwalkers | number of parallel walkers |
Definition at line 90 of file Sampler.cpp.
◆ set_function()
void cbl::statistics::Sampler::set_function |
( |
const std::function< double(std::vector< double > &)> |
function | ) |
|
set the function
- Parameters
-
function | the function to be sampled |
Definition at line 112 of file Sampler.cpp.
◆ write_chain()
void cbl::statistics::Sampler::write_chain |
( |
const std::string |
dir_output, |
|
|
const std::string |
file, |
|
|
const int |
start, |
|
|
const int |
thin |
|
) |
| |
write the chains in an output file
- Parameters
-
dir_output | the output directory |
file | the output file |
start | the starting position for each chain |
thin | the position step |
Definition at line 431 of file Sampler.cpp.
The documentation for this class was generated from the following files: