Skip to content

fit.parameters

Parameter sets, the artifact which connects a fit to its report.

A parameter fit stores its results as ParameterSets: named sets of parameter values with their units. A report is created from the definition of the optimization problem, the settings of the fit and one or more of these sets, so that reporting is separate from optimizing and several sets can be compared in a single report.

ParameterSet dataclass

ParameterSet(
    sid, values, units=dict(), cost=None, provenance=None
)

A named set of parameter values.

Attributes:

Name Type Description
sid str

identifier of the set, used as its label in a report.

values dict[str, float]

value of every parameter by parameter id.

units dict[str, str | None]

unit of every parameter by parameter id, a unit of pint, the model unit if None. A set of a problem has the unit of a parameter with the unit ids of the model resolved, see OptimizationProblem.parameter_units.

cost float | None

cost of the set, if it comes from an optimization.

provenance str | None

where the set comes from, e.g. the id of an optimization.

x

x(pids, units=None)

Get the values as a vector in the order of the given parameter ids.

Parameters:

Name Type Description Default
pids Sequence[str]

parameter ids of the optimization problem.

required
units Mapping[str, str | None] | None

units to bind the values to. Missing source units assume these units; explicit units are converted or rejected.

None

Returns:

Type Description
ndarray

Vector of the values.

Raises:

Type Description
KeyError

if the set does not contain one of the parameters.

to_units

to_units(units)

Return a converted copy, retaining labels and provenance.

from_fit_parameters staticmethod

from_fit_parameters(
    parameters,
    x,
    sid,
    cost=None,
    provenance=None,
    units=None,
)

Create a parameter set from the parameters of a problem and a vector.

Parameters:

Name Type Description Default
parameters Iterable[FitParameter]

fit parameters, they provide the ids and the units.

required
x Sequence[float] | ndarray

values in the order of the parameters.

required
sid str

identifier of the set.

required
cost float | None

cost of the set.

None
provenance str | None

where the set comes from.

None
units Mapping[str, str | None] | None

the unit of a parameter by parameter id, which replaces the unit of the parameter, e.g. the resolved units of OptimizationProblem.parameter_units.

None

Returns:

Type Description
ParameterSet

The parameter set.

Raises:

Type Description
ValueError

if the number of values does not match the parameters.

from_model staticmethod

from_model(parameters, x, sid='model', units=None)

Create the parameter set of the initial values of the model.

Parameters:

Name Type Description Default
parameters Iterable[FitParameter]

fit parameters, they provide the ids and the units.

required
x ndarray

values in the order of the parameters.

required
sid str

identifier of the set.

'model'
units Mapping[str, str | None] | None

the unit of a parameter by parameter id, see from_fit_parameters.

None

Returns:

Type Description
ParameterSet

The parameter set.

to_dict

to_dict()

Convert to a dictionary of JSON serializable values.

from_dict staticmethod

from_dict(d)

Create a parameter set from a dictionary.

ParameterSets dataclass

ParameterSets(sets=list())

One or more named parameter sets.

This is what a fit writes and a report reads; the sets of a report are compared with each other, e.g., the fitted parameters against the initial values of the model.

of staticmethod

of(parameter_sets)

Accept a single set, an iterable of sets or ParameterSets.

Parameters:

Name Type Description Default
parameter_sets ParameterSets | Iterable[ParameterSet] | ParameterSet

the sets in any of the supported forms.

required

Returns:

Type Description
ParameterSets

The sets as ParameterSets.

Raises:

Type Description
ValueError

if no set is given.

to_df

to_df(units=None, *, resolved_units=None)

Get a DataFrame with one row per parameter and one column per set.

Parameters:

Name Type Description Default
units Mapping[str, str | None] | None

the unit to show for a parameter by parameter id, e.g. the unit as the user defined it, which a report shows. A parameter which is not in it has the unit of the sets, a|b when the sets disagree.

None
resolved_units Mapping[str, str | None] | None

units to convert to when display labels are model unit ids, which the global unit registry does not know.

None

Returns:

Type Description
DataFrame

The table with the columns parameter, unit and one per set.

to_json

to_json(path=None)

Store the sets as JSON.

Parameters:

Name Type Description Default
path Path | None

file to write, the JSON string is returned if it is None.

None

Returns:

Type Description
str | Path

The path or the JSON string.

from_json staticmethod

from_json(json_info)

Load the sets from a JSON file or string.

Parameters:

Name Type Description Default
json_info str | Path

path of the file or the JSON string.

required

Returns:

Type Description
ParameterSets

The parameter sets.