pyFDN.train_fdn#

pyFDN.train_fdn(model, loss, *, max_steps=2000, lr=0.001, optimizer='adam', patience=10, tol=1e-06, device=None, dtype=None, rng=None, log=False, train_dir=None)[source]#

Train model on loss in place and return a TrainLog.

Read the trained result back with pyFDN.extract_build().

Parameters:
  • model (Any) – A trainable model from pyFDN.build_fdn() / trainable_from_build. It must return its impulse response – every loss is a function of it – which every pyFDN shell does by construction.

  • loss (Loss) –

    The objective, e.g.:

    pyFDN.FlatMagnitude() + 0.2 * pyFDN.Sparsity(pyFDN.param(model, "feedback"))
    

    A loss holds whatever reference data it needs (e.g. MatchSpectrogram(target)), so one objective can compare against more than one reference.

  • max_steps (int)

  • lr (float)

  • patience (int)

  • optimizer (str) – "adam" (default) or "lbfgs".

  • tol (float) – Relative-improvement threshold for the plateau early stop.

  • device (Any) – Torch device / dtype (default cpu / float32).

  • dtype (Any) – Torch device / dtype (default cpu / float32).

  • rng (int | None) – Integer seed for torch.manual_seed.

  • log (bool) – If True, log/checkpoint to train_dir.

  • train_dir (str | None) – Checkpoint directory (used when log=True).

Return type:

TrainLog