Registration is open for TensorFlow Dev Summit 2020 Learn more


public class SGD<Model: Differentiable>: Optimizer
    where Model.TangentVector: VectorProtocol & ElementaryFunctions,
          Model.TangentVector.VectorSpaceScalar == Float

Stochastic gradient descent (SGD) optimizer.

An optimizer that implements stochastic gradient descent, with support for momentum, learning rate decay, and Nesterov momentum.

  • Declaration

    public typealias Model = Model
  • The learning rate.


    public var learningRate: Float
  • The momentum factor. It accelerates stochastic gradient descent in the relevant direction and dampens oscillations.


    public var momentum: Float
  • The weight decay.


    public var decay: Float
  • Use Nesterov momentum if true.


    public var nesterov: Bool
  • The velocity state of the model.


    public var velocity: Model.TangentVector
  • The set of steps taken.


    public var step: Int
  • Declaration

    public init(
        for model: __shared Model,
        learningRate: Float = 0.01,
        momentum: Float = 0,
        decay: Float = 0,
        nesterov: Bool = false
  • Declaration

    public func update(_ model: inout Model, along direction: Model.TangentVector)