nessai.livepoint
Functions related to creating live points and converting to other common data-types.
Module Contents
Functions
|
Add extra parameters to the live points dtype. |
Reset the extra live points parameters. |
|
|
Get a list of tuples containing the dtypes for the structured array |
|
Get an empty structured array with the extra parameters initialised. |
|
Converts live points to unstructured arrays for training. |
|
Take a list or array of parameters for a single live point |
|
Convert a numpy array to a numpy structure array with the correct fields |
|
Convert a dictionary with parameters names as keys to live points. |
|
Convert a structured array of live points to a dictionary with |
|
Convert and pandas dataframe to live points. |
|
Get an unstructured view of a live points containing certain parameters. |
- nessai.livepoint.add_extra_parameters_to_live_points(parameters, default_values=None)
Add extra parameters to the live points dtype.
Extra parameters will be included in the live points dtype that is used for constructing/converting to/from live points.
- Parameters:
- parameters: list
List of parameters to add.
- default_values: Optional[Union[List, Tuple]]
List of default values for each parameters. If not specified, default values will be set to based on :code: DEFAULT_FLOAT_VALUE in
nessai.config
.
- nessai.livepoint.reset_extra_live_points_parameters()
Reset the extra live points parameters.
- nessai.livepoint.get_dtype(names, array_dtype=None, non_sampling_parameters=True)
Get a list of tuples containing the dtypes for the structured array
- Parameters:
- nameslist of str
Names of parameters
- array_dtypeOptional[str]
dtype to use
- non_sampling_parametersbool
Indicates whether non-sampling parameters should be included.
- Returns:
- numpy.dtype
A instance of
numpy.dtype
.
- nessai.livepoint.empty_structured_array(n, names=None, dtype=None, non_sampling_parameters=True)
Get an empty structured array with the extra parameters initialised.
- Parameters:
- nint
Length of the structured array
- dtypeOptional[list]
Dtype to use. Must contain the non-sampling parameters.
- namesOptional[list]
Names of fields (excluding non-sampling parameters) to construct the dtype. Must be specified if
dtype
is not specified.- non_sampling_parametersbool
Indicates whether non-sampling parameters should be included.
- Returns:
- np.ndarray
Structured array with the all parameters initialised to their default values.
- nessai.livepoint.live_points_to_array(live_points, names=None, copy=False)
Converts live points to unstructured arrays for training.
- Parameters:
- live_pointsstructured_array
Structured array of live points
- nameslist of str or None
If None all fields in the structured array are added to the dictionary else only those included in the list are added.
- copybool
If true, returns a copy. If false, returns a view. See numpy documentation for
numpy.lib.recfunctions.structured_to_unstructured
for more details.
- Returns:
- np.ndarray
Unstructured numpy array
- nessai.livepoint.parameters_to_live_point(parameters, names, non_sampling_parameters=True)
Take a list or array of parameters for a single live point and converts them to a live point.
Returns an empty array with the correct fields if len(parameters) is zero
- Parameters:
- parameterstuple
Float point values for each parameter
- namestuple
Names for each parameter as strings
- non_sampling_parametersbool
Indicates whether non-sampling parameters should be included.
- Returns:
- structured_array
Numpy structured array with fields given by names plus logP and logL
- nessai.livepoint.numpy_array_to_live_points(array, names, non_sampling_parameters=True)
Convert a numpy array to a numpy structure array with the correct fields
- Parameters:
- arraynp.ndarray
Instance of np.ndarray to convert to a structured array
- namestuple
Names for each parameter as strings
- non_sampling_parametersbool
Indicates whether non-sampling parameters should be included.
- Returns:
- structured_array
Numpy structured array with fields given by names plus logP and logL
- nessai.livepoint.dict_to_live_points(d, non_sampling_parameters=True)
Convert a dictionary with parameters names as keys to live points.
Assumes all entries have the same length. Also, determines number of points from the first entry by checking if the value has __len__ attribute, if not the dictionary is assumed to contain a single point.
- Parameters:
- ddict
Dictionary with parameters names as keys and values that correspond to one or more parameters
- non_sampling_parametersbool
Indicates whether non-sampling parameters should be included.
- Returns:
- structured_array
Numpy structured array with fields given by names plus logP and logL
- nessai.livepoint.live_points_to_dict(live_points, names=None)
Convert a structured array of live points to a dictionary with a key per field.
- Parameters:
- live_pointsstructured_array
Array of live points
- nameslist of str or None
If None all fields in the structured array are added to the dictionary else only those included in the list are added.
- Returns:
- dict
Dictionary of live points
- nessai.livepoint.dataframe_to_live_points(df, non_sampling_parameters=True)
Convert and pandas dataframe to live points.
Adds the non-sampling parameter initialised to their defaults.
Based on this answer on Stack Exchange: https://stackoverflow.com/a/51280608
- Parameters:
- df
pandas.DataFrame
Pandas DataFrame to convert to live points
- non_sampling_parametersbool
Indicates whether non-sampling parameters should be included.
- df
- Returns:
- structured_array
Numpy structured array with fields given by column names plus logP and logL.
- nessai.livepoint.unstructured_view(x, names=None, dtype=None)
Get an unstructured view of a live points containing certain parameters.
This is quicker than converting to a unstructured array and does not create a copy of the array.
- Parameters:
- xnumpy.ndarray
Structured array.
- namesOptional[Iterable]
Iterable of parameters to include in the view. Must be specified if dtype is None.
- dtypeOptional[numpy.dtype]
Dtype for constructing the unstructured view.
- Returns:
- numpy.ndarray
View of x as an unstructured array that contains only the parameters in names/dtype. Shape is (x.size, # parameters).