Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

(no description)

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

Defines 1 class

KernelPCA:: (8 methods):
  __construct()
  fit()
  transform()
  calculateKernelMatrix()
  centerMatrix()
  getKernel()
  getDistancePairs()
  projectSample()


Class: KernelPCA  - X-Ref

__construct(int $kernel = self::KERNEL_RBF, ?float $totalVariance = null, ?int $numFeatures = null, ?float $gamma = null)   X-Ref
Kernel principal component analysis (KernelPCA) is an extension of PCA using
techniques of kernel methods. It is more suitable for data that involves
vectors that are not linearly separable<br><br>
Example: <b>$kpca = new KernelPCA(KernelPCA::KERNEL_RBF, null, 2, 15.0);</b>
will initialize the algorithm with an RBF kernel having the gamma parameter as 15,0. <br>
This transformation will return the same number of rows with only <i>2</i> columns.

param: float $totalVariance Total variance to be preserved if numFeatures is not given
param: int   $numFeatures   Number of columns to be returned
param: float $gamma         Gamma parameter is used with RBF and Sigmoid kernels

fit(array $data)   X-Ref
Takes a data and returns a lower dimensional version
of this data while preserving $totalVariance or $numFeatures. <br>
$data is an n-by-m matrix and returned array is
n-by-k matrix where k <= m


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


calculateKernelMatrix(array $data, int $numRows)   X-Ref
Calculates similarity matrix by use of selected kernel function<br>
An n-by-m matrix is given and an n-by-n matrix is returned


centerMatrix(array $matrix, int $n)   X-Ref
Kernel matrix is centered in its original space by using the following
conversion:

K′ = K − N.K −  K.N + N.K.N where N is n-by-n matrix filled with 1/n

getKernel()   X-Ref
Returns the callable kernel function


getDistancePairs(array $sample)   X-Ref
No description

projectSample(array $pairs)   X-Ref
No description