|
bi-kappa 3.0.0
Monte Carlo particle samplers for plasma velocity and position distributions
|
Samples positions in 1D/2D/3D from a user density rho(x), rho(x,y), or rho(x,y,z). More...
#include <general_position_generator.H>
Public Types | |
| using | result_type = std::vector<RealType> |
| A position, of length dimension(). | |
| using | point_type = result_type |
| Same as result_type. | |
| using | density_function = std::function<RealType(const point_type &)> |
| The type of the density rho(x) passed to define(). | |
Public Member Functions | |
| general_position_generator () | |
| Construct an undefined generator; call define() before drawing. | |
| general_position_generator (int dimension, const point_type &lower_bounds, const point_type &upper_bounds, density_functiondensity_function density_functiondensity_function, int probe_points=4096, int max_reject_tries=200000) | |
| Construct and call define() with these arguments. | |
| void | define (int dimension, const point_type &lower_bounds, const point_type &upper_bounds, density_functiondensity_function density_functiondensity_function, int probe_points=4096, int max_reject_tries=200000) |
| Configure the sampler. | |
| void | seed (int s) |
| Reseed the internal engine and discard any variate cached from before, so that seed(s) followed by n draws gives the same values however many draws came first. | |
| void | reset () |
| Discard any state cached by the internal uniform distributions. | |
| int | dimension () const |
| 1, 2 or 3; 0 before define(). | |
| const point_type & | lowerBounds () const |
| Lower corner of the box. | |
| const point_type & | upperBounds () const |
| Upper corner of the box. | |
| RealType | densityUpperBound () const |
| The rejection envelope: the largest probed value of rho times 1.05. | |
| template<typename GeneratorType> | |
| point_type | operator() (GeneratorType &gen) const |
Draw one position from the engine gen instead of the internal one. | |
| point_type | operator() () const |
| Draw one position from the internal engine; throws as operator()(gen) does. | |
Samples positions in 1D/2D/3D from a user density rho(x), rho(x,y), or rho(x,y,z).
The generator uses rejection sampling in an axis-aligned box domain.
Definition at line 26 of file general_position_generator.H.
| using general_position_generator< RealType >::density_function = std::function<RealType(const point_type &)> |
The type of the density rho(x) passed to define().
Definition at line 32 of file general_position_generator.H.
| using general_position_generator< RealType >::point_type = result_type |
Same as result_type.
Definition at line 30 of file general_position_generator.H.
| using general_position_generator< RealType >::result_type = std::vector<RealType> |
A position, of length dimension().
Definition at line 29 of file general_position_generator.H.
|
inline |
Construct an undefined generator; call define() before drawing.
The internal engine is seeded from std::random_device.
Definition at line 36 of file general_position_generator.H.
Referenced by general_position_generator().
|
inline |
Construct and call define() with these arguments.
Definition at line 45 of file general_position_generator.H.
References general_position_generator(), define(), and dimension().
|
inline |
Configure the sampler.
| dimension | 1, 2, or 3. Fixes the length of the bounds vectors and of every returned point. |
| lower_bounds | Lower corner of the sampling box, size dimension. |
| upper_bounds | Upper corner, size dimension, each entry above its counterpart in lower_bounds. The box is a hard support: nothing outside it is ever produced. |
| density_function | Your rho(x), taking a std::vector<RealType> of length dimension. Need not be normalized; must be finite, non-negative, and positive somewhere in the box. |
| probe_points | Number of points at which rho is evaluated once, here, to estimate its maximum. The points are uniformly random in the box, drawn from a separate engine with a fixed seed, so they do not depend on seed() and are the same for every call with the same box. The largest value found, plus a 5% margin, is the rejection envelope (densityUpperBound()). A density with a spike narrow enough to fall between probes yields a silently wrong sample – see Rejection-sampler settings: probe_points, max_reject_tries. Must be > 0. |
| max_reject_tries | Candidate draws per sample before operator() throws. Must be > 0. A density concentrated in a small corner of a large box exhausts this; shrink the box instead. |
| std::invalid_argument | if dimension is outside 1-3, the bounds sizes do not match it, a bound is inverted, the callable is null, a knob is non-positive, or rho is nowhere positive in the box. |
Definition at line 84 of file general_position_generator.H.
References dimension(), and reset().
Referenced by general_position_generator(), and main().
|
inline |
The rejection envelope: the largest probed value of rho times 1.05.
Raise probe_points until this stops increasing; see Rejection-sampler settings: probe_points, max_reject_tries.
Definition at line 176 of file general_position_generator.H.
|
inline |
1, 2 or 3; 0 before define().
Definition at line 171 of file general_position_generator.H.
Referenced by general_position_generator(), and define().
|
inline |
Lower corner of the box.
Definition at line 172 of file general_position_generator.H.
|
inline |
Draw one position from the internal engine; throws as operator()(gen) does.
Definition at line 206 of file general_position_generator.H.
|
inline |
Draw one position from the engine gen instead of the internal one.
| std::runtime_error | if called before define(), if max_reject_tries is exhausted, or if rho returns a negative or non-finite value. |
Definition at line 181 of file general_position_generator.H.
|
inline |
|
inline |
Reseed the internal engine and discard any variate cached from before, so that seed(s) followed by n draws gives the same values however many draws came first.
Definition at line 157 of file general_position_generator.H.
References reset().
Referenced by main().
|
inline |
Upper corner of the box.
Definition at line 173 of file general_position_generator.H.