yaml_helpers module¶
- class itrails.yaml_helpers.FlowSeq(iterable=(), /)[source]¶
Bases:
listA list subclass that indicates the sequence should be represented inline in YAML.
This class is used to signal that the list is to be serialized using flow style (i.e. inline) when dumped by PyYAML.
- itrails.yaml_helpers.flow_seq_representer(dumper, data)[source]¶
Represent a FlowSeq instance in YAML flow style.
This custom representer instructs PyYAML to dump FlowSeq instances using a flow-style sequence.
- Parameters:
dumper – The YAML dumper instance.
data – The FlowSeq data to be represented.
- Returns:
A YAML node representing the sequence in flow style.
- itrails.yaml_helpers.load_config(config_file)[source]¶
Load a YAML configuration file.
Reads the YAML file specified by
config_fileand returns the parsed configuration. If an error occurs during file reading or parsing, the error is printed to stderr and the process exits.- Parameters:
config_file (str) – Path to the YAML configuration file.
- Returns:
Parsed configuration data.
- Return type:
Any
- itrails.yaml_helpers.update_best_model(best_model_yaml, optim_variables, current_optim_params, current_result, iteration)[source]¶
Update the YAML file storing the best model information.
This function compares the current log likelihood with the stored value in the YAML file and updates the file if the current value is better (i.e. higher than the stored value). It updates the following fields in the YAML data:
optimized_parameters: A dictionary mapping optimized parameter names to their adjusted values. The adjustment is done by scaling each parameter using the fixed parametermufound in the YAML file’sfixed_parametersfield. For the parameter named “r”, the value is multiplied bymu; for all other parameters, the value is divided bymu.results: A dictionary containing the best log likelihood value and the corresponding iteration number.
Note: The YAML file is expected to exist and contain the required fields (
fixed_parametersandresults). If the file does not exist or cannot be read, the function raises an error or exits.- Parameters:
best_model_yaml (str) – Path to the YAML file (e.g., “best_model.yaml”).
optim_variables (list) – List of names for optimized parameters.
current_optim_params (list) – List of current optimized parameter values corresponding to
optim_variables.current_result (float) – The current log likelihood value to compare against the stored value.
iteration (int) – The current iteration number in the model training process.