GradientDescent¶
- class hoomd.tune.GradientDescent(alpha: float = 0.1, kappa: ndarray | None = None, tol: float = 1e-05, maximize: bool = True, max_delta: float | None = None)¶
Bases:
Optimizer
Solves equations of \(min_x f(x)\) using gradient descent.
Derivatives are computed using the forward difference.
The solver updates
x
each step via,\[x_n = x_{n-1} - \alpha {\left (1 - \kappa) \nabla f + \kappa \Delta_{n-1} \right)}\]where \(\Delta\) is the last step size. This gives the optimizer a sense of momentum which for noisy (stochastic) optimization can lead to smoother optimization. Due to the need for two values to compute a derivative, then first time this is called it makes a slight jump higher or lower to start the method.
The solver will stop updating when a maximum is detected (i.e. the step size is smaller than
tol
).- Parameters:
alpha (
hoomd.variant.variant_like
, optional) – Either a number between 0 and 1 used to dampen the rate of change in x or a variant that varies not by timestep but by the number of timessolve
has been called (i.e. the number of steps taken) (defaults to 0.1).alpha
scales the corrections to x each iteration. Larger values ofalpha
lead to larger changes while aalpha
of 0 leads to no change in x at all.kappa (
numpy.ndarray
, optional) – Real number array that determines how much of the previous steps’ directions to use (defaults toNone
which does no averaging over past step directions). The array values correspond to weight that the \(N\) last steps are weighted when combined with the current step. The current step is weighted by \(1 - \sum_{i=1}^{N} \kappa_i\).tol (
float
, optional) – The absolute tolerance for convergence of y, (defaults to1e-5
).maximize (
bool
, optional) – Whether or not to maximize function (defaults toTrue
).max_delta (
float
, optional) – The maximum step size to allow (defaults toNone
which allows a step size of any length).
- kappa¶
Real number array that determines how much of the previous steps’ directions to use. The array values correspond to weight that the \(N\) last steps are weighted when combined with the current step. The current step is weighted by \(1 - \sum_{i=1}^{N} \kappa_i\).
- Type:
- __eq__(other)¶
Test for equality.
- property alpha¶
Number between 0 and 1 that dampens of change in x.
Larger values of
alpha
lead to larger changes while aalpha
of 0 leads to no change in x at all. The property returns the currentalpha
given the current number of steps.The property can be set as in the constructor.
- Type:
- reset()¶
Reset all solving internals.
- solve(tunables)¶
Iterates towards a solution for a list of tunables.
If a y for one of the
tunables
isNone
then we skip thattunable
. Skipping implies that the quantity is not tuned andsolve
will returnFalse
.- Parameters:
tunables (list[
hoomd.tune.ManualTuneDefinition
]) – A list of tunable objects that represent a relationship f(x) = y.- Returns:
Returns whether or not all tunables were considered tuned by the object.
- Return type:
- solve_one(tunable)¶
Solve one step.