gwkokab.analysis.core.utils¶
Classes¶
Helper class that provides a standard way to create an ABC using |
|
Mixin class that provides a random number generator key and seed management for |
|
Helper class that provides a standard way to create an ABC using |
Functions¶
|
Converts a structured array to a 2D array. |
|
Reads attributes from a specified dataset in an HDF5 file. |
|
Reads data from an HDF5 file at the specified dataset path. |
|
Converts a 2D array to a structured array with given field names. |
|
Writes data to an HDF5 file at the specified dataset path, with optional |
Module Contents¶
- class gwkokab.analysis.core.utils.IdentitySampleTransformer¶
Bases:
SampleTransformerHelper class that provides a standard way to create an ABC using inheritance.
- log_abs_det_jacobian(samples: numpy.ndarray, transformed_samples: numpy.ndarray) numpy.ndarray¶
Compute the log absolute determinant of the Jacobian of the transformation.
- Parameters:
samples (np.ndarray) – The original samples before transformation.
transformed_samples (np.ndarray) – The transformed samples after applying the transformation.
- Returns:
The log absolute determinant of the Jacobian for each sample.
- Return type:
np.ndarray
- transform(samples: numpy.ndarray) numpy.ndarray¶
Transform the input samples to a new coordinate system.
- Parameters:
samples (np.ndarray) – The input samples to be transformed.
- Returns:
The transformed samples.
- Return type:
np.ndarray
- class gwkokab.analysis.core.utils.PRNGKeyMixin¶
Mixin class that provides a random number generator key and seed management for classes that require random number generation.
This mixin allows classes to initialize a random key based on a seed and provides a property to access the current random key, which is automatically split to ensure independent random streams across different parts of the code.
- property rng_key: jaxtyping.PRNGKeyArray¶
Accessor for the current random number generator key.
Each call to this property will split the key and return a new subkey, ensuring that different parts of the code can use independent random keys without interfering with each other.
- Returns:
A new random key generated by splitting the current key.
- Return type:
PRNGKeyArray
- class gwkokab.analysis.core.utils.SampleTransformer¶
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- check(samples: numpy.ndarray, transformed_samples: numpy.ndarray) numpy.ndarray¶
Additional checks for the transformation, such as ensuring that the transformed samples are within expected bounds.
- abstractmethod log_abs_det_jacobian(samples: numpy.ndarray, transformed_samples: numpy.ndarray) numpy.ndarray¶
Compute the log absolute determinant of the Jacobian of the transformation.
- Parameters:
samples (np.ndarray) – The original samples before transformation.
transformed_samples (np.ndarray) – The transformed samples after applying the transformation.
- Returns:
The log absolute determinant of the Jacobian for each sample.
- Return type:
np.ndarray
- abstractmethod transform(samples: numpy.ndarray) numpy.ndarray¶
Transform the input samples to a new coordinate system.
- Parameters:
samples (np.ndarray) – The input samples to be transformed.
- Returns:
The transformed samples.
- Return type:
np.ndarray
- gwkokab.analysis.core.utils.from_structured(data: numpy.ndarray) tuple[numpy.ndarray, collections.abc.Sequence[str]]¶
Converts a structured array to a 2D array.
- gwkokab.analysis.core.utils.read_attrs_from_hdf5(target: str | h5py.File | h5py.Group, dataset_path: str) dict¶
Reads attributes from a specified dataset in an HDF5 file.
- Parameters:
- Returns:
A dictionary containing the attributes of the specified dataset.
- Return type:
- Raises:
ValueError – If the specified dataset_path does not exist in the HDF5 file.
- gwkokab.analysis.core.utils.read_from_hdf5(target: str | h5py.File | h5py.Group, dataset_path: str) numpy.ndarray¶
Reads data from an HDF5 file at the specified dataset path.
- Parameters:
- Returns:
The data read from the specified dataset in the HDF5 file.
- Return type:
np.ndarray
- Raises:
ValueError – If the specified dataset_path does not exist in the HDF5 file.
- gwkokab.analysis.core.utils.to_structured(data: numpy.ndarray, names: collections.abc.Sequence[str]) numpy.ndarray¶
Converts a 2D array to a structured array with given field names.
- Parameters:
data (np.ndarray) – 2D array of shape (n_samples, n_features).
names (Sequence[str]) – List of field names for the structured array.
- Returns:
Structured array with fields named according to names.
- Return type:
np.ndarray
- gwkokab.analysis.core.utils.write_to_hdf5(target: str | h5py.File | h5py.Group, dataset_path: str, data: numpy.ndarray | None = None, attrs: dict | None = None, mode: Literal['r', 'r+', 'w', 'w-', 'a'] = 'a') None¶
Writes data to an HDF5 file at the specified dataset path, with optional attributes.
- Parameters:
target (str | h5py.File | h5py.Group) – Path or file descriptor to the HDF5 file to write to.
dataset_path (str) – The path to the dataset within the HDF5 file, by default None
data (np.ndarray | None, optional) – The data to write to the dataset, by default None
attrs (dict | None, optional) – A dictionary of attributes to set on the dataset, by default None
mode (Literal["r", "r+", "w", "w-", "a"], optional) – The mode in which to open the HDF5 file, by default “a”
- Raises:
ValueError – If either dataset_path or data is not provided when attempting to write to the HDF5 file.