sciml.parameters¶
The nominal values and the fit parameters of a network.
A problem describes the elements of a network in groups: an entry is given
for the network (net1), for a layer (net1.layer1) or for an array
(net1.layer1.weight), and the more specific entry wins. This is how a
problem sets the elements of one layer to 0.0 while the other layers keep
the values of the array file, and how it estimates one layer and freezes the
others.
covered_arrays
¶
Get the arrays an entry covers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
the network. |
required |
key
|
str
|
the network ( |
required |
Returns:
| Type | Description |
|---|---|
int
|
How specific the entry is (0 for the network, 1 for a layer, 2 for an |
list[tuple[str, str]]
|
array) and the arrays as pairs of layer id and array name. Only the |
tuple[int, list[tuple[str, str]]]
|
arrays which are parameters are covered, i.e. not the running |
tuple[int, list[tuple[str, str]]]
|
statistics of a normalization layer. |
Raises:
| Type | Description |
|---|---|
NetworkImportError
|
if the key does not name the network, one of its layers or one of their arrays. |
resolve_entries
¶
Resolve the entries of a problem to the arrays of a network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
the network. |
required |
entries
|
Mapping[str, T]
|
key of the entry -> value, see |
required |
Returns:
| Type | Description |
|---|---|
dict[tuple[str, str], T]
|
layer id and array name -> the value of the most specific entry which |
dict[tuple[str, str], T]
|
covers the array. An array no entry covers is not part of it. |
Raises:
| Type | Description |
|---|---|
NetworkImportError
|
if a key does not name the network, a layer or an array. |
nominal_parameters
¶
Get the nominal values of the arrays of a network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
the network with the values of its array file. |
required |
values
|
Mapping[str, float] | None
|
key of the entry -> value of every element the entry covers,
see |
None
|
Returns:
| Type | Description |
|---|---|
NetworkParameters
|
The arrays in the PyTorch layout. The network is not changed. |
Raises:
| Type | Description |
|---|---|
NetworkImportError
|
if a key does not name the network, a layer or an
array, if a value is not finite, or if an array of a layer of the
forward pass has values neither in the array file nor in
|
network_fit_parameters
¶
Create the fit parameters of the estimated elements of a network.
estimate and bounds are given for the network, for a layer or for an
array, and the more specific entry wins, see covered_arrays.
The nominal values of the elements are the values the network carries,
which are the start values of the estimated elements and the values of
the frozen ones. They are set on the network, not here, so that the
network a hybridization runs is the network the fit parameters describe:
dataclasses.replace(network, parameters=nominal_parameters(network,
values)).
The elements of a layer which the forward pass does not call are left out: the outputs of the network do not depend on them, so a fit cannot estimate them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
the network with the nominal values of its elements. |
required |
estimate
|
Mapping[str, bool]
|
key of the entry -> whether the elements are estimated. An element no entry covers is not estimated. |
required |
bounds
|
Mapping[str, tuple[float, float]]
|
key of the entry -> lower and upper bound of the elements. An estimated element no entry covers is not bounded. |
required |
external
|
bool
|
whether the elements are not entities of a model, which is
the case for a network which runs before the simulation. The
target of such a parameter is |
False
|
Returns:
| Type | Description |
|---|---|
list[FitParameter]
|
One parameter per estimated element, named by the id of the element, |
list[FitParameter]
|
with the nominal value as start value, the linear scale and the unit |
list[FitParameter]
|
|
Raises:
| Type | Description |
|---|---|
NetworkImportError
|
if a key does not name the network, a layer or an array, or if an estimated element has no nominal value. |
ValueError
|
if a nominal value is outside of its bounds. |