swiftemulator.backend.model_parameters module

Model parameters container, contains only the parameters that are part of the differences between models (i.e. not anything about the individual scaling relations!).

class swiftemulator.backend.model_parameters.ModelParameters(model_parameters: Dict[Hashable, Dict[str, float]])[source]

Bases: object

Class that contains the parameters of the models, i.e. this does not contain any information about individual scaling relations. Performs validation on the dictionary that is given.

Parameters:
  • model_parameters – Free parameters of the underlying model. This is specified as a dictionary with the following structure: {unique_run_identifier: {parameter_name: parameter_value}}. Here the unique run identifier can be anything, but it must be unique between runs. An example could be just an integer defining a run number. The parameter names must match with what is defined in the :class:ModelSpecification, with the parameter values the specific values taken for that individual simulation run. Note that all models must have each parameter present, and this is checked at the creation time of the ModelParameters object.

  • Dict[Hashable – Free parameters of the underlying model. This is specified as a dictionary with the following structure: {unique_run_identifier: {parameter_name: parameter_value}}. Here the unique run identifier can be anything, but it must be unique between runs. An example could be just an integer defining a run number. The parameter names must match with what is defined in the :class:ModelSpecification, with the parameter values the specific values taken for that individual simulation run. Note that all models must have each parameter present, and this is checked at the creation time of the ModelParameters object.

  • Dict[str – Free parameters of the underlying model. This is specified as a dictionary with the following structure: {unique_run_identifier: {parameter_name: parameter_value}}. Here the unique run identifier can be anything, but it must be unique between runs. An example could be just an integer defining a run number. The parameter names must match with what is defined in the :class:ModelSpecification, with the parameter values the specific values taken for that individual simulation run. Note that all models must have each parameter present, and this is checked at the creation time of the ModelParameters object.

  • float]] – Free parameters of the underlying model. This is specified as a dictionary with the following structure: {unique_run_identifier: {parameter_name: parameter_value}}. Here the unique run identifier can be anything, but it must be unique between runs. An example could be just an integer defining a run number. The parameter names must match with what is defined in the :class:ModelSpecification, with the parameter values the specific values taken for that individual simulation run. Note that all models must have each parameter present, and this is checked at the creation time of the ModelParameters object.

Raises:

AttributeError – When the parameters do not match between all models.

model_parameters: Dict[Hashable, Dict[str, float]]
items()[source]
keys()[source]
values()[source]
find_closest_model(comparison_parameters: Dict[str, float], number_of_close_models: int = 1) Tuple[List[Hashable], List[Dict[str, float]]][source]

Finds the closest model currently in this instance of ModelParameters to the set of provided comparison_parameters, with the option to return the closest ‘n’ sets to the input.

Parameters:
  • comparison_parameters – Set of comparison parameters. The closest parameters, and unique indentifier, of the run within the current set of model_parameters to this point in n-dimensional parameter space will be returned.

  • Dict[str – Set of comparison parameters. The closest parameters, and unique indentifier, of the run within the current set of model_parameters to this point in n-dimensional parameter space will be returned.

  • float] – Set of comparison parameters. The closest parameters, and unique indentifier, of the run within the current set of model_parameters to this point in n-dimensional parameter space will be returned.

  • number_of_close_models – Number of closest model that will be returned

  • int – Number of closest model that will be returned

Returns:

  • unique_identifier, List[Hashable] – Unique identifier of the closest run(s).

  • closest_parameters, List[Dict[str, float]] – Model parameters of the closest run(s).

plot_model(model_specification: ModelSpecification, filename: Optional[Union[Path, str]] = None, corner_kwargs: Optional[Dict[str, Any]] = None)[source]

Plots the model parameters based on the model specification given. Can either be saved to file, or show.

Parameters:
  • model_specification – Model specification object for this set of parameters.

  • ModelSpecification – Model specification object for this set of parameters.

  • filename – Name for the file to which the plot is saved. Optional, if None it will show the image.

  • Union[str – Name for the file to which the plot is saved. Optional, if None it will show the image.

  • Path] – Name for the file to which the plot is saved. Optional, if None it will show the image.

  • optional – Name for the file to which the plot is saved. Optional, if None it will show the image.

  • corner_kwargs (Dict[str, Any], optional) – Optional key word arguments to pass to corner for the plotting.

to_yaml(filename: Path)[source]

Write the model parameters to a YAML file.

Parameters:

filename (Path) – The path to write the file to. This should be a Path object, but if it is a string it will be automatically converted.

classmethod from_yaml(filename: Path) ModelParameters[source]

Generate an instance of ModelParameters from a YAML file, written to disk using to_yaml.

Parameters:

filename (Path) – The path to read the file from. This should be a Path object, but if it is a string it will be automatically converted.

Returns:

model_parameters – Instance of ModelParameters restored from disk.

Return type:

ModelParameters

to_json(filename: Path)[source]

Write the model parameters to a JSON file. Preferred over YAML as this is much faster for large datasets.

Parameters:

filename (Path) – The path to write the file to. This should be a Path object, but if it is a string it will be automatically converted.

classmethod from_json(filename: Path) ModelParameters[source]

Generate an instance of ModelParameters from a JSON file, written to disk using to_json.

Parameters:

filename (Path) – The path to read the file from. This should be a Path object, but if it is a string it will be automatically converted.

Returns:

model_parameters – Instance of ModelParameters restored from disk.

Return type:

ModelParameters