Skip to content

fit.project_fits

A fit of a project: its start, the adopted fits it keeps fixed and its remainders.

A fit of one subset of a project (sbmlsim.project.Project.fits) runs on the models of the project, which carry the values of the adopted fits of the other subsets (Project.adopted_fits), so a fit keeps these values fixed and records them: fixed_values gives the adopted fits of the other subsets and the values of their parameters, which the provenance of the fit records (FIXED_FITS), and the report of the fit names them, see sbmlsim.fit.cli.report_context. Least squares can start from a point instead of samples of the bounds (start_point, with_start): the values of a JSON file, of a finished or of an adopted fit. remainder_problems refuses a fit whose bounds let a remainder 1 - a - b of the model become negative.

The fit kind of sbmlsim.run uses them with the fields start and record_adopted of its spec, and the kind adopt adopts a finished fit.

start_point

start_point(project, definition, start, output_dir=None)

Get the parameters a fit starts from.

The start is a point, the values by parameter id in the units of the fit parameters (FitParameter.unit), given as a mapping or as a JSON file of one; or a fit: the directory of its records, or a name, the id of a fit, which is looked up as an adopted fit of the project (Project.fits_dir), then as a finished fit in output_dir when one is given, and only then as a path; the best parameters of the fit (parameters.json, in the units of the model) are converted into the units of the fit parameters. A fit of another problem gives the parameters which the definition fits. A parameter which the start does not give keeps its own start value.

Parameters:

Name Type Description Default
project Project

the project.

required
definition FitDefinition

the fit problem.

required
start Mapping[str, float] | str | Path

the point, the JSON file, the directory or the id of a fit.

required
output_dir Path | None

the directory of the finished fits, none without.

None

Returns:

Type Description
dict[str, float]

The start value of every parameter the start gives which the

dict[str, float]

definition fits.

Raises:

Type Description
ValueError

if the start is neither a point, a file nor a fit, a value is not a number, a parameter of the point is not fitted, a value of a fit has no unit for a fit parameter with one, or a value is outside of the bounds of its parameter.

with_start

with_start(definition, point)

Get a fit problem whose parameters start from a point.

The parameters are copies, so the definition of the project keeps its start values (the definitions are objects of a module).

Parameters:

Name Type Description Default
definition FitDefinition

the fit problem.

required
point Mapping[str, float]

the start value by parameter id.

required

Returns:

Type Description
FitDefinition

The fit problem with the start values of the point.

current_fixed_fits

current_fixed_fits(project, subset)

Get the adopted fits whose parameters a fit of a subset keeps fixed.

Parameters:

Name Type Description Default
project Project

the project.

required
subset str

the fit problem, e.g. PK.

required

Returns:

Type Description
list[str]

The adopted fits of the project of the other subsets, in the order of

list[str]

Project.adopted_fits.

fixed_values

fixed_values(project, subset, definition)

Get what a fit of a subset keeps fixed: the adopted fits of the other problems.

Parameters:

Name Type Description Default
project Project

the project.

required
subset str

the fit problem, e.g. PK.

required
definition FitDefinition

its definition, whose parameters are fitted and not fixed.

required

Returns:

Type Description
list[str]

The adopted fits of the other subsets (current_fixed_fits) and the

dict[str, float]

values of their parameters in the units of the model, without the

tuple[list[str], dict[str, float]]

parameters the definition fits.

recorded_fixed_fits

recorded_fixed_fits(records)

Get the fixed adopted fits which the provenance of a fit records.

A fit records them in the arguments of its provenance (FIXED_FITS).

Parameters:

Name Type Description Default
records FitRecords

the records of the fit (sbmlsim.fit.cli.load_fit_records).

required

Returns:

Type Description
str

The ids of the fixed fits, none for a fit without a result, without a

...

provenance or which did not record them.

remainder_problems

remainder_problems(
    sbml_path, parameters, fixed_values=None
)

Check that the fitted fractions of a remainder cannot sum above 1.

A remainder is the initial assignment 1 - a - b - ... of a constant of the model, e.g. the remainder of the product fractions of a metabolism: it keeps the sum of the fractions at 1, and is negative, a product formed at a negative rate, when the other fractions sum above 1. A fit whose bounds allow it is refused before it starts: the upper bounds of the fitted fractions of a remainder and the values of the others (the fixed values, else those of the model) sum to at most 1.

Parameters:

Name Type Description Default
sbml_path Path

the model the fit simulates.

required
parameters Iterable[FitParameter]

the parameters of the fit.

required
fixed_values Mapping[str, float] | None

the values of parameters the fit keeps fixed, by id.

None

Returns:

Type Description
list[str]

The problems, naming the remainder, the fitted parameters and their

list[str]

upper bounds.