public abstract class PrincipalComponentAnalysis extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
PrincipalComponentAnalysis.ComponentSelector
Interface for classes capable of selecting a subset of the PCA components
|
static class |
PrincipalComponentAnalysis.EnergyThresholdComponentSelector
PrincipalComponentAnalysis.ComponentSelector that selects a subset of the principal
components such that all remaining components have a cumulative energy
less than the given value. |
static class |
PrincipalComponentAnalysis.NumberComponentSelector
PrincipalComponentAnalysis.ComponentSelector that selects the n-best components. |
static class |
PrincipalComponentAnalysis.PercentageEnergyComponentSelector
PrincipalComponentAnalysis.ComponentSelector that selects a subset of the principal
components such that all remaining components have a certain percentage
cumulative energy of the total. |
| Modifier and Type | Field and Description |
|---|---|
protected Jama.Matrix |
basis |
protected double[] |
eigenvalues |
protected double[] |
mean |
| Constructor and Description |
|---|
PrincipalComponentAnalysis() |
| Modifier and Type | Method and Description |
|---|---|
protected Jama.Matrix |
buildNormalisedDataMatrix(Jama.Matrix m)
Zero-centre the data matrix and return a copy
|
double[] |
generate(double[] scalings)
Generate a new "observation" as a linear combination of the principal
components (PC): mean + PC * scaling.
|
Jama.Matrix |
getBasis()
Get the principal components.
|
double[] |
getCumulativeEnergies()
Get the cumulative energies of each principal component
|
double |
getCumulativeEnergy(int i)
Get the cumulative energy of the ith principal component
|
double |
getEigenValue(int i)
Get the eigen value corresponding to the ith principal component.
|
double[] |
getEigenValues() |
Jama.Matrix |
getEigenVectors()
Get the principal components.
|
double[] |
getMean() |
double[] |
getPrincipalComponent(int index)
Get a specific principle component vector as a double array.
|
double[] |
getStandardDeviations()
Get the standard deviations (sqrt of eigenvalues) of the principal
components.
|
double[] |
getStandardDeviations(int n)
Get the standard deviations (sqrt of eigenvalues) of the n top principal
components.
|
void |
learnBasis(double[][] data)
Learn the principal components of the given data array.
|
void |
learnBasis(List<double[]> data)
Learn the principal components of the given data list.
|
void |
learnBasis(Jama.Matrix data)
Learn the principal components of the given data matrix.
|
protected abstract void |
learnBasisNorm(Jama.Matrix norm)
Learn the PCA basis from the centered data provided.
|
double[] |
project(double[] vector)
Project a vector by the basis.
|
Jama.Matrix |
project(Jama.Matrix m)
Project a matrix of row vectors by the basis.
|
void |
selectSubset(int n)
Select a subset of the principal components.
|
void |
selectSubset(PrincipalComponentAnalysis.ComponentSelector selector)
Select a subset of the principal components using a
PrincipalComponentAnalysis.ComponentSelector. |
void |
selectSubsetEnergyThreshold(double threshold)
Select a subset of the principal components such that all remaining
components have a cumulative energy less than the given value.
|
void |
selectSubsetPercentageEnergy(double percentage)
Select a subset of the principal components such that all remaining
components have a certain percentage cumulative energy of the total.
|
String |
toString() |
protected Jama.Matrix basis
protected double[] mean
protected double[] eigenvalues
public PrincipalComponentAnalysis()
public void learnBasis(List<double[]> data)
data - the datapublic void learnBasis(double[][] data)
data - the datapublic void learnBasis(Jama.Matrix data)
data - the dataprotected abstract void learnBasisNorm(Jama.Matrix norm)
norm - protected Jama.Matrix buildNormalisedDataMatrix(Jama.Matrix m)
data - the data matrixpublic Jama.Matrix getBasis()
public double[] getPrincipalComponent(int index)
index - the index of the principle componentpublic Jama.Matrix getEigenVectors()
getBasis()public double[] getEigenValues()
public double getEigenValue(int i)
i - the index of the componentpublic double getCumulativeEnergy(int i)
i - the index of the componentpublic double[] getCumulativeEnergies()
public double[] getMean()
public void selectSubset(PrincipalComponentAnalysis.ComponentSelector selector)
PrincipalComponentAnalysis.ComponentSelector. Calling this method throws away any extra
basis vectors and eigenvalues.selector - the PrincipalComponentAnalysis.ComponentSelector to applypublic void selectSubset(int n)
n - public void selectSubsetEnergyThreshold(double threshold)
threshold - threshold on the cumulative energy.public void selectSubsetPercentageEnergy(double percentage)
selectSubset(int),
selectSubsetEnergyThreshold(double) or
selectSubsetPercentageEnergy(double), then the percentage
calculation only factors in the remaining eigenvalues that are available
to it.
Calling this method throws away any extra basis vectors and eigenvalues.percentage - percentage of the total cumulative energy to retain [0..1].public double[] generate(double[] scalings)
scalings - the weighting for each PCpublic Jama.Matrix project(Jama.Matrix m)
m - the vector to projectpublic double[] project(double[] vector)
vector - the vector to projectpublic double[] getStandardDeviations()
public double[] getStandardDeviations(int n)
n - number of principal components