Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
Phpml\Classification\Linear\Perceptron Class Reference
Inheritance diagram for Phpml\Classification\Linear\Perceptron:
Phpml\Classification\Classifier Phpml\IncrementalEstimator Phpml\Estimator Phpml\Classification\Linear\Adaline

Public Member Functions

 __construct (float $learningRate=0.001, int $maxIterations=1000, bool $normalizeInputs=true)
 Initalize a perceptron classifier with given learning rate and maximum number of iterations used while training the perceptron.
 
 getCostValues ()
 Returns the cost values obtained during the training.
 
 partialTrain (array $samples, array $targets, array $labels=[])
 
 predict (array $samples)
 
 setEarlyStop (bool $enable=true)
 Normally enabling early stopping for the optimization procedure may help saving processing time while in some cases it may result in premature convergence.
 
 train (array $samples, array $targets)
 
 trainBinary (array $samples, array $targets, array $labels)
 

Protected Member Functions

 checkNormalizedSample (array $sample)
 Checks if the sample should be normalized and if so, returns the normalized sample.
 
 output (array $sample)
 Calculates net output of the network as a float value for the given input.
 
 outputClass (array $sample)
 Returns the class value (either -1 or 1) for the given input.
 
 predictProbability (array $sample, $label)
 Returns the probability of the sample of belonging to the given label.
 
 predictSampleBinary (array $sample)
 
 resetBinary ()
 
 runGradientDescent (array $samples, array $targets, Closure $gradientFunc, bool $isBatch=false)
 Executes a Gradient Descent algorithm for the given cost function.
 
 runTraining (array $samples, array $targets)
 Trains the perceptron model with Stochastic Gradient Descent optimization to get the correct set of weights.
 

Protected Attributes

bool $enableEarlyStop = true
 
int $featureCount = 0
 
array $labels = []
 
float $learningRate
 
int $maxIterations
 
Normalizer $normalizer
 
Optimizer GD StochasticGD null $optimizer
 
array $weights = []
 

Constructor & Destructor Documentation

◆ __construct()

Phpml\Classification\Linear\Perceptron::__construct ( float $learningRate = 0.001,
int $maxIterations = 1000,
bool $normalizeInputs = true )

Initalize a perceptron classifier with given learning rate and maximum number of iterations used while training the perceptron.

Parameters
float$learningRateValue between 0.0(exclusive) and 1.0(inclusive)
int$maxIterationsMust be at least 1
Exceptions
InvalidArgumentException

Member Function Documentation

◆ output()

Phpml\Classification\Linear\Perceptron::output ( array $sample)
protected

Calculates net output of the network as a float value for the given input.

Return values
int|float

◆ partialTrain()

Phpml\Classification\Linear\Perceptron::partialTrain ( array $samples,
array $targets,
array $labels = [] )

◆ predict()

Phpml\Estimator::predict ( array $samples)
inherited

Implemented in Phpml\Pipeline.

◆ predictProbability()

Phpml\Classification\Linear\Perceptron::predictProbability ( array $sample,
$label )
protected

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.

Parameters
mixed$label

◆ predictSampleBinary()

Phpml\Classification\Linear\Perceptron::predictSampleBinary ( array $sample)
protected
Return values
mixed

◆ runTraining()

Phpml\Classification\Linear\Perceptron::runTraining ( array $samples,
array $targets )
protected

Trains the perceptron model with Stochastic Gradient Descent optimization to get the correct set of weights.

Reimplemented in Phpml\Classification\Linear\Adaline.

◆ setEarlyStop()

Phpml\Classification\Linear\Perceptron::setEarlyStop ( bool $enable = true)

Normally enabling early stopping for the optimization procedure may help saving processing time while in some cases it may result in premature convergence.


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

Return values
$this

◆ train()

Phpml\Estimator::train ( array $samples,
array $targets )
inherited

The documentation for this class was generated from the following file: