Utils#
- simpple.utils.find_args(obj, argtype='args')[source]#
Find arguments that an object requires at initialization
Inspects the
__init__method of the object class. Used internally by models and distributions.- Parameters:
obj (Any) – Any object
argtype (str) – Type of argument desired (
"args"or"kwars")
- Returns:
List of argument names
- Return type:
list[str]
- simpple.utils.get_subclasses(cls)[source]#
Get all subclasses of a class
This is used internally when reading models and distributions from YAML.
- Parameters:
cls (type) – Class for which we want the subclasses
- Returns:
Dictionary mapping subclass names to the actual subclasses
- Return type:
dict[str, type]
- simpple.utils.make_hashable(obj)[source]#
Return an hashable version of an object
Used internally to hash and compare models and distributions.
Handles the following objects:
dict is converted to a tuple recursively
list and tuples are converted to tuples recursively
numpy arrays are converted to bytes with
.tobytes()Scipy distribution are converted to dictionaries with
scipy_dist_to_dict()and then made hashable.Any other object is returned as is
- Parameters:
obj (Any) – Object to be made hashable
- Returns:
Hashable version of the object
- Return type:
tuple | bytes | Any
- simpple.utils.scipy_dist_to_dict(dist)[source]#
Convert a scipy distribution to a dictionary
This first calls the
__dict__method and then tries to unroll arguments and keyword arguments. Used internally bymake_hashable().- Parameters:
dist – Any scipy distribution creted through scipy.stats.
- Returns:
Dictionary with the distribution attributes
- Return type:
dict