cubie.systemmodels.SystemValues
Classes
|
A container for numerical values used to specify ODE systems. |
- class cubie.systemmodels.SystemValues.SystemValues(values_dict, precision, defaults=None, **kwargs)[source]
Bases:
object
A container for numerical values used to specify ODE systems.
A container for numerical values such as initial state values, parameters, and observables (auxiliary variables). This object creates a corresponding array to feed to CUDA functions for compiling, and a dictionary of indices to look up that array.
- Parameters:
values_array (np.ndarray) – Array containing the numerical values.
indices_dict (dict) – Dictionary mapping parameter names to array indices.
keys_by_index (dict) – Dictionary mapping array indices to parameter names.
values_dict (dict) – Dictionary containing parameter name-value pairs.
precision (np.dtype) – Data type for the values array.
Notes
If given a list of strings, it will create a dictionary with those strings as keys and 0.0 as the default value.
You can index into this object like a dictionary or an array, i.e. values[‘key’] or values[index or slice].
- __init__(values_dict, precision, defaults=None, **kwargs)[source]
Initialize the system parameters.
Initialize the system parameters with default values, user-specified values from a dictionary, then any keyword arguments. Sets up an array of values and a dictionary mapping parameter names to indices.
- Parameters:
values_dict (dict or list of str) – Full dictionary of parameter values, or dictionary of a subset of parameter values for use with a second dictionary of default values. This argument can also be a list of strings, in which case it will create a dictionary with those strings as keys.
precision (numpy.dtype) – Data type for the values array (e.g., np.float32, np.float64).
defaults (dict, optional) – Dictionary of default parameter values, if you’re only updating a subset.
**kwargs (dict) – Additional parameter values that override both defaults and values_dict.
Notes
If the same value occurs in the dict and keyword args, the kwargs one will win.
- get_index_of_key(parameter_key, silent=False)[source]
Retrieve the index of a given key in the values_array.
- Parameters:
- Returns:
The index of the parameter in the values_array.
- Return type:
- Raises:
- get_indices(keys_or_indices, silent=False)[source]
Convert parameter identifiers to array indices.
Convert from the many possible forms that a user might specify parameters (str, int, list of either, array of indices) into an array of indices that can be passed to the CUDA functions.
- Parameters:
keys_or_indices (str, int, slice, list, or numpy.ndarray) – Parameter identifiers that can be: - Single string parameter name - Single integer index - Slice object - List of string parameter names - List of integer indices - Numpy array of indices
silent (bool, optional) – Flag determining whether to raise KeyError if a key is not found, by default False.
- Returns:
Array of parameter indices as np.int16 values.
- Return type:
- Raises:
KeyError – If a string key is not found and silent is False.
IndexError – If an index is out of bounds.
TypeError – If the input type is not supported or mixed types are provided.
- get_labels(indices)[source]
Get parameter labels corresponding to indices.
- Parameters:
indices (list or numpy.ndarray) – Array or list of indices.
- Returns:
List of labels corresponding to the provided indices.
- Return type:
- Raises:
TypeError – If indices is not a list or numpy array.
- get_values(keys_or_indices)[source]
Retrieve parameter values.
Retrieve the value(s) of the parameter(s) from the values_dict. Accepts the same range of input types as get_indices.
- Parameters:
keys_or_indices (str, int, list, or numpy.ndarray) – Parameter identifiers that can be: - Single string parameter name - Single integer index - List of string parameter names - List of integer indices - Numpy array of indices
- Returns:
The parameter value(s) requested.
- Return type:
- Raises:
KeyError – If a string key is not found in the parameters dictionary.
IndexError – If an integer index is out of bounds.
TypeError – If the input type is not supported.
- set_values(keys, values)[source]
Set parameter values.
- Parameters:
keys (str, int, list, or numpy.ndarray) – Parameter identifiers.
values (float, list, or numpy.ndarray) – Values to set for the specified parameters.
- Raises:
ValueError – If the number of keys does not match the number of values.
- update_from_dict(values_dict, silent=False, **kwargs)[source]
Update dictionary and values_array with new values.
Updates both the values_dict and the values_array.
- Parameters:
- Returns:
A set of keys that were successfully updated.
- Return type:
- Raises:
- update_param_array_and_indices()[source]
Extract values and create array and indices mapping.
Extract all values in self.values_dict and save to a numpy array with the specified precision. Also create a dict keyed by the values_dict key whose value is the index of the parameter in the created array.
Notes
The indices_dict dict will always be in the same order as the values_array, as long as the keys are extracted in the same order (insertion order is preserved in Python 3.7+).