Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

(no description)

File Size: 278 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

StochasticGD:: (11 methods):
  __construct()
  setTheta()
  setChangeThreshold()
  setEarlyStop()
  setLearningRate()
  setMaxIterations()
  runOptimization()
  getCostValues()
  updateTheta()
  earlyStop()
  clear()


Class: StochasticGD  - X-Ref

Stochastic Gradient Descent optimization method
to find a solution for the equation A.ϴ = y where
A (samples) and y (targets) are known and ϴ is unknown.

__construct(int $dimensions)   X-Ref
Initializes the SGD optimizer for the given number of dimensions


setTheta(array $theta)   X-Ref
No description

setChangeThreshold(float $threshold = 1e-5)   X-Ref
Sets minimum value for the change in the theta values
between iterations to continue the iterations.<br>

If change in the theta is less than given value then the
algorithm will stop training

return: $this

setEarlyStop(bool $enable = true)   X-Ref
Enable/Disable early stopping by checking at each iteration
whether changes in theta or cost value are not large enough

return: $this

setLearningRate(float $learningRate)   X-Ref

return: $this

setMaxIterations(int $maxIterations)   X-Ref

return: $this

runOptimization(array $samples, array $targets, Closure $gradientCb)   X-Ref
Optimization procedure finds the unknow variables for the equation A.ϴ = y
for the given samples (A) and targets (y).<br>

The cost function to minimize and the gradient of the function are to be
handled by the callback function provided as the third parameter of the method.

getCostValues()   X-Ref
Returns the list of cost values for each iteration executed in
last run of the optimization


updateTheta()   X-Ref
No description

earlyStop(array $oldTheta)   X-Ref
Checks if the optimization is not effective enough and can be stopped
in case large enough changes in the solution do not happen


clear()   X-Ref
No description