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.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

(no description)

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

Defines 1 class

Perceptron:: (13 methods):
  __construct()
  partialTrain()
  trainBinary()
  setEarlyStop()
  getCostValues()
  resetBinary()
  runTraining()
  runGradientDescent()
  checkNormalizedSample()
  output()
  outputClass()
  predictProbability()
  predictSampleBinary()


Class: Perceptron  - X-Ref

__construct(float $learningRate = 0.001, int $maxIterations = 1000, bool $normalizeInputs = true)   X-Ref
Initalize a perceptron classifier with given learning rate and maximum
number of iterations used while training the perceptron

param: float $learningRate  Value between 0.0(exclusive) and 1.0(inclusive)
param: int   $maxIterations Must be at least 1

partialTrain(array $samples, array $targets, array $labels = [])   X-Ref
No description

trainBinary(array $samples, array $targets, array $labels)   X-Ref
No description

setEarlyStop(bool $enable = true)   X-Ref
Normally enabling early stopping for the optimization procedure may
help saving processing time while in some cases it may result in
premature convergence.<br>

If "false" is given, the optimization procedure will always be executed
for $maxIterations times

return: $this

getCostValues()   X-Ref
Returns the cost values obtained during the training.


resetBinary()   X-Ref
No description

runTraining(array $samples, array $targets)   X-Ref
Trains the perceptron model with Stochastic Gradient Descent optimization
to get the correct set of weights


runGradientDescent(array $samples, array $targets, Closure $gradientFunc, bool $isBatch = false)   X-Ref
Executes a Gradient Descent algorithm for
the given cost function


checkNormalizedSample(array $sample)   X-Ref
Checks if the sample should be normalized and if so, returns the
normalized sample


output(array $sample)   X-Ref
Calculates net output of the network as a float value for the given input

return: int|float

outputClass(array $sample)   X-Ref
Returns the class value (either -1 or 1) for the given input


predictProbability(array $sample, $label)   X-Ref
Returns the probability of the sample of belonging to the given label.

The probability is simply taken as the distance of the sample
to the decision plane.

param: mixed $label

predictSampleBinary(array $sample)   X-Ref

return: mixed