org.openimaj.math.matrix.algorithm

## Class LinearDiscriminantAnalysis

• java.lang.Object
• org.openimaj.math.matrix.algorithm.LinearDiscriminantAnalysis

• ```@Reference(type=Article,
author="Fisher, Ronald A.",
title="{The use of multiple measurements in taxonomic problems}",
year="1936",
journal="Annals Eugen.",
pages={"179","","188"},
volume="7",
customData={"citeulike-article-id","764226","keywords","classification","posted-at","2006-09-18 14:06:16","priority","2"})
public class LinearDiscriminantAnalysis
extends Object```
Implementation of Multiclass Linear Discriminant Analysis.
Author:
Jonathon Hare (jsh2@ecs.soton.ac.uk)
• ### Field Summary

Fields
Modifier and Type Field and Description
`protected double[]` `eigenvalues`
`protected Jama.Matrix` `eigenvectors`
`protected double[]` `mean`
`protected int` `numComponents`
• ### Constructor Summary

Constructors
Constructor and Description
`LinearDiscriminantAnalysis(int numComponents)`
Construct with the given number of components.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double[]` `generate(double[] scalings)`
Generate a new "observation" as a linear combination of the eigenvectors (ev): mean + ev * scaling.
`Jama.Matrix` `getBasis()`
Get the basis (the LDA eigenvectors)
`double[]` `getBasisVector(int index)`
Get a specific basis vector as a double array.
`double` `getEigenValue(int i)`
Get the eigen value corresponding to the ith principal component.
`double[]` `getEigenValues()`
`Jama.Matrix` `getEigenVectors()`
Get the basis eigenvectors.
`double[]` `getMean()`
`void` `learnBasis(List<double[][]> data)`
Learn the LDA basis.
`void` `learnBasis(Map<?,double[][]> data)`
Learn the LDA basis.
`void` `learnBasisIP(List<? extends IndependentPair<?,double[]>> data)`
Learn the LDA basis.
`void` `learnBasisLL(List<List<double[]>> data)`
Learn the LDA basis.
`void` `learnBasisML(Map<?,List<double[]>> data)`
Learn the LDA basis.
`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.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### numComponents

`protected int numComponents`
• #### eigenvectors

`protected Jama.Matrix eigenvectors`
• #### eigenvalues

`protected double[] eigenvalues`
• #### mean

`protected double[] mean`
• ### Constructor Detail

• #### LinearDiscriminantAnalysis

`public LinearDiscriminantAnalysis(int numComponents)`
Construct with the given number of components.
Parameters:
`numComponents` - the number of components.
• ### Method Detail

• #### learnBasisIP

`public void learnBasisIP(List<? extends IndependentPair<?,double[]>> data)`
Learn the LDA basis.
Parameters:
`data` - data grouped by class
• #### learnBasisML

`public void learnBasisML(Map<?,List<double[]>> data)`
Learn the LDA basis.
Parameters:
`data` - data grouped by class
• #### learnBasisLL

`public void learnBasisLL(List<List<double[]>> data)`
Learn the LDA basis.
Parameters:
`data` - data grouped by class
• #### learnBasis

`public void learnBasis(Map<?,double[][]> data)`
Learn the LDA basis.
Parameters:
`data` - data grouped by class
• #### learnBasis

`public void learnBasis(List<double[][]> data)`
Learn the LDA basis.
Parameters:
`data` - data grouped by class
• #### getBasis

`public Jama.Matrix getBasis()`
Get the basis (the LDA eigenvectors)
Returns:
the eigenvectors
• #### getBasisVector

`public double[] getBasisVector(int index)`
Get a specific basis vector as a double array. The returned array contains a copy of the data.
Parameters:
`index` - the index of the vector
Returns:
the eigenvector
• #### getEigenVectors

`public Jama.Matrix getEigenVectors()`
Get the basis eigenvectors. Each of column vector of the returned matrix is an eigenvector. Syntactic sugar for `getBasis()`
Returns:
the eigenvectors
• #### getEigenValues

`public double[] getEigenValues()`
Returns:
the eigen values corresponding to the principal components
• #### getEigenValue

`public double getEigenValue(int i)`
Get the eigen value corresponding to the ith principal component.
Parameters:
`i` - the index of the component
Returns:
the eigen value corresponding to the principal component
• #### getMean

`public double[] getMean()`
Returns:
The mean values
• #### generate

`public double[] generate(double[] scalings)`
Generate a new "observation" as a linear combination of the eigenvectors (ev): mean + ev * scaling.

If the scaling vector is shorter than the number of components, it will be zero-padded. If it is longer, it will be truncated.

Parameters:
`scalings` - the weighting for each eigenvector
Returns:
generated observation
• #### project

`public Jama.Matrix project(Jama.Matrix m)`
Project a matrix of row vectors by the basis. The vectors are normalised by subtracting the mean and then multiplied by the basis. The returned matrix has a row for each vector.
Parameters:
`m` - the vector to project
Returns:
projected vectors
• #### project

`public double[] project(double[] vector)`
Project a vector by the basis. The vector is normalised by subtracting the mean and then multiplied by the basis.
Parameters:
`vector` - the vector to project
Returns:
projected vector