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.

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

(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