lightcurvelynx.math_nodes.scipy_random
Wrapper classes for some of scipy’s sampling functions.
Classes
A class for sampling from scipy's NumericalInversePolynomial |
|
A class that just wraps a given PDF function. |
|
A node for sampling from a given PDF function. |
|
A class that just wraps a given Log PDF function. |
|
A node for sampling from a given Log PDF function. |
|
The base class sampling from scipy.stats distributions. |
Module Contents
- class NumericalInversePolynomialFunc(dist=None, *, domain=None, seed=None, **kwargs)[source]
Bases:
lightcurvelynx.base_models.FunctionNodeA class for sampling from scipy’s NumericalInversePolynomial given a distribution function, an object with a pdf function, or a class from which to create such an object.
Note
If a class is provided, then the sampling function will create a new object (with the sampled parameters) for each sampling. This is very expensive.
- Parameters:
dist (object or class) – An object or class with either a pdf() or logpdf() method that defines the distribution from which to sample.
domain (tuple, optional) – A tuple of (min, max) values to use as bounds for the sampling. If not provided, scipy will try to infer the domain.
seed (int, optional) – The seed to use.
- set_seed(new_seed)[source]
Update the random number generator’s seed to a given value.
- Parameters:
new_seed (int) – The given seed
- compute(graph_state, rng_info=None, **kwargs)[source]
Execute the wrapped function.
The input arguments are taken from the current graph_state and the outputs are written to graph_state.
- Parameters:
graph_state (GraphState) – An object mapping graph parameters to their values. This object is modified in place as it is sampled.
rng_info (numpy.random._generator.Generator, optional) – A given numpy random number generator to use for this computation. If not provided, the function uses the node’s random number generator.
**kwargs (dict, optional) – Additional function arguments.
- Returns:
results – The result of the computation. This return value is provided so that testing functions can easily access the results.
- Return type:
any
- class SamplePDF(dist, *, domain=None, **kwargs)[source]
Bases:
NumericalInversePolynomialFuncA node for sampling from a given PDF function.
- Parameters:
dist (function, class, or object) – The pdf function from which to sample or a class/object with that function.
domain (tuple, optional) – A tuple of (min, max) values to use as bounds for the sampling. If not provided, scipy will try to infer the domain.
- class SampleLogPDF(dist, **kwargs)[source]
Bases:
NumericalInversePolynomialFuncA node for sampling from a given Log PDF function.
- Parameters:
dist (function, class, or object) – The pdf function from which to sample or a class/object with that function.
- class ScipyRandomDist(dist_name, seed=None, node_label=None, **kwargs)[source]
Bases:
lightcurvelynx.base_models.FunctionNodeThe base class sampling from scipy.stats distributions.
- sample_size
The shape of the array to generate for each sample. The actual returned value will be
(num_samples, *size). If an empty tuple will generate a single value per sample.- Type:
tuple
- params_names[source]
The names of the parameters used to create the distribution object.
- Type:
list of str
- Parameters:
dist_name (str) – The name of the distribution from which to sample.
seed (int, optional) – The seed to use.
node_label (str, optional) – An optional label for the node. If not provided, a default label will be created based on the function name and parameters.
**kwargs (dict, optional) – The parameters to use to create the distribution object.
- set_seed(new_seed)[source]
Update the random number generator’s seed to a given value.
- Parameters:
new_seed (int) – The given seed
- compute(graph_state, rng_info=None, **kwargs)[source]
Execute the wrapped function.
The input arguments are taken from the current graph_state and the outputs are written to graph_state.
- Parameters:
graph_state (GraphState) – An object mapping graph parameters to their values. This object is modified in place as it is sampled.
rng_info (numpy.random._generator.Generator, optional) – A given numpy random number generator to use for this computation. If not provided, the function uses the node’s random number generator.
**kwargs (dict, optional) – Additional function arguments.
- Returns:
results – The result of the computation. This return value is provided so that testing functions can easily access the results.
- Return type:
any
- Raises:
ValueError – is func attribute is None.