OptimHistory.from_epochs()

OptimHistory.from_epochs()#

classmethod OptimHistory.from_epochs(epochs, position, loss_dtype=None)[source]#

Allocates an empty optimizer history for a fixed number of epochs.

Parameters:
  • epochs (int) – Number of epochs to allocate.

  • position (Position (dict[str, Any]) | None) – Initial position used to infer the shape of the stored parameter history. If None, no parameter history is allocated.

  • loss_dtype (dtype | None, default: None) – Optional dtype for the loss history. If omitted, the first floating dtype in position is used, falling back to JAX’s default.

Return type:

OptimHistory

Returns:

OptimHistory – Initialized history object.

Examples

>>> import jax.numpy as jnp
>>> from liesel.optim import OptimHistory
>>> from liesel.optim.types import Position
>>> history = OptimHistory.from_epochs(2, Position({"theta": jnp.array(1.0)}))
>>> history.loss_monitor.tolist()
[inf, inf]
>>> history.position["theta"].tolist()
[0.0, 0.0]