biogeme.parameters module¶
Centralized management of the parameters.
Parameters are organized by section. Parameters within the same section must have different names
- author:
Michel Bierlaire
- date:
Fri Dec 2 12:17:38 2022
- class biogeme.parameters.NameSectionTuple(name, section)[source]¶
Bases:
NamedTuple- Parameters:
name (str)
section (str)
-
name:
str¶ Alias for field number 0
-
section:
str¶ Alias for field number 1
- class biogeme.parameters.Parameters[source]¶
Bases:
objectClass to manage configuration parameters used throughout Biogeme.
Parameters are organized by section and identified by name. This class allows loading, accessing, modifying, and validating parameters, typically stored in a TOML file. Default values are defined centrally and added during initialization.
Attributes are stored internally in a dictionary keyed by (name, section) tuples.
- add_parameter(parameter_tuple)[source]¶
Add one parameter
- Parameters:
parameter_tuple (ParameterTuple) – tuple containing the data associated with the parameter
- static check_parameter_value(the_tuple)[source]¶
Check if the value of the parameter is valid
- Parameters:
the_tuple (ParameterTuple) – tuple to check
- Returns:
a boolean that is True if the value is valid. If not, diagnostics are provided.
- Return type:
tuple(bool, list(str))
- dump_file(file_name)[source]¶
Dump the values of the parameters in the TOML file
- Parameters:
file_name (str)
- get_param_tuple(name, section=None)[source]¶
Obtain a tuple describing the parameter
- Parameters:
name (str) – name of the parameter
section (str) – section where the parameter is relevant
- Returns:
tuple containing the name, section and value of the parameter, or None if not found
- Return type:
- get_value(name, section=None)[source]¶
Get the value of a parameter. If the parameter appears in only one section, the name of the section can be omitted.
- Parameters:
name (str) – name of the parameter
section (str) – section containing the parameter
- Return type:
bool|int|float|str
- import_document()[source]¶
Record the values of the parameters in the TOML document
- Return type:
set[str]
- parameter_exists(name)[source]¶
Checks if a parameter with the given name exists in any section.
- Parameters:
name (
str) – Name of the parameter to check.- Return type:
bool- Returns:
True if the parameter exists, False otherwise.
- property parameter_names: list[str]¶
List of all unique parameter names across sections.
- Returns:
Sorted list of parameter names.
- parameters_in_section(section_name)[source]¶
Returns the parameters in a section
- Parameters:
section_name (str) – name of the section
- Return type:
list[ParameterTuple]
- read_file(file_name)[source]¶
Read TOML file. If the file name is invalid (typically, an empty string), the default value sof the parameters are used
- Parameters:
file_name (str)
- property sections: list[str]¶
List of all defined parameter sections.
- Returns:
Sorted list of section names.
- sections_from_name(name)[source]¶
Obtain the list of sections containing the given entry
- Parameters:
name (str) – name of the parameter
- Return type:
set[str]
- set_several_parameters(dict_of_parameters)[source]¶
Sets multiple parameter values from a dictionary.
This method iterates through the provided dictionary of parameters, updating their values. If a parameter name is invalid or cannot be updated, a warning is logged instead of raising an exception.
- Parameters:
dict_of_parameters (
dict[str,bool|int|float|str]) – A dictionary where keys are parameter names and values are the values to set.- Return type:
None
- biogeme.parameters.format_comment(the_param)[source]¶
Format the content of the file, in particular the description of the parameter
- Parameters:
the_param (ParameterTuple) – parameter to format
- Returns:
formatted text
- Return type:
str