lightcurvelynx.math_nodes.given_sampler
Samplers used for testing that produces precomputed results. These can be used in testing to produce known results or to use data previously sampled from another method (such as pzflow).
Classes
A FunctionNode that randomly returns True or False according |
|
A FunctionNode that returns given results for a single parameter |
|
A FunctionNode that returns randomly selected items from a given list |
|
A FunctionNode that selects a single value from a list of parameters. |
|
A FunctionNode that returns values from a table-like data, |
Module Contents
- class BinarySampler(probability, seed=None, **kwargs)[source]
Bases:
lightcurvelynx.math_nodes.np_random.NumpyRandomFuncA FunctionNode that randomly returns True or False according to a given probability. This function is particularly useful in probabilistically applying effects or making decisions in the simulation.
- compute(graph_state, rng_info=None, **kwargs)[source]
Return the given values.
- 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 GivenValueList(values, *, stateful=True, **kwargs)[source]
Bases:
lightcurvelynx.base_models.FunctionNodeA FunctionNode that returns given results for a single parameter in the order in which they are provided. This node can be used as either stateful or stateless. If stateful, the node will keep track of the next index to return and will return the values in order. If stateless, the node will always return the first N values in the list.
Note
The stateful version of this node does not support parallel sampling, because it keeps track of a single index for the next value to return. If you need to use this node in parallel sampling, you should set stateful=False, but be aware that this will cause the node to always return the first N values in the list, where N is the number of samples requested, instead of iterating through the list.
- stateful
Whether this node is stateful. If True, the node will keep track of the next index to return. If False, the node will always return the first N values in the list, where N is the number of samples requested. Default: True
- Type:
bool
- compute(graph_state, rng_info=None, **kwargs)[source]
Return the given values.
- 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) – Unused in this function, but included to provide consistency with other compute functions.
**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 GivenValueSampler(values, weights=None, seed=None, **kwargs)[source]
Bases:
lightcurvelynx.math_nodes.np_random.NumpyRandomFuncA FunctionNode that returns randomly selected items from a given list with replacement.
Note that this node does not support parameterized (chained) inputs. If you need to select from a list of parameterized inputs, use the RandomChoiceNode.
- values[source]
The values to select from. If an integer is provided, it is treated as a range from 0 to that value - 1.
- Type:
int, list, or numpy.ndarray
- _weights
The weights for each value, if provided. If None, all values are equally likely.
- Type:
numpy.ndarray, optional
- compute(graph_state, rng_info=None, **kwargs)[source]
Return the given values.
- 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 GivenValueSelector(values, index, **kwargs)[source]
Bases:
lightcurvelynx.base_models.FunctionNodeA FunctionNode that selects a single value from a list of parameters.
- Parameters:
values (float, list, or numpy.ndarray) – The values that can be selected.
index (parameter) – The parameter that selects which value to return. This should return an integer index corresponding to the position in values.
**kwargs (dict, optional) – Any additional keyword arguments.
- class TableSampler(data, in_order=False, **kwargs)[source]
Bases:
lightcurvelynx.base_models.FunctionNodeA FunctionNode that returns values from a table-like data, including a Pandas DataFrame or AstroPy Table. The results returned can be in-order (for testing) or randomly selected with replacement.
Note
This is NOT a stateful node. When in_order=True the node will always return the first N rows of the table, where N is the number of samples requested.
- Parameters:
data (pandas.DataFrame, astropy.table.Table, or dict) – The object containing the data to sample.
in_order (bool) – Return the given data in order of the rows (True). If False, performs random sampling with replacement. Default: False
- data
The object containing the data to sample.
- Type:
astropy.table.Table
- in_order[source]
Return the given data in order of the rows (True). If False, performs random sampling with replacement. Default: False
- Type:
bool
- num_values
The total number of items from which to draw the data.
- Type:
int
- compute(graph_state, rng_info=None, **kwargs)[source]
Return the given values.
- 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