Load#

simpple.load.get_func_str(func)[source]#

Get a string representing the function

Parameters:

func (Callable) – Function object

Returns:

String representing the function

Return type:

str

simpple.load.load_parameters(path)[source]#

Load parameter dictionary from YAML file

The YAML file should contain a parameter specification consistent with parse_parameters(), either under the parameters key or at the top level. This allows users to read only the parmeters from a full model YAML file.

Parameters:

path (Path | str) – Path to a YAML file.

Returns:

Dictionary mapping parameter names to simpple.distributions.Distribution objects

Return type:

dict[str, Distribution]

simpple.load.parse_parameters(pdict)[source]#

Parse parameter distributions from a YAML dictionary

Each parameter spec is read with simpple.distributions.Distribution.from_yaml_dict()

Parameters:

pdict (dict) – Dictionary mapping parameter names to distribution specs

Returns:

Dictionary mapping parameter names to simpple.distributions.Distribution objects

Return type:

dict[str, Distribution]

simpple.load.resolve(func_str)[source]#

Resolve a function based on its name

This function tries to resolve a function based on its name. It is used by simpple.model.Model.from_yaml() to resolve the likelihood and forward model functions based on the name given in a YAML file.

If there is a dot (.) in the string, it will treat everything before the last dot as the module name and will try to import the function.

Otherwise, it loops through the globals() dictionary, the __main__ namespace, and then goes up the stack of contexts to find one with the function.

If nothing is found, a ValueError is raised.

Parameters:

func_str (str) – Name of the function

Returns:

The function object that the name refers to

Return type:

Callable

simpple.load.unparse_parameters(parameters)[source]#

Convert parameter dictionary to a YAML-compatible dictionary

Does the exact opposite from parse_parameters(). Calls simpple.distributions.Distribution.to_yaml_dict() for each parameter. (Note: this link is to the default implementation, see the docs for each class to see if it overrides it).

Parameters:

parameters (dict[str, Distribution]) – Dictionary mapping parameter names to simpple.distributions.Distribution objects

Returns:

Dictionary mapping parameter names to YAML specifications

Return type:

dict

simpple.load.write_parameters(path, parameters, overwrite=False)[source]#

Write parameters to a YAML file

Calls unparse_parameters() and dumps it to the YAML file.

Parameters: