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, the model unit if None.

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)

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

Returns:

Type Description
ndarray

Vector of the values.

Raises:

Type Description
KeyError

if the set does not contain one of the parameters.

from_fit_parameters staticmethod

from_fit_parameters(
    parameters, x, sid, cost=None, provenance=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

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')

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

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()

Get a DataFrame with one row per parameter and one column 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.