optim
#
Custom parameter optimizers.
Classes:
-
LevenbergMarquardtConfig
–Configuration for the Levenberg-Marquardt optimizer.
Functions:
-
levenberg_marquardt
–Optimize a given set of parameters using the Levenberg-Marquardt algorithm.
LevenbergMarquardtConfig
pydantic-model
#
Bases: BaseModel
Configuration for the Levenberg-Marquardt optimizer.
Fields:
-
type
(Literal['levenberg-marquardt']
) -
mode
(Mode
) -
trust_radius
(float
) -
trust_radius_min
(float
) -
min_eigenvalue
(float
) -
min_damping_factor
(float
) -
adaptive_factor
(float
) -
adaptive_damping
(float
) -
search_tolerance
(float
) -
search_trust_radius_max
(float
) -
search_trust_radius_factor
(float
) -
error_tolerance
(float
) -
quality_threshold_low
(float
) -
quality_threshold_high
(float
) -
convergence_loss
(float
) -
convergence_gradient
(float
) -
convergence_step
(float
) -
n_convergence_steps
(int
) -
n_convergence_criteria
(int
) -
max_steps
(int
)
min_eigenvalue
pydantic-field
#
Lower bound on hessian eigenvalue. If the smallest eigenvalue is smaller than this, a small amount of steepest descent is mixed in prior to taking a next step to try and correct this.
adaptive_factor
pydantic-field
#
Adaptive trust radius adjustment factor to use when running in adaptive mode.
adaptive_damping
pydantic-field
#
Adaptive trust radius adjustment damping to use when running in adaptive mode.
search_tolerance
pydantic-field
#
The tolerance used when searching for the optimal damping factor with hessian diagonal search (i.e. mode='hessian-search'
).
search_trust_radius_max
pydantic-field
#
The maximum trust radius to use when falling back to a second line search if the loss would increase after the one.
search_trust_radius_factor
pydantic-field
#
The factor to scale the trust radius by when falling back to a second line search.
error_tolerance
pydantic-field
#
Steps that increase the loss more than this amount are rejected.
quality_threshold_low
pydantic-field
#
The threshold below which the step is considered low quality.
quality_threshold_high
pydantic-field
#
The threshold above which the step is considered high quality.
convergence_loss
pydantic-field
#
The loss will be considered converged if its std deviation over the last n_convergence_steps
steps is less than this value.
convergence_gradient
pydantic-field
#
The gradient will be considered converged if its norm is less thanthis value.
convergence_step
pydantic-field
#
The step size will be considered converged if its norm is less than this value.
n_convergence_steps
pydantic-field
#
The number of steps to consider when checking for convergence in the loss.
n_convergence_criteria
pydantic-field
#
The number of convergence criteria that must be satisfied before the optimization is considered converged. If 0, no convergence criteria will be used and the optimizer will run for max_steps
full steps.
levenberg_marquardt
#
levenberg_marquardt(
x: Tensor,
config: LevenbergMarquardtConfig,
closure_fn: ClosureFn,
correct_fn: CorrectFn | None = None,
report_fn: ReportFn | None = None,
) -> Tensor
Optimize a given set of parameters using the Levenberg-Marquardt algorithm.
Notes
- This optimizer assumes a least-square loss function.
- This is a reimplementation of the Levenberg-Marquardt optimizer from the ForceBalance package, and so may differ from a standard implementation.
Parameters:
-
x
(Tensor
) –The initial guess of the parameters with
shape=(n,)
. -
config
(LevenbergMarquardtConfig
) –The optimizer config.
-
closure_fn
(ClosureFn
) –A function that computes the loss (
shape=()
), its gradient (shape=(n,)
), and hessian (shape=(n, n)
). It should accept as arguments the current parameter tensor, and two booleans indicating whether the gradient and hessian are required. -
correct_fn
(CorrectFn | None
, default:None
) –A function that can be used to correct the parameters after each step is taken and before the new loss is computed. This may include, for example, ensuring that vdW parameters are all positive. It should accept as arguments the current parameter tensor and return the corrected parameter tensor.
-
report_fn
(ReportFn | None
, default:None
) –An optional function that should be called at the end of every step. This can be used to report the current state of the optimization. It should accept as arguments the step number, the current parameter tensor the loss, gradient and hessian, the step 'quality', and a bool indicating whether the step was accepted or rejected.
Returns:
-
Tensor
–The parameters that minimize the loss.
Source code in descent/optim/_lm.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
|