bi-kappa 3.0.0
Monte Carlo particle samplers for plasma velocity and position distributions
Loading...
Searching...
No Matches
general_generators.GeneralPositionGenerator Class Reference

Public Member Functions

 __init__ (self, int dimension, List[float] lower_bounds, List[float] upper_bounds, Callable density_function, int probe_points=4096, int max_reject_tries=200000)
np.ndarray __call__ (self, np.random.Generator rng)

Public Attributes

 dimension = dimension
 lower_bounds = lower
 upper_bounds = upper
 density_function = density_function
 max_reject_tries = max_reject_tries
float density_upper_bound = self._estimate_density_upper_bound(probe_points)

Static Public Attributes

int PROBE_SEED = 1337

Protected Member Functions

float _density (self, np.ndarray x)
float _estimate_density_upper_bound (self, int probe_points)

Detailed Description

Samples positions in 1D/2D/3D from a user density rho(x) by rejection sampling.

The domain is the axis-aligned box lower_bounds <= x <= upper_bounds, a hard
support.  density_function takes a list of length ``dimension`` and returns
a finite, non-negative value, positive somewhere in the box; it need not be
normalized.  The rejection envelope is the largest density found at
probe_points uniform points, drawn from a fixed seed so that two identical
constructions give the same envelope, times a 5% margin.  A peak narrow
enough to fall between the probes is undersampled without warning.  Each
call returns an array of length ``dimension``.

Definition at line 85 of file general_generators.py.

Constructor & Destructor Documentation

◆ __init__()

general_generators.GeneralPositionGenerator.__init__ ( self,
int dimension,
List[float] lower_bounds,
List[float] upper_bounds,
Callable density_function,
int probe_points = 4096,
int max_reject_tries = 200000 )

Definition at line 100 of file general_generators.py.

Member Function Documentation

◆ __call__()

np.ndarray general_generators.GeneralPositionGenerator.__call__ ( self,
np.random.Generator rng )
Generate one position, an array of length ``dimension``.

Definition at line 148 of file general_generators.py.

References _density(), density_upper_bound, dimension, lower_bounds, max_reject_tries, general_generators.GeneralVelocityGenerator.max_reject_tries, and upper_bounds.

◆ _density()

float general_generators.GeneralPositionGenerator._density ( self,
np.ndarray x )
protected

Definition at line 129 of file general_generators.py.

References density_function.

Referenced by __call__(), and _estimate_density_upper_bound().

◆ _estimate_density_upper_bound()

float general_generators.GeneralPositionGenerator._estimate_density_upper_bound ( self,
int probe_points )
protected
Largest density at probe_points uniform points in the box, with a 5% margin.

Definition at line 138 of file general_generators.py.

References _density(), dimension, lower_bounds, PROBE_SEED, and upper_bounds.

Member Data Documentation

◆ density_function

general_generators.GeneralPositionGenerator.density_function = density_function

Definition at line 122 of file general_generators.py.

Referenced by _density().

◆ density_upper_bound

float general_generators.GeneralPositionGenerator.density_upper_bound = self._estimate_density_upper_bound(probe_points)

Definition at line 125 of file general_generators.py.

Referenced by __call__().

◆ dimension

general_generators.GeneralPositionGenerator.dimension = dimension

Definition at line 119 of file general_generators.py.

Referenced by __call__(), and _estimate_density_upper_bound().

◆ lower_bounds

general_generators.GeneralPositionGenerator.lower_bounds = lower

Definition at line 120 of file general_generators.py.

Referenced by __call__(), and _estimate_density_upper_bound().

◆ max_reject_tries

general_generators.GeneralPositionGenerator.max_reject_tries = max_reject_tries

◆ PROBE_SEED

int general_generators.GeneralPositionGenerator.PROBE_SEED = 1337
static

Definition at line 98 of file general_generators.py.

Referenced by _estimate_density_upper_bound().

◆ upper_bounds

general_generators.GeneralPositionGenerator.upper_bounds = upper

Definition at line 121 of file general_generators.py.

Referenced by __call__(), and _estimate_density_upper_bound().


The documentation for this class was generated from the following file: