ParameterGroup
- class glotaran.parameter.parameter_group.ParameterGroup(label: Optional[str] = None, root_group: Optional[glotaran.parameter.parameter_group.ParameterGroup] = None)[source]
Bases:
dict
Represents are group of parameters.
Can contain other groups, creating a tree-like hierarchy.
Initialize a
ParameterGroup
instance withlabel
.- Parameters
label (str) – The label of the group.
root_group (ParameterGroup) – The root group
- Raises
ValueError – Raised if the an invalid label is given.
Attributes Summary
Label of the group.
List of full labels where the value is a NaN.
Root of the group.
Methods Summary
Add a
ParameterGroup
to the group.Add a
Parameter
to the group.Iterate over all parameter in the group and it's subgroups together with their labels.
Create a copy of the
ParameterGroup
.Create a
ParameterGroup
from apandas.DataFrame
.Create a
ParameterGroup
from a dictionary.Create a
ParameterGroup
from a list.Create a
ParameterGroup
from a list of parameter dictionaries.Create a new dictionary with keys from iterable and values set to value.
Get a
Parameter
by its label.Get the group for a parameter by it's label.
Return a arrays of all parameter labels, values and bounds.
Return the number of roots of the group.
Return a generator over all groups and their subgroups.
Check if a parameter with the given label is in the group or in a subgroup.
Create a
ParameterGroup
instance from the specs defined in a file.Format the
ParameterGroup
as markdown string.If key is not found, d is returned if given, otherwise KeyError is raised
Remove and return a (key, value) pair as a 2-tuple.
Update the
ParameterGroup
with values from a parameter history.Update the parameter values from a list of labels and values.
Insert key with a value of default if key is not in the dictionary.
Save a
ParameterGroup
to a CSV file.Create a pandas data frame from the group.
Create list of parameter dictionaries from the group.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
Update all parameters which have an expression.
Methods Documentation
- add_group(group: glotaran.parameter.parameter_group.ParameterGroup)[source]
Add a
ParameterGroup
to the group.- Parameters
group (ParameterGroup) – The group to add.
- Raises
TypeError – Raised if the group is not an instance of
ParameterGroup
.
- all(root: str | None = None, separator: str = '.') Generator[tuple[str, Parameter], None, None] [source]
Iterate over all parameter in the group and it’s subgroups together with their labels.
- clear() None. Remove all items from D.
- copy() glotaran.parameter.parameter_group.ParameterGroup [source]
Create a copy of the
ParameterGroup
.- Returns
A copy of the
ParameterGroup
.- Return type
- classmethod from_dataframe(df: pandas.core.frame.DataFrame, source: str = 'DataFrame') glotaran.parameter.parameter_group.ParameterGroup [source]
Create a
ParameterGroup
from apandas.DataFrame
.- Parameters
df (pd.DataFrame) – The source data frame.
source (str) – Optional name of the source file, used for error messages.
- Returns
The created parameter group.
- Return type
- Raises
ValueError – Raised if the columns ‘label’ or ‘value’ doesn’t exist. Also raised if the columns ‘minimum’, ‘maximum’ or ‘values’ contain non numeric values or if the columns ‘non-negative’ or ‘vary’ are no boolean.
- classmethod from_dict(parameter_dict: dict[str, dict[str, Any] | list[float | list[Any]]], label: str = None, root_group: ParameterGroup = None) ParameterGroup [source]
Create a
ParameterGroup
from a dictionary.- Parameters
- Returns
The created
ParameterGroup
- Return type
- classmethod from_list(parameter_list: list[float | list[Any]], label: str = None, root_group: ParameterGroup = None) ParameterGroup [source]
Create a
ParameterGroup
from a list.- Parameters
parameter_list (list[float | list[Any]]) – A parameter list containing parameters
label (str) – The label of the group.
root_group (ParameterGroup) – The root group
- Returns
The created
ParameterGroup
.- Return type
- classmethod from_parameter_dict_list(parameter_dict_list: list[dict[str, Any]]) ParameterGroup [source]
Create a
ParameterGroup
from a list of parameter dictionaries.- Parameters
parameter_dict_list (list[dict[str, Any]]) – A list of parameter dictionaries.
- Returns
The created
ParameterGroup
.- Return type
- fromkeys(iterable, value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(label: str) glotaran.parameter.parameter.Parameter [source]
Get a
Parameter
by its label.- Parameters
label (str) – The label of the parameter, with its path in a
ParameterGroup
prepended.- Returns
The parameter.
- Return type
- Raises
ParameterNotFoundException – Raised if no parameter with the given label exists.
- get_group_for_parameter_by_label(parameter_label: str, create_if_not_exist: bool = False) glotaran.parameter.parameter_group.ParameterGroup [source]
Get the group for a parameter by it’s label.
- Parameters
- Returns
The group of the parameter.
- Return type
- Raises
KeyError – Raised if the group does not exist and create_if_not_exist is False.
- get_label_value_and_bounds_arrays(exclude_non_vary: bool = False) tuple[list[str], np.ndarray, np.ndarray, np.ndarray] [source]
Return a arrays of all parameter labels, values and bounds.
- get_nr_roots() int [source]
Return the number of roots of the group.
- Returns
The number of roots.
- Return type
- groups() Generator[glotaran.parameter.parameter_group.ParameterGroup, None, None] [source]
Return a generator over all groups and their subgroups.
- Yields
ParameterGroup – A subgroup of
ParameterGroup
.
- has(label: str) bool [source]
Check if a parameter with the given label is in the group or in a subgroup.
- Parameters
label (str) – The label of the parameter, with its path in a
ParameterGroup
prepended.- Returns
Whether a parameter with the given label exists in the group.
- Return type
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- loader(format_name: str = None, **kwargs) ParameterGroup
Create a
ParameterGroup
instance from the specs defined in a file.- Parameters
file_name (StrOrPath) – File containing the parameter specs.
format_name (str) – Format the file is in, if not provided it will be inferred from the file extension.
**kwargs (Any) – Additional keyword arguments passes to the
load_parameters
implementation of the project io plugin.
- Returns
ParameterGroup
instance created from the file.- Return type
- markdown(float_format: str = '.3e') glotaran.utils.ipython.MarkdownStr [source]
Format the
ParameterGroup
as markdown string.This is done by recursing the nested
ParameterGroup
tree.- Parameters
float_format (str) – Format string for floating point numbers, by default “.3e”
- Returns
The markdown representation as string.
- Return type
- property missing_parameter_value_labels: list[str]
List of full labels where the value is a NaN.
This property is used to validate that all parameters have starting values.
- Returns
List full labels with missing value.
- Return type
- pop(k[, d]) v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
- popitem(/)
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- property root_group: ParameterGroup | None
Root of the group.
- Returns
The root group.
- Return type
- set_from_history(history: ParameterHistory, index: int)[source]
Update the
ParameterGroup
with values from a parameter history.- Parameters
history (ParameterHistory) – The parameter history.
index (int) – The history index.
- set_from_label_and_value_arrays(labels: list[str], values: np.ndarray)[source]
Update the parameter values from a list of labels and values.
- Parameters
- Raises
ValueError – Raised if the size of the labels does not match the stize of values.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- to_csv(filename: str, delimiter: str = ',') None [source]
Save a
ParameterGroup
to a CSV file.Warning
Deprecated use
glotaran.io.save_parameters(parameters, file_name=<parameters.csv>, format_name="csv")
instead.
- to_dataframe(as_optimized: bool = True) pandas.core.frame.DataFrame [source]
Create a pandas data frame from the group.
- Parameters
as_optimized (bool) – Whether to include properties which are the result of optimization.
- Returns
The created data frame.
- Return type
pd.DataFrame
- to_parameter_dict_list(as_optimized: bool = True) list[dict[str, Any]] [source]
Create list of parameter dictionaries from the group.
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- update_parameter_expression()[source]
Update all parameters which have an expression.
- Raises
ValueError – Raised if an expression evaluates to a non-numeric value.
- values() an object providing a view on D's values