fit.derived¶
Changes of a simulation which are calculated from the parameters of a fit.
A fit writes the values of its parameters into the model as the changes of a
simulation. A derived change is a change which is not a parameter but a
function of them: before every simulation the problem hands the values of the
parameters, of the changes of the simulation and of the model to the objects
it was given as hybridizations, and adds the changes they answer with to
the simulation.
DerivedChanges is what such an object provides. The neural networks of a
hybrid problem are the implementation, see
sbmlsim.sciml.hybridization.Hybridization: a network which runs before the
simulation calculates parameters and initial values of the model from
parameters of the fit.
resolve_derived_changes binds the hooks to the simulation groups of a
problem when it is initialized and refuses what would make the objective flat
or wrong, evaluate_derived_changes calculates the changes of a group before
its simulation. OptimizationProblem calls both.
ParameterGroup
dataclass
¶
Parameters of a fit which a hook holds as one array.
The console and the report show the group as one row, because a network adds hundreds of elements to a fit.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
what the group is, e.g. |
ids |
tuple[str, ...]
|
the ids of its elements, estimated or not, in the order of the array. |
HookSummary
dataclass
¶
What the console and the report say about a hook.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
id of the hook, e.g. of the network. |
kind |
str
|
where it sits, e.g. the pattern of a network. |
description |
str
|
what it is made of, e.g. the layers of a network. |
targets |
tuple[str, ...]
|
the entities it sets. |
groups |
tuple[ParameterGroup, ...]
|
its parameters, as the groups the tables show. |
DerivedChanges
¶
Bases: Protocol
The changes of a simulation which follow from the values of a fit.
constants
property
¶
Get the values of the symbols the object provides itself.
Returns:
| Type | Description |
|---|---|
Mapping[str, float]
|
id -> value of the symbols which are neither entities of the |
Mapping[str, float]
|
model nor parameters of the fit. |
conditions
¶
Get the conditions for which the hook has values of its own.
Returns:
| Type | Description |
|---|---|
Mapping[str, Collection[str]]
|
id of an input, e.g. of a network -> the ids of the simulations |
Mapping[str, Collection[str]]
|
the input has values for, without the values of every other |
Mapping[str, Collection[str]]
|
simulation; an input which is the same for every simulation is |
Mapping[str, Collection[str]]
|
not listed. |
symbols
¶
Get the ids whose values derived_changes reads.
Returns:
| Type | Description |
|---|---|
Collection[str]
|
The ids of entities of the model, of parameters of the fit which |
Collection[str]
|
are not entities of the model, and of the |
targets
¶
Get the entities of the model derived_changes sets.
Returns:
| Type | Description |
|---|---|
Collection[str]
|
The ids of the entities, or the selections of their |
Collection[str]
|
concentrations. |
check_parameters
¶
Check the targets of the parameters of a fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
Collection[str]
|
the entities the parameters of the fit write, without the prefix of a target which is not an entity of the model. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the fit writes what the derived changes set or hold constant. |
derived_changes
¶
Get the changes of a simulation for the values of the fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Mapping[str, float]
|
id -> value in the units of the model. The values are the ones of the parameters of the fit, of the changes of the simulation and of the model, in this order of precedence. |
required |
condition
|
str
|
id of the simulation in its experiment. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
target -> value in the unit of the target in the model, for every |
dict[str, float]
|
target. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a value is missing or a change is not a finite number. |
describe
¶
Describe a hook for the serialization of a problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hybridization
|
DerivedChanges
|
the hook. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The type, the model, the targets and the summary of the hook. |
group_parameters
¶
Split the parameters of a fit into single ones and the groups of the hooks.
The elements of a group are found by the entity they write
(FitParameter.entity_id), so a parameter of an element which is versioned
under another id belongs to the group as well. A group which several hooks
share, e.g. a network which is used twice, is listed once, at its first
occurrence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Sequence[FitParameter]
|
the parameters of the fit. |
required |
summaries
|
Iterable[HookSummary]
|
the summaries of the hooks of the problem. |
required |
Returns:
| Type | Description |
|---|---|
list[FitParameter]
|
The parameters which belong to no group, in their order, and every |
list[tuple[ParameterGroup, list[FitParameter]]]
|
group with the parameters of the fit which are its elements. A group |
tuple[list[FitParameter], list[tuple[ParameterGroup, list[FitParameter]]]]
|
without a parameter of the fit is listed with none, i.e. an array |
tuple[list[FitParameter], list[tuple[ParameterGroup, list[FitParameter]]]]
|
which is frozen. |
resolve_derived_changes
¶
Bind the hooks of a problem to its simulation groups.
The derived changes of a group are the hooks of its model. The values of the model which they read are stored with them, from the model as it was loaded: a simulation changes the state of the model. The simulations of the problem must not have been simulated yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
the problem, with its fit mappings resolved into simulation
groups and its |
required |
Returns:
| Type | Description |
|---|---|
list[GroupDerivedChanges]
|
The derived changes of every simulation group. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a hook names a model no fit mapping is simulated with, if a parameter which is not an entity of the model and one which is reach a group with one id, if a parameter of the fit writes what a hook sets or holds constant, if a hook sets what is not an entity of the model or what the first timecourse of the simulation changes, if two hooks set one entity, if a hook reads what another one sets, if a hook reads a constant of its own which a parameter of the fit writes, if a hook reads a symbol which is neither an entity of the model, nor a parameter of the fit in the group, nor one of its constants, or if a parameter which is not an entity of the model is read by no hook. |
model_values
¶
Get the values of the entities of a model which are symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
RoadrunnerSBMLModel
|
the model as it was loaded, with its changes. |
required |
symbols
|
Collection[str]
|
ids, of which some are entities of the model. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
id -> value of the symbols which are entities of the model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model is not loaded in roadrunner, or if roadrunner has no value for an entity. |
evaluate_derived_changes
¶
Get the derived changes of the simulation of a group.
The values the hooks calculate from are the values of the parameters of the fit, the changes of the first timecourse of the simulation and the values of the model, in this order of precedence and in the units of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
the initialized problem. |
required |
k_group
|
int
|
index of the simulation group. |
required |
simulation
|
TimecourseSim
|
the simulation of the group with the changes of the parameters, normalized to the units of the model. |
required |
simulator
|
SimulatorSerial
|
simulator of the problem, with the model of the group. |
required |
quantities
|
Sequence[Quantity]
|
the quantity of every parameter, in the order of the parameter vector. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Quantity]
|
The changes by entity of the model, in the unit of the entity. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a hook cannot calculate its changes, or if it answers with other changes than the ones of its targets. |