Stochastic gradient descent
Manopt.stochastic_gradient_descent — Function
stochastic_gradient_descent(M, grad_f, p=rand(M); kwargs...)
stochastic_gradient_descent(M, msgo; kwargs...)
stochastic_gradient_descent!(M, grad_f, p; kwargs...)
stochastic_gradient_descent!(M, msgo, p; kwargs...)perform a stochastic gradient descent. This can be performed in-place of p.
Input
M::AbstractManifold: a Riemannian manifold $\mathcal{M}$grad_f: a gradient function, that either returns a vector of the gradients or is a vector of gradient functionsp::P: a point on the manifold $\mathcal{M}$
alternatively to the gradient you can provide a ManifoldStochasticGradientObjective msgo, then using the cost= keyword does not have any effect since if so, the cost is already within the objective.
Keyword arguments
callbacks::D = Dict{Symbol,Function}(): provided callback functions given either as a single function(symbol, problem, state, k)called in every hook or as a (vector of) pairs:hook => function, which are processed byprocess_callbacks_arg. As key you can either pass single symbol or an array of symbols to indicate a callback should be added in multiple placescost=missing: you can provide a cost function for example to track the function valuedirection=StochasticGradient(; p=p)add a post-processor to the direction obtained from evaluating the stochastic gradient.evaluation::AbstractEvaluationType=AllocatingEvaluation(): specify whether the functions that return an array, for example a point or a tangent vector, work by allocating their result (AllocatingEvaluation) or whether they modify their input argument to return the result therein (InplaceEvaluation). Since usually the first argument is the manifold, the modified argument is the second.order_type=:Random: whether to use a randomly permuted sequence that is drawn anew at the start of every epoch (:FixedRandom), the sequence as given inorder(:Linear), or the default:Randomone, which chooses a random gradient in every step.stopping_criterion::StoppingCriterion=StopAfterIteration(10000)|StopWhenGradientNormLess(1.0e-9): a functor indicating that the stopping criterion is fulfilledstepsize::Stepsize=default_stepsize(M,StochasticGradientDescentState): a functor inheriting fromStepsizeto determine a step sizeorder=collect(1:n): the initial permutation, wherenis the number of gradients ingrad_f.retraction_method::AbstractRetractionMethod=default_retraction_method(M, typeof(p)): a retraction $\operatorname{retr}$ to use, see the section on retractions
All other keyword arguments are passed to decorate_state! for state decorators or decorate_objective! for objective decorators, respectively.
Output
The obtained approximate minimizer $p^*$. To obtain the whole final state of the solver, see get_solver_return for details, especially the return_state= keyword.
Manopt.stochastic_gradient_descent! — Function
stochastic_gradient_descent(M, grad_f, p=rand(M); kwargs...)
stochastic_gradient_descent(M, msgo; kwargs...)
stochastic_gradient_descent!(M, grad_f, p; kwargs...)
stochastic_gradient_descent!(M, msgo, p; kwargs...)perform a stochastic gradient descent. This can be performed in-place of p.
Input
M::AbstractManifold: a Riemannian manifold $\mathcal{M}$grad_f: a gradient function, that either returns a vector of the gradients or is a vector of gradient functionsp::P: a point on the manifold $\mathcal{M}$
alternatively to the gradient you can provide a ManifoldStochasticGradientObjective msgo, then using the cost= keyword does not have any effect since if so, the cost is already within the objective.
Keyword arguments
callbacks::D = Dict{Symbol,Function}(): provided callback functions given either as a single function(symbol, problem, state, k)called in every hook or as a (vector of) pairs:hook => function, which are processed byprocess_callbacks_arg. As key you can either pass single symbol or an array of symbols to indicate a callback should be added in multiple placescost=missing: you can provide a cost function for example to track the function valuedirection=StochasticGradient(; p=p)add a post-processor to the direction obtained from evaluating the stochastic gradient.evaluation::AbstractEvaluationType=AllocatingEvaluation(): specify whether the functions that return an array, for example a point or a tangent vector, work by allocating their result (AllocatingEvaluation) or whether they modify their input argument to return the result therein (InplaceEvaluation). Since usually the first argument is the manifold, the modified argument is the second.order_type=:Random: whether to use a randomly permuted sequence that is drawn anew at the start of every epoch (:FixedRandom), the sequence as given inorder(:Linear), or the default:Randomone, which chooses a random gradient in every step.stopping_criterion::StoppingCriterion=StopAfterIteration(10000)|StopWhenGradientNormLess(1.0e-9): a functor indicating that the stopping criterion is fulfilledstepsize::Stepsize=default_stepsize(M,StochasticGradientDescentState): a functor inheriting fromStepsizeto determine a step sizeorder=collect(1:n): the initial permutation, wherenis the number of gradients ingrad_f.retraction_method::AbstractRetractionMethod=default_retraction_method(M, typeof(p)): a retraction $\operatorname{retr}$ to use, see the section on retractions
All other keyword arguments are passed to decorate_state! for state decorators or decorate_objective! for objective decorators, respectively.
Output
The obtained approximate minimizer $p^*$. To obtain the whole final state of the solver, see get_solver_return for details, especially the return_state= keyword.
State
Manopt.StochasticGradientDescentState — Type
StochasticGradientDescentState <: AbstractGradientSolverStateStore the following fields for a default stochastic gradient descent algorithm, see also ManifoldStochasticGradientObjective and stochastic_gradient_descent.
Fields
callbacks::D: provided callback functions given as a dictionary with symbols as keysp::P: a point on the manifold $\mathcal{M}$ storing the current iteratedirection: a direction update to usestop::StoppingCriterion: a functor indicating that the stopping criterion is fulfilledstepsize::Stepsize: a functor inheriting fromStepsizeto determine a step sizeorder_type: specify whether to use a randomly permuted sequence that is drawn anew at the start of every epoch (:FixedRandom), the sequence as given inorder(:Linear), or the default:Randomone, which chooses a random gradient in every step.order: stores the current permutationretraction_method::AbstractRetractionMethod: a retraction $\operatorname{retr}$ to use, see the section on retractionsX::T: a tangent vector at the point $p$ on the manifold $\mathcal{M}$ storing the gradient at the current iterate
Constructor
StochasticGradientDescentState(M::AbstractManifold; kwargs...)Create a StochasticGradientDescentState with start point p.
Keyword arguments
callbacks::D = Dict{Symbol,Function}(): provided callback functions given as a dictionary with symbols as keysdirection=StochasticGradientRule(M; X=zero_vector(M, p))order_type=:Randomorder=Int[]: specify how to store the order of indices for the next epochretraction_method::AbstractRetractionMethod=default_retraction_method(M, typeof(p)): a retraction $\operatorname{retr}$ to use, see the section on retractionsp::P =rand(M): a point on the manifold $\mathcal{M}$ to specify the initial valuestopping_criterion::StoppingCriterion=StopAfterIteration(1000): a functor indicating that the stopping criterion is fulfilledstepsize::Stepsize=default_stepsize(M,StochasticGradientDescentState): a functor inheriting fromStepsizeto determine a step sizeX::T =zero_vector(M, p): a tangent vector at the point $p$ on the manifold $\mathcal{M}$ to specify the representation of a tangent vector
Manopt.default_stepsize — Method
default_stepsize(M::AbstractManifold, ::Type{StochasticGradientDescentState})Define the default step size computed for the StochasticGradientDescentState, which is ConstantStepsize(M).
Additionally, the state shares a DirectionUpdateRule, so you can also apply MomentumGradient and AverageGradient here. The innermost one should always be the following:
Manopt.StochasticGradient — Function
StochasticGradient(; kwargs...)
StochasticGradient(M::AbstractManifold; kwargs...)Keyword arguments
X::T =zero_vector(M, p): a tangent vector at the point $p$ on the manifold $\mathcal{M}$p::P =rand(M): a point on the manifold $\mathcal{M}$ to specify the initial value
This function generates a ManifoldDefaultsFactory for StochasticGradientRule. For default values that depend on the manifold, this factory postpones the construction until the manifold is available, for example from a corresponding AbstractManoptSolverState.
which internally uses
Manopt.StochasticGradientRule — Type
StochasticGradientRule <: AbstractGradientGroupDirectionRuleCreate a functor (problem, state, k) -> (s, X) to evaluate the stochastic gradient, that is, choose a random index from the state and use the internal field for evaluation of the gradient in-place.
The default gradient processor, which just evaluates the (stochastic) gradient or a subset thereof.
Fields
X::T: a tangent vector at the point $p$ on the manifold $\mathcal{M}$
Constructor
StochasticGradientRule(M::AbstractManifold; p=rand(M), X=zero_vector(M, p))Initialize the stochastic gradient processor with tangent vector type of X, where both M and p are just help variables.
See also
Technical details
The stochastic_gradient_descent solver requires the following functions of a manifold to be available
- A
retract!(M, q, p, X); it is recommended to set thedefault_retraction_methodto a favorite retraction. If this default is set, aretraction_method=does not have to be specified. - If you do not provide a
stepsize=, the defaultConstantStepsizerequires theinjectivity_radius(M). - By default the stopping criterion uses the
normas well, to stop when the norm of the gradient is small, but if you implementedinner, the norm is provided already.