morphogen.learning.networks¶
The models of learned behaviours, with their gradients written out (no automatic differentiation): the stress as a function of the strain, a potential of the stress, and a recurrent network over the strain increments.
Every model sees the strain divided by the scale of the strains of its training set and
gives the stress divided by that of the stresses (
Scales); its linear term starts from the least-squares fit of the training set, which
the networks then correct. The objective of the training is the mean square of the gap
of the normalized stresses.
FeedForward:y = L x + N(x),Na perceptron of hidden layers oftanh. Path-independent, its tangent the Jacobian of the network (not symmetric in general).Potential:y = dW/dx (x) - dW/dx (0),W(x) = x.A x / 2 + w . z_Kan input-convex network (Amos, Xu & Kolter 2017):z_1 = g(U_1 x + b_1),z_k = g(W_k z_{k-1} + U_k x + b_k)withW_k >= 0,w >= 0(softplus of free parameters),gthe softplus (convex, increasing) andA = L L^T. The potential of the stresspsi = s_sigma s_eps (W(x) - W(0) - x . dW/dx(0))is convex, zero with its gradient at the natural state: the stress derives from it (hyperelasticity), its tangentd2 psi / d eps2is symmetric and positive semi-definite. The training fits the gradient ofW: the gradients of the objective with respect to the parameters are those of a derivative ofWalong the gaps, a forward derivative (tangents of the layers) differentiated backward.Recurrent: a gated recurrent unit (Cho et al. 2014) over the steps, whose input is the strain at the end of the step and the increment of the step (and the time step, withrate) and whose stateh(hiddenvalues: the internal variables of the law, learned) gives the stressy = V h + Q x + c; path-dependent, trained by backpropagation through time over whole paths. Its consistent tangent is the derivative of the stress of a step with respect to the strain at its end, the state at its start held.
In finite strains (data of the Green-Lagrange strain E and the second Piola-Kirchhoff
stress S) the option strain of every model (STRAINS) chooses what it sees:
logarithmic (the default), the logarithmic strain H = 1/2 ln C (and its increments,
for the recurrent network), its output the stress T conjugate to H, whence S =
J^T T and dS/dE = J^T (dT/dH) J + T : d2H/dE2 (morphogen.learning.logarithmic;
the potential psi(H) of T is that of S, psi(H(E))); or green-lagrange,
E and S themselves. J = dH/dE does not depend on the parameters: the gaps of
S reach T through it, J r. Either way a law is a function of C (H an
isotropic function of C), objective. The files written before the option load as
laws of E.
- morphogen.learning.networks.KINDS = ('feedforward', 'potential', 'recurrent', 'standard')¶
-
- Type:
The kinds of models (
standard
- morphogen.learning.networks.STRAINS = ('logarithmic', 'green-lagrange')¶
the logarithmic strain
1/2 ln C(their stressTconjugate to it,S = J^T T) or the Green-Lagrange strainE(their stressS)- Type:
The strains of the models in finite strains (their option
strain)
- class morphogen.learning.networks.Model(**options)[source]¶
Bases:
objectA learned behaviour: its parameters (
params, arrays), the normalization of its training set (scales), the measure of its data ("small"or"green-lagrange"), its options and itsmetadata(the data, the training). In finite strains its optionstrain(STRAINS) chooses the strain it sees,1/2 ln CorE(see the module).- property n_state: int¶
The internal variables of a point (the state of a recurrent network).
- property ready: bool¶
- property logarithmic: bool¶
Whether the model sees the logarithmic strains of the Green-Lagrange strains of its data and gives the stresses conjugate to them (finite strains,
strain="logarithmic").
- setup(data: Dataset) None[source]¶
The scales of the training set
data, and the parameters initialized (seeded by the optionseed).
- prepare(data: Dataset) tuple[source]¶
The normalized arrays of the objective, their first axis the samples (the points of the paths, or the paths of a recurrent model).
- objective(arrays, grad: bool = True) tuple[float, dict | None][source]¶
The mean square of the gaps of the normalized stresses, and its gradients with respect to the parameters (with
grad).
- predict(strain, times=None) ndarray[source]¶
The stresses of strains (…, 6); of a recurrent model, of paths (paths x points x 6, the first point the natural state, at the
times). In finite strains: the second Piola-Kirchhoff stresses of Green-Lagrange strains.
- tangent(strain) ndarray[source]¶
The tangents
d sigma / d eps(…, 6, 6) at strains (…, 6);dS/dEin finite strains.
- morphogen.learning.networks.load_model(path) Model[source]¶
A model saved by
Model.save().
- morphogen.learning.networks.make_model(kind: str, **options) Model[source]¶
A model of
kind(KINDS) with its options (hidden,seed,strainin finite strains;ratefor a recurrent or standard model;internal,plasticandsmoothingfor a standard model).
- class morphogen.learning.networks.FeedForward(hidden=(32, 32), *, strain: str = 'logarithmic', seed: int = 0)[source]¶
Bases:
ModelThe stress of the strain by a perceptron (see the module):
hidden, the sizes of its hidden layers;strain, the strain it sees in finite strains (STRAINS;T(1/2 ln C), the default, orS(E));seed, that of its initial parameters.
- class morphogen.learning.networks.Potential(hidden=(32, 32), *, strain: str = 'logarithmic', seed: int = 0)[source]¶
Bases:
ModelThe stress derived from a learned convex potential (see the module):
hidden, the sizes of the hidden layers of its input-convex network;strain, the strain of the potential in finite strains (STRAINS;psi(1/2 ln C), the default, which represents Hencky’s elasticity with its quadratic term, orpsi(E));seed, that of its initial parameters.
- class morphogen.learning.networks.Recurrent(hidden: int = 32, *, rate: bool = False, strain: str = 'logarithmic', seed: int = 0)[source]¶
Bases:
ModelA recurrent network over the steps of the paths (see the module):
hidden, the size of its state;rate, whether the time step is an input (rate-dependent behaviours);strain, the strain it sees in finite strains (STRAINS: the logarithmic strain and its increments, its outputT, the default; orEand its increments, its outputS);seed, that of its initial parameters.- property n_state: int¶
The internal variables of a point (the state of a recurrent network).
- property n_inputs: int¶
- prepare(data: Dataset) tuple[source]¶
The inputs, the normalized strains at the ends of the steps and the normalized stresses of the paths (
ln C: the Green-Lagrange strains, which the rotations of the training turn, their logarithmic strains in the inputs).
- objective(arrays, grad=True)[source]¶
The mean square of the gaps of the normalized stresses, and its gradients with respect to the parameters (with
grad).
- predict(strain, times=None) ndarray[source]¶
The stresses of strains (…, 6); of a recurrent model, of paths (paths x points x 6, the first point the natural state, at the
times). In finite strains: the second Piola-Kirchhoff stresses of Green-Lagrange strains.