|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectFacemorph.PCA
public class PCA
Principal Component Analysis data object
| Constructor Summary | |
|---|---|
PCA()
Constructs an empty PCA object |
|
| Method Summary | |
|---|---|
static void |
addToAverage(Template average1,
PCA pca1,
Template currentAverage,
int n,
int start,
BigMat data)
Incrementally updates the data matrix and currentAverage by adding the PCA data to them |
double[] |
analyse(double[] shifts)
Finds the PCA components given the point shifts given |
double[] |
analyse(double[] shifts,
double[] average)
Finds the PCA components given the point shifts given |
double[] |
analyse(double[] shifts,
double[] average,
int count)
Finds the PCA components given the point shifts given |
double[] |
analyse(double[] shifts,
int maxComp)
Finds the PCA components given the point shifts given |
double[] |
analyse(Template tem,
Template avTem)
Analyse a template to find the PCA weights |
double[] |
analyse(Template tem,
Template avTem,
int normalisation,
int[] normalisationPoints)
Analyse a template to find the PCA weights |
Template |
build(java.util.ArrayList<Template> templates,
int normalisation,
int[] normalisationPoints)
Builds a PCA from the set of Templates given |
int |
build(java.util.ArrayList<Template> templates,
Template avTem,
int normalisation,
int[] normalisationPoints)
Builds a PCA from the set of Templates given |
int |
build(BigMat data)
Builds a PCA from the data in a matrix form |
int |
build(BigMat data,
double[] weights)
Builds a PCA from a set of weighted samples |
java.util.ArrayList<Template> |
build(java.util.Vector<java.util.ArrayList<Template>> templateSets)
Builds a PCA from a set of template sets. |
int |
buildPCAandAverage(BigMat data,
double[] average)
Builds a PCA from the data in a matrix form |
java.util.ArrayList<Template> |
buildTemplateSet(java.lang.String fileName)
Builds a PCA from a set of template sets. |
java.util.ArrayList<double[]> |
buildVectors(java.util.Vector<java.util.ArrayList<double[]>> sets)
Builds a PCA from a set of vector sets. |
Template |
combine(PCA pca1,
Template average1,
PCA pca2,
Template average2)
Combine two PCA models into a single one. |
Template |
combine2(PCA pca1,
Template average1,
PCA pca2,
Template average2)
Combine two PCA models into a single one. |
int |
componentsExplainedBy(double var)
Returns the minimum number of components required to explain a certain amount of variance |
float[] |
findPCAFit(float[] shifts)
Finds the PCA components given the point shifts given |
BigMat |
getComponents()
Get the PCA components as a matrix |
BigMat |
getComponents(double[] average,
boolean normalise)
Gets the components as a matrix, pus 4 first rows hold linear approximations to rigid + scale parameters |
BigMat |
getComponents2(double[] average)
Gets the components as a BigMat plus 4 initial cols for rigid params |
BigMat |
getComponents3D(double[] average,
boolean normalise)
Gets the components as a matrix, pus 7 first rows hold linear approximations to rigid + scale parameters for 3D |
int |
getCount()
Gets the number of components in this PCA |
double |
getD(int i)
Gets the ith variance |
Template[] |
getIntersection(Template average1,
Template average2,
PCA pca,
double alpha,
double beta)
Find the least squares intersection between the two PCA models |
PCA |
getReduced(int max)
Gets a copy of this PCA with fewer components |
double |
getSD(int i)
|
int |
getSize()
Gets the size of samples in this PCA |
java.util.Vector<java.util.ArrayList<Template>> |
getTemplateSet(java.lang.String fileName)
Reads sets of templates from file into a Vector of ArrayList of Templates |
java.util.Vector<java.util.ArrayList<double[]>> |
getVectorSet(java.lang.String fileName)
Reads a set of vector sets from a file. |
static void |
main(java.lang.String[] args)
Main method used for testing |
java.util.Vector<java.util.ArrayList<Template>> |
makeMatchingSets(java.util.Vector<java.util.ArrayList<Template>> templateSets,
java.util.ArrayList<Template> averages,
double varianceToExplain)
Creates a set of matching sets from a set of Template sets. |
java.util.Vector<java.util.ArrayList<Template>> |
makeMatchingTemplateSets(java.lang.String fileName,
double pcVar)
Creates a set of matching sets from a set of Template sets. |
java.util.Vector<java.util.ArrayList<double[]>> |
makeMatchingVectorSets(java.lang.String fileName,
double pcVar)
Creates a set of matching sets from a set of double[] sets. |
java.util.Vector<java.util.ArrayList<double[]>> |
makeMatchingVectorSets(java.util.Vector<java.util.ArrayList<double[]>> templateSets,
java.util.ArrayList<double[]> averages,
double varianceToExplain)
Creates a set of matching vector sets from a set of vector sets. |
Template |
normaliseEyes(Template average,
Template average2)
Rotates this PCA so that it aligns with the new average |
Template |
project(Template tem,
Template av)
Projects the given Template into the closest approximation in the PCA space |
Template |
project(Template tem,
Template av,
boolean cap,
double capval)
Projects the given Template into the closest approximation in the PCA space |
Template |
project(Template tem,
Template av,
int left,
int right,
boolean cap,
double capval)
Projects the given Template into the closest approximation in the PCA space |
static void |
quickSort(double[] vals,
int[] order,
int start,
int len)
Does a quick sort on the values given |
boolean |
readBinary(java.io.InputStream is,
double maxvar)
Reads a PCA from a binary format (as produced by Psychomorph) |
boolean |
readBinary(java.lang.String file,
double maxvar)
Reads a PCA from a binary format (as produced by Psychomorph) |
static double |
readDouble(java.io.StreamTokenizer st)
Reads a double precision value from a text file |
void |
readText(java.io.InputStream in)
Read a text format PCA file from an InputStream |
void |
readText(java.io.Reader r)
Read a text format PCA file from a Reader |
void |
readText(java.util.Scanner sc)
Read a text format PCA file from a Scanner |
void |
readText(java.io.StreamTokenizer st)
Read a text format PCA file from a StreamTokenizer |
boolean |
readText(java.lang.String file)
Reads a PCA file in a text format |
boolean |
readText(java.net.URL url)
Read a text format PCA file from a URL |
double[] |
reconstruct(double[] parameters)
Create a vector from the component weights |
double[] |
reconstruct(double[] parameters,
double[] average)
Create a vector from the component weights |
double[] |
reconstruct(double[] parameters,
int maxComp)
Create a vector from the component weights |
float[] |
reconstruct(float[] parameters)
Create a vector from the component weights |
float[] |
reconstruct(float[] parameters,
int maxComp)
Create a vector from the component weights |
Template |
replaceMean(Template newMean,
Template oldMean,
int left,
int right,
boolean closest)
Replaces the mean of this PCA with a new mean aligned to the old using 2 point normalisation |
void |
setCount(float maxvar)
Set the number of components for this PCA |
void |
setCount(int c)
Set the number of components for this PCA |
void |
solve(BigMat data)
Builds this PCA from the data given |
void |
writeBinary(java.io.OutputStream out)
Writes a binary format PCA to the OutputStream |
boolean |
writeBinary(java.lang.String file)
Writes a PCA to file in a binary format |
boolean |
writeText(java.lang.String filename)
Writes this PCA in a text format |
void |
writeText(java.io.Writer fw)
Writes this PCA data to a writer in a text format |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PCA()
| Method Detail |
|---|
public PCA getReduced(int max)
max -
public static double readDouble(java.io.StreamTokenizer st)
throws java.io.IOException
st - The stream tokenizer to read from
java.io.IOException - could be thrown by the streamTokenizerpublic void setCount(int c)
c - public void setCount(float maxvar)
maxvar - the maximum variance this PCA should expresspublic BigMat getComponents()
public BigMat getComponents(double[] average,
boolean normalise)
average - the averagenormalise - indicates that the data should be normalised / orthogonalised
public BigMat getComponents3D(double[] average,
boolean normalise)
average - the averagenormalise - indicates that the data should be normalised / orthogonalised
public BigMat getComponents2(double[] average)
average - the average of this PCA
public int getCount()
public int getSize()
public double getD(int i)
i - the index of the variance to get
public double getSD(int i)
public int componentsExplainedBy(double var)
var - the amount of variance to explain
public boolean readText(java.lang.String file)
file - The file to read from
public boolean readText(java.net.URL url)
url - The URL to read from
public boolean writeText(java.lang.String filename)
filename - the name of the file to write to
public void writeText(java.io.Writer fw)
throws java.io.IOException
fw - the writer to write to
java.io.IOException
public void readText(java.io.InputStream in)
throws java.io.IOException
in - The InputStream to read from
java.io.IOException
public void readText(java.io.Reader r)
throws java.io.IOException
r - The Reader to read from
java.io.IOException
public void readText(java.io.StreamTokenizer st)
throws java.io.IOException
st - The StreamTokenizer to read from
java.io.IOException
public void readText(java.util.Scanner sc)
throws java.io.IOException
sc - The Scanner to read from
java.io.IOException
public boolean readBinary(java.lang.String file,
double maxvar)
throws java.io.FileNotFoundException,
java.io.IOException
file - the name of the file to read frommaxvar - the maximum fraction of variance to explain/read
java.io.FileNotFoundException
java.io.IOException
public boolean readBinary(java.io.InputStream is,
double maxvar)
throws java.io.IOException
is - the InputStream to read frommaxvar - the maximum fraction of variance to explain/read
java.io.IOExceptionpublic boolean writeBinary(java.lang.String file)
file - the file to write to
public void writeBinary(java.io.OutputStream out)
throws java.io.IOException
out - the OutputStream
java.io.IOException
public double[] analyse(Template tem,
Template avTem)
tem - the Template to analyseavTem - the average Template to subtract before analysis
public double[] analyse(Template tem,
Template avTem,
int normalisation,
int[] normalisationPoints)
tem - the Template to analyseavTem - the average Template to subtract before analysisnormalisation - one of ASM.TWO_POINT_NORMALISATION, ASM.RIGID_BODY_NORMALISATION or ASM.THREE_POINT_NORMALISATIONnormalisationPoints - the indices of points to use in the normalisation (if any)
public double[] analyse(double[] shifts)
shifts - The shifts from the mean
public double[] analyse(double[] shifts,
double[] average)
shifts - The shifts from the meanaverage - the average, this will be subtracted before analysis
public double[] analyse(double[] shifts,
double[] average,
int count)
shifts - The shifts from the meanaverage - the average, this will be subtracted before analysiscount - number of pca parameters to use
public Template project(Template tem,
Template av,
boolean cap,
double capval)
tem - the Template to approximateav - the average Templatecap - flag indicating if large parameter values should be cappedcapval - the multiple of the standr deviation to cap each parameter at
public Template project(Template tem,
Template av)
tem - the Template to approximateav - the average Template
public Template project(Template tem,
Template av,
int left,
int right,
boolean cap,
double capval)
tem - the Template to approximateav - the average Templateleft - the index of the first normalisation pointright - the index of the second normalisation pointcap - flag indicating if large parameter values should be cappedcapval - the multiple of the standr deviation to cap each parameter at
public double[] analyse(double[] shifts,
int maxComp)
shifts - The shifts from the meanmaxComp - The maximum number of components to use
public float[] findPCAFit(float[] shifts)
shifts - The shifts from the mean
public double[] reconstruct(double[] parameters)
parameters - The weights of the PCs
public double[] reconstruct(double[] parameters,
double[] average)
parameters - The weights of the PCsaverage - Th mean of the PCA distribution
public float[] reconstruct(float[] parameters)
parameters - The weights of the PCs
public double[] reconstruct(double[] parameters,
int maxComp)
parameters - The weights of the PCsmaxComp - The maximum number of components to use
public float[] reconstruct(float[] parameters,
int maxComp)
parameters - The weights of the PCsmaxComp - The maximum number of components to use
public Template build(java.util.ArrayList<Template> templates,
int normalisation,
int[] normalisationPoints)
templates - a list of templates to build the PCA fromnormalisation - a flag indicating which kind of normalisation to use (2 point, 3 point or best fit)normalisationPoints - the list of normalisation point indexes to use
public int build(java.util.ArrayList<Template> templates,
Template avTem,
int normalisation,
int[] normalisationPoints)
templates - a list of templates to build the PCA fromavTem - the average template, should be the average of the setnormalisation - a flag indicating which kind of normalisation to use (2 point, 3 point or best fit)normalisationPoints - the list of normalisation point indexes to use
public java.util.ArrayList<Template> build(java.util.Vector<java.util.ArrayList<Template>> templateSets)
templateSets - a list of Template lists
public java.util.Vector<java.util.ArrayList<Template>> makeMatchingSets(java.util.Vector<java.util.ArrayList<Template>> templateSets,
java.util.ArrayList<Template> averages,
double varianceToExplain)
templateSets - the set of original template setsaverages - the average of each template setvarianceToExplain - the fraction of variance to explain in the output components
public java.util.Vector<java.util.ArrayList<Template>> makeMatchingTemplateSets(java.lang.String fileName,
double pcVar)
fileName - the name of the text file listing the templates to usepcVar - the fraction of variance to explain
public java.util.Vector<java.util.ArrayList<double[]>> makeMatchingVectorSets(java.lang.String fileName,
double pcVar)
fileName - the name of the text file listing the values to usepcVar - the fraction of variance to explain
public java.util.ArrayList<double[]> buildVectors(java.util.Vector<java.util.ArrayList<double[]>> sets)
sets - the sets of double values to build from
public java.util.Vector<java.util.ArrayList<double[]>> makeMatchingVectorSets(java.util.Vector<java.util.ArrayList<double[]>> templateSets,
java.util.ArrayList<double[]> averages,
double varianceToExplain)
templateSets - the set of vectors to matchaverages - the array of within set and global averagesvarianceToExplain - the variance to explain in this model
public java.util.ArrayList<Template> buildTemplateSet(java.lang.String fileName)
fileName - the name of a text file listing the templates to use
public java.util.Vector<java.util.ArrayList<Template>> getTemplateSet(java.lang.String fileName)
fileName - the name of a text file containing a list of text file names,
each of which lists images and templates for a particular subject
public java.util.Vector<java.util.ArrayList<double[]>> getVectorSet(java.lang.String fileName)
fileName - the name of the file containing the vector sets.
public int build(BigMat data)
data - The BigMat containing the data samples as rows
public int buildPCAandAverage(BigMat data,
double[] average)
data - The BigMat containing the data samples as rowsaverage - used to return the average of the sample
public int build(BigMat data,
double[] weights)
data - the matrix of data samples as rowsweights - the weighting of each row
public static void quickSort(double[] vals,
int[] order,
int start,
int len)
vals - the values to sortorder - records the reordering so the same sorting to be applied to the associated
vectors, should initially be in order from 0.start - the start of the portion of the array to sortlen - the length of the portion of the array to sort
public Template[] getIntersection(Template average1,
Template average2,
PCA pca,
double alpha,
double beta)
average1 - the mean of this PCAaverage2 - the mean of pcapca - the other PCAalpha - a regularisation term for this (not currently used)beta - a regularisation term for pca (not currently used)
public Template replaceMean(Template newMean,
Template oldMean,
int left,
int right,
boolean closest)
newMean - the new averageoldMean - the old averageleft - the left normalisation pointright - the right normalisation pointclosest - boolean indicating if the new mean should be the old mean projected into
the PCA space with newMean as its centre.
public Template normaliseEyes(Template average,
Template average2)
average - the current centreaverage2 - the new centre
public static void addToAverage(Template average1,
PCA pca1,
Template currentAverage,
int n,
int start,
BigMat data)
average1 - the average of the PCA datapca1 - the PCA data to addcurrentAverage - the current global averagen - the number of templates and PCAs previously addedstart - the index to start filling in the data matrix rows fromdata - the place to put the scaled principal components from pca1public void solve(BigMat data)
data - the data to build from, samples as rows
public Template combine(PCA pca1,
Template average1,
PCA pca2,
Template average2)
pca1 - The first PCAaverage1 - The average of the first PCApca2 - The second PCAaverage2 - The average of the second PCA
public Template combine2(PCA pca1,
Template average1,
PCA pca2,
Template average2)
pca1 - The first PCAaverage1 - The average of the first PCApca2 - The second PCAaverage2 - The average of the second PCA
public static void main(java.lang.String[] args)
args -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||