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), N a perceptron of hidden layers of tanh. 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_K an 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) with W_k >= 0, w >= 0 (softplus of free parameters), g the softplus (convex, increasing) and A = L L^T. The potential of the stress psi = 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 tangent d2 psi / d eps2 is symmetric and positive semi-definite. The training fits the gradient of W: the gradients of the objective with respect to the parameters are those of a derivative of W along 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, with rate) and whose state h (hidden values: the internal variables of the law, learned) gives the stress y = 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')

Standard)

Type:

The kinds of models (standard

morphogen.learning.networks.STRAINS = ('logarithmic', 'green-lagrange')

the logarithmic strain 1/2 ln C (their stress T conjugate to it, S = J^T T) or the Green-Lagrange strain E (their stress S)

Type:

The strains of the models in finite strains (their option strain)

class morphogen.learning.networks.Model(**options)[source]

Bases: object

A 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 its metadata (the data, the training). In finite strains its option strain (STRAINS) chooses the strain it sees, 1/2 ln C or E (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 option seed).

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/dE in finite strains.

step(e_new, e_old, h_old, dt)[source]

A step of points: the stresses (n x 6) and tangents (n x 6 x 6) at the strains e_new at its end, from the strains e_old and the states h_old (n x n_state) at its start over the time dt, and the states at its end.

to_dict() → dict[source]

The metadata of a file of the model (JSON).

save(path) → Path[source]

The parameters in an .npz file, with the metadata (JSON) of the model.

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, strain in finite strains; rate for a recurrent or standard model; internal, plastic and smoothing for a standard model).

class morphogen.learning.networks.FeedForward(hidden=(32, 32), *, strain: str = 'logarithmic', seed: int = 0)[source]

Bases: Model

The 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, or S(E)); seed, that of its initial parameters.

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

class morphogen.learning.networks.Potential(hidden=(32, 32), *, strain: str = 'logarithmic', seed: int = 0)[source]

Bases: Model

The 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, or psi(E)); seed, that of its initial parameters.

energy(strain) → ndarray[source]

The potential of the stress (energy per unit volume) at strains (…, 6; Green-Lagrange strains in finite strains).

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

class morphogen.learning.networks.Recurrent(hidden: int = 32, *, rate: bool = False, strain: str = 'logarithmic', seed: int = 0)[source]

Bases: Model

A 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 output T, the default; or E and its increments, its output S); 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.

tangent(strain)[source]

The tangents d sigma / d eps (…, 6, 6) at strains (…, 6); dS/dE in finite strains.

step(e_new, e_old, h_old, dt)[source]

A step of points: the stresses (n x 6) and tangents (n x 6 x 6) at the strains e_new at its end, from the strains e_old and the states h_old (n x n_state) at its start over the time dt, and the states at its end.