jhplot.math.pca
Class PCA
- java.lang.Object
-
- jhplot.math.pca.PCA
-
public final class PCA extends java.lang.Object
The class responsible mainly for preparing the PCA transformation parameters based on training data and executing the actual transformation on test data.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
PCA.TransformationType
Type of the possible data transformation.
-
Constructor Summary
Constructors Constructor and Description PCA(Matrix data)
Create the PCA transformation.PCA(Matrix data, boolean center)
Create the PCA transformation.PCA(Matrix data, CovarianceMatrixEVDCalculator evdCalc)
Create the PCA transformation.PCA(Matrix data, CovarianceMatrixEVDCalculator evdCalc, boolean center)
Create the PCA transformation
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean
belongsToGeneratedSubspace(Matrix pt)
Check if given point lies in PCA-generated subspace.static Matrix
calculateCovarianceMatrix(Matrix data)
Function for JUnit testing purposes onlydouble
getEigenvalue(int dimNo)
Get selected eigenvalueMatrix
getEigenvectorsMatrix()
int
getInputDimsNo()
Get number of dimensions of the input vectorsint
getOutputDimsNo()
Get number of dimensions of the output vectorsMatrix
transform(Matrix data, PCA.TransformationType type)
Execute selected transformation on given data.
-
-
-
Constructor Detail
-
PCA
public PCA(Matrix data)
Create the PCA transformation. Use the popular SVD method for internal calculations- Parameters:
data
- data matrix used to compute the PCA transformation. Rows of the matrix are the instances/samples, columns are dimensions. It is assumed that the matrix is already centered.
-
PCA
public PCA(Matrix data, boolean center)
Create the PCA transformation. Use the popular SVD method for internal calculations- Parameters:
data
- data matrix used to compute the PCA transformation. Rows of the matrix are the instances/samples, columns are dimensions.center
- should the data matrix be centered before doing the calculations?
-
PCA
public PCA(Matrix data, CovarianceMatrixEVDCalculator evdCalc)
Create the PCA transformation.- Parameters:
data
- data matrix used to compute the PCA transformation. Rows of the matrix are the instances/samples, columns are dimensions. It is assumed that the matrix is already centered.evdCalc
- method of computing eigenvalue decomposition of data's covariance matrix
-
PCA
public PCA(Matrix data, CovarianceMatrixEVDCalculator evdCalc, boolean center)
Create the PCA transformation- Parameters:
data
- data matrix used to compute the PCA transformation. Rows of the matrix are the instances/samples, columns are dimensions.evdCalc
- method of computing eigenvalue decomposition of data's covariance matrixcenter
- should the data matrix be centered before doing the calculations?
-
-
Method Detail
-
getEigenvectorsMatrix
public Matrix getEigenvectorsMatrix()
- Returns:
- matrix where eigenvectors are placed in columns
-
getEigenvalue
public double getEigenvalue(int dimNo)
Get selected eigenvalue- Parameters:
dimNo
- dimension number corresponding to given eigenvalue
-
getInputDimsNo
public int getInputDimsNo()
Get number of dimensions of the input vectors
-
getOutputDimsNo
public int getOutputDimsNo()
Get number of dimensions of the output vectors
-
transform
public Matrix transform(Matrix data, PCA.TransformationType type)
Execute selected transformation on given data.- Parameters:
data
- data to transform. Rows of the matrix are the instances/samples, columns are dimensions. If the original PCA data matrix was set to be centered, this matrix will also be centered using the same parameters.type
- transformation to apply- Returns:
- transformed data
-
belongsToGeneratedSubspace
public boolean belongsToGeneratedSubspace(Matrix pt)
Check if given point lies in PCA-generated subspace. If it does not, it means that the point doesn't belong to the transformation domain i.e. it is an outlier.- Parameters:
pt
- point. If the original PCA data matrix was set to be centered, this point will also be centered using the same parameters.- Returns:
- true iff the point lies on all principal axes
-
-
DMelt 3.0 © DataMelt by jWork.ORG