Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

(no description)

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

Defines 1 class

LDA:: (8 methods):
  __construct()
  fit()
  transform()
  getLabels()
  calculateMeans()
  calculateClassVar()
  calculateClassCov()
  calculateVar()


Class: LDA  - X-Ref

__construct(?float $totalVariance = null, ?int $numFeatures = null)   X-Ref
Linear Discriminant Analysis (LDA) is used to reduce the dimensionality
of the data. Unlike Principal Component Analysis (PCA), it is a supervised
technique that requires the class labels in order to fit the data to a
lower dimensional space. <br><br>
The algorithm can be initialized by speciyfing
either with the totalVariance(a value between 0.1 and 0.99)
or numFeatures (number of features in the dataset) to be preserved.

param: float|null $totalVariance Total explained variance to be preserved
param: int|null   $numFeatures   Number of features to be preserved

fit(array $data, array $classes)   X-Ref
Trains the algorithm to transform the given data to a lower dimensional space.


transform(array $sample)   X-Ref
Transforms the given sample to a lower dimensional vector by using
the eigenVectors obtained in the last run of <code>fit</code>.


getLabels(array $classes)   X-Ref
Returns unique labels in the dataset


calculateMeans(array $data, array $classes)   X-Ref
Calculates mean of each column for each class and returns
n by m matrix where n is number of labels and m is number of columns


calculateClassVar(array $data, array $classes)   X-Ref
Returns in-class scatter matrix for each class, which
is a n by m matrix where n is number of classes and
m is number of columns


calculateClassCov()   X-Ref
Returns between-class scatter matrix for each class, which
is an n by m matrix where n is number of classes and
m is number of columns


calculateVar(array $row, array $means)   X-Ref
Returns the result of the calculation (x - m)T.(x - m)