package org.jmat.test;
import org.jmat.data.*;
import org.jmat.data.matrixDecompositions.*;
import org.jmat.gui.*;
/**
* <p>Description : Principal Component Analysis</p>
* <p>Copyright : GPL</p>
* @author Yann RICHET
*/
public class PCA {
private AbstractMatrix covariance;
private AbstractMatrix EigenVectors;
private AbstractMatrix EigenValues;
public PCA(AbstractMatrix X) {
covariance = new RandomMatrix(X).covariance();
EigenvalueDecomposition e = covariance.eig();
EigenVectors = e.getV();
EigenValues = e.getD();
}
public AbstractMatrix getVectors() {
return EigenVectors;
}
public AbstractMatrix getValues() {
return EigenValues;
}
public static void main(String[] arg) {
//construct the matrix X
AbstractMatrix x1 = RandomMatrix.normal(100, 1, 0, 1);
AbstractMatrix x2 = RandomMatrix.normal(100, 1, 0, 1);
AbstractMatrix X = x1.plus(x2).mergeColumns(x2);
PCA pca = new PCA(X);
//display a Frame with data in a 2D-Plot and EigenValues and EigenVectors in the command line.
new FrameView(X.toPlot2DPanel("[x1+x2,x2]", PlotPanel.SCATTER));
pca.getValues().toCommandLine("EigenValues");
pca.getVectors().toCommandLine("EigenVectors");
}
}
| Matrix construction &
manipulations |
Matrix linear algebra functions |
Matrix decompositions & tools |
I/O |
Statistical tools |
| from double[][] identity random increment get / set element get / set SubMatrix get / set Diagonal(s) get / set row(s) / column(s) resize merge reshape |
plus, minux, uminus times, ebeTimes divide, ebeDivide solve, inverse ebeLog, ebePow, ebeExp, ebeSin, ebeCos norm1, norm2, normInf, normFrobenius condition, determinant, trace, rank min, max, sum, product mean, variance, covariance, correlation |
Cholesky SVD QR Eigenvectors / EigenValues LU sort rows / columns find elements: == <= >= < > != shuffle rows / columns slice as a sample (for histogram) |
Plots 2D / 3D : - ScatterPlot - Histogram - LinePlot - BoxPlot - StairCasePlot - BarPlot XML / MathML ASCII Binary Little / Big endian |
random generators: - uniform - normal - lognormal - exponential - triangular - cauchy - beta - weibull - bootstrap - rejection |