otf.optim.base
Optimization utilities for parameter estimation during data assimilation.
This module provides base classes and helpers used to update the cs parameters
of BaseSystem instances during data assimilation. See the individual class and
function docstrings for details and usage examples.
Classes:
| Name | Description |
|---|---|
BaseOptimizer |
Base interface for optimizers that estimate |
OptimizerChain |
Combine several optimizers by summing their weighted updates. |
PartialOptimizer |
Wrap an optimizer to update only a subset of parameters. |
Regularizer |
Produce parameter-space penalties used as a regularization term. |
Functions:
| Name | Description |
|---|---|
pruned_factory |
Return a 'pruned' variant of |
BaseOptimizer
Base interface for optimizers that estimate BaseSystem parameters.
Subclasses must implement step(observed_true, nudged) and may override
step_from_gradient.
Create a BaseOptimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
BaseSystem
|
|
required |
gradient_computer
|
GradientComputer | None
|
Optional |
None
|
Methods:
| Name | Description |
|---|---|
__call__ |
Compute the new parameter values following one step of the |
step |
Abstract: compute the parameter update vector. |
step_from_gradient |
Optional: compute an update from a precomputed |
Source code in src/otf/optim/base.py
__call__
Compute the new parameter values following one step of the optimization algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed_true
|
jndarray
|
The observed portion of the true system's state |
required |
nudged
|
jndarray
|
The nudged system's state |
required |
Returns:
| Type | Description |
|---|---|
new_cs
|
The new values for |
Source code in src/otf/optim/base.py
step
Abstract: compute the parameter update vector.
Subclasses should return the vector that will be added to system.cs to
obtain the updated parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed_true
|
jndarray
|
Observed portion of the true system's state (array-like). |
required |
nudged
|
jndarray
|
The nudged/assimilated system's state (array-like). |
required |
Returns:
| Type | Description |
|---|---|
step
|
Vector to add to |
Source code in src/otf/optim/base.py
step_from_gradient
Optional: compute an update from a precomputed gradient.
Default implementations may delegate to step. Subclasses that have
closed-form updates from the gradient can override this for speed and
clarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gradient
|
jndarray
|
Derivative of the assimilation error with respect to parameters
(same shape as |
required |
observed_true
|
jndarray
|
Observed portion of the true system's state (array-like). |
required |
nudged
|
jndarray
|
The nudged/assimilated system's state (array-like). |
required |
Returns:
| Type | Description |
|---|---|
step
|
Vector to add to |
Source code in src/otf/optim/base.py
OptimizerChain
OptimizerChain(
system: BaseSystem,
learning_rate: float,
optimizers: list[BaseOptimizer],
weights: list[float],
)
Bases: BaseOptimizer
Combine several optimizers by summing their weighted updates.
Initialize an OptimizerChain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learning_rate
|
float
|
Scalar applied to the total weighted update (controls overall step size). |
required |
optimizers
|
list[BaseOptimizer]
|
Sequence of |
required |
weights
|
list[float]
|
Sequence of relative weights (one per optimizer). These are normalized internally so their sum is one. |
required |
Notes
It can be convenient to set each individual optimizer's internal
learning rate to 1.0 and control the combined step size with
learning_rate supplied here.
Source code in src/otf/optim/base.py
PartialOptimizer
Bases: BaseOptimizer
Wrap an optimizer to update only a subset of parameters.
The wrapped optimizer computes a full update vector; PartialOptimizer
masks that update so only selected indices in system.cs are changed.
Initialize the wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimizer
|
BaseOptimizer
|
Base optimizer used to compute the full parameter update. |
required |
param_idx
|
jndarray | None
|
Indices of |
None
|
Methods:
| Name | Description |
|---|---|
__getattr__ |
For attributes that aren't defined in this class, route access to the |
__setattr__ |
For attributes that aren't defined in this class, route access to the |
Source code in src/otf/optim/base.py
__getattr__
For attributes that aren't defined in this class, route access to the wrapped optimizer.
__setattr__
For attributes that aren't defined in this class, route access to the wrapped optimizer.
Source code in src/otf/optim/base.py
Regularizer
Regularizer(
system: BaseSystem,
ord: int | float | Callable,
prior: jndarray | None = None,
callable_is_derivative: bool | None = None,
)
Bases: BaseOptimizer
Produce parameter-space penalties used as a regularization term.
The step method returns the negative derivative of the regularization
penalty (same shape as system.cs) and can be combined with a
gradient-based optimizer.
Initialize a Regularizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ord
|
int | float | Callable
|
If an int/float, interpreted as the |
required |
prior
|
jndarray | None
|
Optional prior parameter vector; penalty is applied to |
None
|
callable_is_derivative
|
bool | None
|
If |
None
|
Methods:
| Name | Description |
|---|---|
step |
Return the negative derivative of the regularization penalty. |
Source code in src/otf/optim/base.py
step
Return the negative derivative of the regularization penalty.
The returned array has the same shape as system.cs and can be added to
a gradient-based update.
Source code in src/otf/optim/base.py
pruned_factory
Return a 'pruned' variant of system_type.
If a parameter in cs of the system is to be set below its corresponding
threshold (in absolute value), it will be set to zero permanently.
Optionally require that this occur at least a specified number of times
consecutively before setting a parameter to zero permanently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system_type
|
type[BaseSystem]
|
The type of |
required |
Source code in src/otf/optim/base.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |