morphogen.learning.training

Training of the models: Adam on mini-batches, early stopping on a validation set.

The parameters follow Adam (Kingma & Ba 2015) on the gradients of mini-batches of the training set (points, or whole paths for a recurrent model), shuffled at each epoch; the global norm of a gradient is clipped to clip, the learning rate falls geometrically from learning_rate to final times it over the epochs. The parameters kept are those of the least loss of the validation set (of the training set without one); the training stops after patience epochs without a better one. The seeds of the initial parameters (the model’s) and of the shuffles (the training’s) make it reproducible. The mini-batches may be turned at each epoch by the symmetries of the behaviour: uniform rotations (isotropic behaviours) or the 24 rotations of the cube (a cubic crystal in its axes), data that the behaviour gives without more responses.

class morphogen.learning.training.Training(model: Model, train_loss: list[float] = <factory>, validation_loss: list[float] = <factory>, best_epoch: int = -1, stopped: bool = False, time_s: float = 0.0)[source]

Bases: object

A training: the model (its parameters those of the best epoch), the losses of the training and validation sets at each epoch (mean squares of the gaps of the normalized stresses), the best epoch, whether it stopped early, its time.

property epochs: int
property best_loss: float
summary() → dict[source]
morphogen.learning.training.rotations(n: int, rng) → ndarray[source]

n rotation matrices drawn uniformly (n, 3, 3): the QR decompositions of Gaussian matrices, the signs of the diagonals of R taken out, the determinants made positive.

morphogen.learning.training.cubic_rotations() → ndarray[source]

The 24 rotations of the cube (24, 3, 3): the signed permutation matrices of determinant 1, the proper symmetries of a cubic crystal in its axes.

morphogen.learning.training.SYMMETRIES = ('isotropic', 'cubic')

The symmetries the mini-batches may be turned by (rotate of train())

morphogen.learning.training.voigt_rotations(rot) → tuple[ndarray, ndarray][source]

The 6 x 6 matrices (n, 6, 6) that turn the Voigt components of strains (engineering shears) and of stresses by rotations rot (n, 3, 3): R t R^T.

morphogen.learning.training.rotated(data: Dataset, rng, points: bool = False) → Dataset[source]

The paths of data each turned by a random rotation (each point, with points): the responses of an isotropic behaviour along the turned paths.

morphogen.learning.training.train(model: Model, data: Dataset, validation: Dataset | None = None, *, epochs: int = 200, batch: int = 32, learning_rate: float = 0.01, final: float = 0.1, patience: int | None = None, clip: float = 1.0, rotate: bool | str = False, seed: int = 0, callback: Callable[[int, float, float], None] | None = None) → Training[source]

Train model on data (see the module), set up on them first when it has no parameters; validation: the paths of the early stopping. With rotate (true or "isotropic": an isotropic behaviour), each mini-batch of paths is turned by random rotations at each epoch (rotated()): the data of every direction, without more responses; with "cubic" (a cubic crystal, its data in its axes), by random rotations of the cube (cubic_rotations()). callback(epoch, train_loss, validation_loss) after each epoch (it may raise Stopped).

morphogen.learning.training.errors(model: Model, data: Dataset) → dict[source]

The gaps of the stresses of model to those of data: relative to the root mean square of the stresses of each path (paths: one per path; their mean and max) and of all (relative), and the root mean square of the gaps (rmse, in the units of the stresses). A recurrent model runs each path from its natural state.