---
title: "applyStochasticGradientDescent(learningRate:variable:gradient:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/applystochasticgradientdescent(learningrate:variable:gradient:name:)"
---

# applyStochasticGradientDescent(learningRate:variable:gradient:name:)

The Stochastic gradient descent performs a gradient descent variable = variable - (learningRate * g) where, g is gradient of error wrt variable this op directly writes to the variable

## Declaration

```swift
func applyStochasticGradientDescent(learningRate learningRateTensor: MPSGraphTensor, variable: MPSGraphVariableOp, gradient gradientTensor: MPSGraphTensor, name: String?) -> MPSGraphOperation
```

## Parameters

- `learningRateTensor`: Scalar tensor which indicates the learning rate to use with the optimizer
- `variable`: Variable operation with trainable parameters
- `gradientTensor`: Partial gradient of the trainable parameters with respect to loss
- `name`: Name for the operation

## Return Value

Return Value A valid MPSGraphTensor object.
