Skip to content

otf.optim.gradient.sensitivity

Classes:

Name Description
SensitivityGradient

Compute gradients using sensitivity (forward) equations.

UpdateOption

Enum for selecting parameter update methods.

SensitivityGradient

SensitivityGradient(
    system: BaseSystem,
    update_option: UpdateOption = UpdateOption.last_state,
    solver: tuple[type[SinglestepSolver | MultistepSolver]]
    | type[SinglestepSolver | MultistepSolver]
    | None = None,
    dt: float | None = None,
    use_unobserved_asymptotics: bool = False,
)

Bases: GradientComputer

Compute gradients using sensitivity (forward) equations.

Different UpdateOptions select how the sensitivity information is assembled (last state, mean state, mean gradient, or complete simulation).

Initialize a SensitivityGradient.

Parameters:

Name Type Description Default
system BaseSystem

BaseSystem instance to analyze.

required
update_option UpdateOption

Strategy for forming the gradient (UpdateOption).

last_state
solver tuple[type[SinglestepSolver | MultistepSolver]] | type[SinglestepSolver | MultistepSolver] | None

Solver class or tuple of solver classes used when the complete update option is selected.

None
dt float | None

Time-step used with the solver (required when solver is used).

None
use_unobserved_asymptotics bool

When True attempt to use asymptotic information from unobserved state components (experimental).

False
Source code in src/otf/optim/gradient/sensitivity.py
def __init__(
    self,
    system: BaseSystem,
    update_option: UpdateOption = UpdateOption.last_state,
    solver: tuple[type[SinglestepSolver | MultistepSolver]]
    | type[SinglestepSolver | MultistepSolver]
    | None = None,
    dt: float | None = None,
    use_unobserved_asymptotics: bool = False,
):
    """Initialize a `SensitivityGradient`.

    Parameters
    ----------
    system
        `BaseSystem` instance to analyze.
    update_option
        Strategy for forming the gradient (`UpdateOption`).
    solver
        Solver class or tuple of solver classes used when the `complete`
        update option is selected.
    dt
        Time-step used with the solver (required when `solver` is used).
    use_unobserved_asymptotics
        When True attempt to use asymptotic information from unobserved
        state components (experimental).
    """
    super().__init__(system)

    self._update_option = update_option
    self.compute_gradient = self._set_up_gradient(update_option)

    if update_option is UpdateOption.complete:
        if dt is None:
            raise ValueError("`dt` must not be None for this update option")
        if solver is None:
            raise ValueError(
                "`solver` must not be None for the given update option"
            )

        sensitivity_system = _SensitivitySystem(system)

        self._dt = dt
        self._solver = self._set_up_solver(sensitivity_system, solver)

    self._use_unobserved_asymptotics = use_unobserved_asymptotics

UpdateOption

Bases: Enum

Enum for selecting parameter update methods.

Options include:

  • last_state: Uses the last observed state for the update and the asymptotic approximation for the observed portion of the sensitivity.
  • mean_state: Uses the mean of the observed states for the update and the asymptotic approximation for the observed portion of the sensitivity.
  • mean_gradient: Uses the mean of the gradients for the update and the asymptotic approximation for the observed portion of the sensitivity.
  • complete: Uses the mean of the gradients for the update and the complete sensitivity via simulation.