Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
Phpml\DimensionReduction\PCA Class Reference
Inheritance diagram for Phpml\DimensionReduction\PCA:
Phpml\DimensionReduction\EigenTransformerBase Phpml\DimensionReduction\KernelPCA

Public Member Functions

 __construct (?float $totalVariance=null, ?int $numFeatures=null)
 PCA (Principal Component Analysis) used to explain given data with lower number of dimensions.
 
 fit (array $data)
 Takes a data and returns a lower dimensional version of this data while preserving $totalVariance or $numFeatures.
 
 transform (array $sample)
 Transforms the given sample to a lower dimensional vector by using the eigenVectors obtained in the last run of fit.
 

Public Attributes

int $numFeatures = null
 Number of features to be preserved after the reduction.
 
float $totalVariance = 0.9
 Total variance to be conserved after the reduction.
 

Protected Member Functions

 calculateMeans (array $data, int $n)
 
 eigenDecomposition (array $matrix)
 Calculates eigenValues and eigenVectors of the given matrix.
 
 normalize (array $data, int $n)
 Normalization of the data includes subtracting mean from each dimension therefore dimensions will be centered to zero.
 
 reduce (array $data)
 Returns the reduced data.
 

Protected Attributes

array $eigValues = []
 Top eigenValues of the matrix.
 
array $eigVectors = []
 Top eigenvectors of the matrix.
 
bool $fit = false
 
array $means = []
 

Constructor & Destructor Documentation

◆ __construct()

Phpml\DimensionReduction\PCA::__construct ( ?float $totalVariance = null,
?int $numFeatures = null )

PCA (Principal Component Analysis) used to explain given data with lower number of dimensions.

This analysis transforms the data to a lower dimensional version of it by conserving a proportion of total variance within the data. It is a lossy data compression technique.

Parameters
float$totalVarianceTotal explained variance to be preserved
int$numFeaturesNumber of features to be preserved
Exceptions
InvalidArgumentException

Member Function Documentation

◆ eigenDecomposition()

Phpml\DimensionReduction\EigenTransformerBase::eigenDecomposition ( array $matrix)
protectedinherited

Calculates eigenValues and eigenVectors of the given matrix.

Returns top eigenVectors along with the largest eigenValues. The total explained variance of these eigenVectors will be no less than desired $totalVariance value

◆ fit()

Phpml\DimensionReduction\PCA::fit ( array $data)

Takes a data and returns a lower dimensional version of this data while preserving $totalVariance or $numFeatures.


$data is an n-by-m matrix and returned array is n-by-k matrix where k <= m

Reimplemented in Phpml\DimensionReduction\KernelPCA.

◆ transform()

Phpml\DimensionReduction\PCA::transform ( array $sample)

Transforms the given sample to a lower dimensional vector by using the eigenVectors obtained in the last run of fit.

Exceptions
InvalidOperationException

Reimplemented in Phpml\DimensionReduction\KernelPCA.


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