|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object Facemorph.tensor.Tensor
public class Tensor
Tensor model implementation
Constructor Summary | |
---|---|
Tensor()
Creates a new instance of Tensor |
|
Tensor(int[] dims)
constructor |
|
Tensor(int[] dims,
double[] data)
Constructor with some data |
Method Summary | |
---|---|
void |
addRowAverages(Tensor rowAvs,
int dim,
int dataDim)
Add row average |
void |
addRowAveragesInPlace(Tensor average,
int row)
Add the row average for each row to each element along that row |
static void |
adjust(double[] params,
double[] mean,
double[] sd)
Subtracts the mean and multiplies by the standard deviation |
static void |
adjust(double[] params,
int start,
int end,
double amount)
multiplies elements of params from start to end by amount |
BigMat[] |
build(boolean rotate,
double[][] weights)
build N-way model, replace this with the core tensor and return the rotation components. |
BigMat[] |
build(boolean rotate,
double[][] weights,
int dataDim)
build N-way model, replace this with the core tensor and return the rotation components. |
static java.awt.Image |
buildAverageFromWarped(java.util.Vector<java.awt.Image> images)
Build an average from a set of warped images |
BigMat[] |
buildWithAverage(double[][] weights,
int dataDim,
double maxvar)
build N-way model, replace this with the core tensor and return the rotation components |
BigMat[] |
buildWithAverageInPlace(double[][] weights,
int dataDim,
double maxvar)
build N-way model, replace this with the core tensor and return the rotation components |
double[][] |
convertParams(double[] params,
int dataDim)
Convert a single set of linear parameters into a set of parameters alon each direction |
void |
copy(Tensor rhs)
Copy another Tensor |
static BigMat |
createAverageAndSubtractMatrix(int width)
Creates the matrix that can be used to calculate and subtract the average from rows of length width |
static void |
createExampleData(java.lang.String[] args)
Create some example data, reconstructs some example images |
static void |
deAdjust(double[] params,
double[] mean,
double[] sd)
Reverse the whitening |
void |
fold(int i,
BigMat M)
Fold the matrix into this Tensor along the axis given |
double |
get(int[] in)
Sample from the Tensor |
static double[] |
getALSWeights(BigMat coeffs,
double[] testData)
Get the paramter weights for test data using linear matrix coeffs |
double[][] |
getALSWeights(double[] testData,
double[][] params,
int dataDim,
int maxIts)
Get the alternating least squares estimate of the weights |
double[][] |
getBestRankTensor(int rank)
Gets the best tensor of the given rank |
BigMat |
getCovar(int i,
boolean skipFirst)
unfold method, unfolds along a dimension i |
BigMat |
getFullLinearAnalysisMatrix(int dataDim,
BigMat average,
boolean skipFirst)
Get the fll tensor as a linear analysis matrix |
static Tensor |
getImageTensor(int[] dims,
java.util.Vector<java.awt.Image> images)
Create a Tensor from a set of images |
BigMat |
getLinearAnalysisMatrix(int dataDim,
BigMat average)
Gets a linear analysis matrix |
static Tensor |
getOuterProduct(double[][] vecs)
Gets the outer product tensor from the array of vectors |
static Tensor |
getOuterProductAppend1(double[][] vecs)
Gets the outer product tensor when each parameter vector has 1 appended/prepended at the start |
double |
getRankWeight(double[][] vecs)
Returns data[0]/product(vecs[i][0]) |
Tensor |
getRowAverage(int row)
Gets the row average |
static Tensor |
getTemplateTensor(int[] dims,
java.util.Vector<Template> templates)
Get A Tensor from a set of Templates |
double[] |
getVariance(double[] mean,
int dim)
Get the variance along the dimension specified |
protected int |
index(int[] in)
return the index into the data at point in[i,j,k...n] |
java.util.Iterator<java.lang.Double> |
iterator()
Returns an iterator over a set of elements of type T. |
java.util.Iterator<java.lang.Double> |
iterator(int dim)
Returns an iterator over a set of elements of type T. |
static double[] |
linearAnalyse(BigMat linearModel,
BigMat average,
double[] testData)
Analyse some test data with a linear model |
static void |
main(java.lang.String[] args)
Main method for testing |
Tensor |
multiply(int i,
BigMat M)
multiply method for N-mode product with M along row i |
void |
multiplyInPlace(int i,
BigMat M)
multiply method for N-mode product with M along row i |
static double |
normalisedScalarProduct(double[] v,
double[] u)
Normalised scalar product |
BigMat |
planeAverages(int dim,
int dataDim)
Average across all but dim and dataDim |
void |
read(java.io.InputStream is)
Read from an InputStream |
boolean |
read(java.lang.String filename)
Read from a file |
Tensor |
reconstruct(BigMat[] U)
Tensor reconstruction method |
double[] |
reconstruct(double[][] weights,
int dataDim)
Reconstruct from a set of edge weights |
double[] |
reconstruct(double[][] weights,
int i,
BigMat U)
reconstruct first multiplying by transpose U along i |
double[] |
reconstruct(double[][] weights,
int dataDim,
double s)
Reconstructs and multiplies each element by by s |
BigMat |
reconstructForALS(double[][] weights,
int dataDim,
int studyDim)
Reconstruction for alternating least squares method |
double[] |
reconvertParams(double[][] params,
int dataDim)
Converts a set of edge parameters into a single vector |
Tensor |
rowAverages(int dim,
int dataDim,
boolean subtract)
Calculates the averages along rows indexed by dim |
BigMat |
rowPCAMatrix(int dim,
int dataDim,
double[] w)
Calculates the PCA rotation matrix along one row |
void |
set(int[] in,
double value)
Set an element of the Tensor |
int |
size(int d)
Get the length of dimension d |
Tensor |
subtractAverage(int row)
Subtract the row average from each element in that row |
void |
subtractAverageInPlace(int row)
Subtract the average from each row without creating a new Tensor to hold the result |
static void |
testAverage(java.lang.String[] args)
Test the ALS method for finding parameters |
static void |
testAverageTransforms(java.lang.String[] args)
Another test method |
static void |
testFitting(java.lang.String[] args)
Test fitting |
static void |
testHOSVD(java.lang.String[] args)
Test for high order SVD (HOSVD) |
static void |
testLinear(java.lang.String[] args)
Test the linear approximate method |
BigMat |
unfold(int i)
unfold method, unfolds along a dimension i |
double[] |
vectorise()
Vectorise the Tensor |
double[] |
vectoriseAppended()
Vectorise |
boolean |
whiten(int i,
double[] mean,
double[] sd)
Whiten the data (i.e. |
void |
write(java.io.PrintStream ps)
Write to a PrintStream |
boolean |
write(java.lang.String filename)
Write a Tensor model to file |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Tensor()
public Tensor(int[] dims)
dims
- length of dimensionspublic Tensor(int[] dims, double[] data)
dims
- the length of each dimensiondata
- the dataMethod Detail |
---|
protected int index(int[] in)
in
- - array containing the n-mode coordinates
public double get(int[] in)
in
- the array of coordinates
public void set(int[] in, double value)
in
- the positionvalue
- the valuepublic int size(int d)
d
- the index of the dimension to get
public void copy(Tensor rhs)
rhs
- public BigMat unfold(int i)
i
- the direction to unfold along
public BigMat getCovar(int i, boolean skipFirst)
i
- dimension to unfold alongskipFirst
- optionally skip the first
public double[] vectorise()
public double[] vectoriseAppended()
public static Tensor getOuterProduct(double[][] vecs)
vecs
- the array of vectors
public static Tensor getOuterProductAppend1(double[][] vecs)
vecs
- the parameter vectors (without the initial 1)
public void fold(int i, BigMat M)
i
- the axis to fold the matrix alongM
- the matrix to foldpublic Tensor multiply(int i, BigMat M) throws BigMatException
i
- the row, the vectors are extracted along this dimension and multiplied by M, the result is put into the output TensorM
- the matrix to multiply the vectors with
BigMatException
public boolean whiten(int i, double[] mean, double[] sd)
i
- the data row to usemean
- the mean vectorsd
- the standard deviation vector
public void multiplyInPlace(int i, BigMat M) throws BigMatException
i
- the direction of the vectors to multiplyM
- matrix to multiply with, must be square for the in-place version
BigMatException
public BigMat[] build(boolean rotate, double[][] weights)
rotate
- if true the PCA rotations are applied to this Tensorweights
- the PCA diagonal vectors are placed here
public BigMat[] build(boolean rotate, double[][] weights, int dataDim)
rotate
- if true rotate this Tensor with the estimated rotation matricesweights
- the weight (row Eigenvalues)dataDim
- the data dimension to leave untouched
public double getRankWeight(double[][] vecs)
vecs
- the vectors
public double[][] getBestRankTensor(int rank)
rank
- not currently used (Use method with extreme caution!)
public Tensor getRowAverage(int row)
row
- the row to averages, average along the row given
public void addRowAveragesInPlace(Tensor average, int row)
average
- the Tensor of row averagesrow
- the dimension to add the averages alongpublic Tensor subtractAverage(int row)
row
- the row to average / subtract along
public void subtractAverageInPlace(int row)
row
- the row to average alongpublic BigMat[] buildWithAverage(double[][] weights, int dataDim, double maxvar)
weights
- stores the output row weightings (row Eigenvalues)dataDim
- the data dimension to leave untouchedmaxvar
- the maximum variance to explain along each dimension
public BigMat[] buildWithAverageInPlace(double[][] weights, int dataDim, double maxvar)
weights
- stores the output row weightings (row Eigenvalues)dataDim
- the data dimension to leave untouchedmaxvar
- the maximum variance to explain along each dimension
public double[][] convertParams(double[] params, int dataDim)
params
- the linear parametersdataDim
- the data dimension
public double[] reconvertParams(double[][] params, int dataDim)
params
- the edge parametersdataDim
- the data dimension
public static Tensor getTemplateTensor(int[] dims, java.util.Vector<Template> templates)
dims
- the dimensions (make sure the vector is ordered properly)templates
- the templates to put in the tensor
public static Tensor getImageTensor(int[] dims, java.util.Vector<java.awt.Image> images)
dims
- the data dimensionsimages
- the images to Tensorise
public static double[] linearAnalyse(BigMat linearModel, BigMat average, double[] testData)
linearModel
- the linear matrixaverage
- teh average, should be Mx1, subtracted before the matrix multiplicationtestData
- the data to analyse
public BigMat getLinearAnalysisMatrix(int dataDim, BigMat average)
dataDim
- the data dimensionaverage
- the average
public BigMat getFullLinearAnalysisMatrix(int dataDim, BigMat average, boolean skipFirst)
dataDim
- the data dimensionaverage
- the averageskipFirst
- should the first element of each row be treated as 1
public double[] reconstruct(double[][] weights, int dataDim)
weights
- the weightsdataDim
- the data dimensions
public double[] reconstruct(double[][] weights, int dataDim, double s)
weights
- the parameter weightsdataDim
- the data dimensions
- the scale factor
public BigMat reconstructForALS(double[][] weights, int dataDim, int studyDim)
weights
- the parametersdataDim
- te data dimensionstudyDim
- the current fixed dimension in the ASL process
public static double[] getALSWeights(BigMat coeffs, double[] testData)
coeffs
- the matrix to usetestData
- the test data to analyse
public double[][] getALSWeights(double[] testData, double[][] params, int dataDim, int maxIts)
testData
- the test data to get parameters forparams
- the original workspacedataDim
- the data dimensionmaxIts
- teh maximum iteration to use
public double[] reconstruct(double[][] weights, int i, BigMat U)
weights
- the parameter weightsi
- the row to multiply alongU
- the matrix to multiply with
public Tensor reconstruct(BigMat[] U)
U
- the set of rotation / Eigenvector matrices
public Tensor rowAverages(int dim, int dataDim, boolean subtract)
dim
- the dimension to average alongdataDim
- the dimension containing the data vectorssubtract
- flag indicating if the row average should be subtracted from each element in the row
public BigMat rowPCAMatrix(int dim, int dataDim, double[] w)
dim
- the dimension to perform the row PCA alongdataDim
- the dimension holding the data vectorsw
- an array to store the calulated weight of each component
public void addRowAverages(Tensor rowAvs, int dim, int dataDim)
rowAvs
- the tensor of row averagesdim
- the dimension to work ondataDim
- the data dimensionpublic static BigMat createAverageAndSubtractMatrix(int width)
width
- the size of the fibres to multiply
public BigMat planeAverages(int dim, int dataDim)
dim
- the first direction to keepdataDim
- the second direction to keep
public boolean write(java.lang.String filename)
filename
- the file to write to
public void write(java.io.PrintStream ps) throws java.io.IOException
ps
- the PrintStream to write to
java.io.IOException
public boolean read(java.lang.String filename)
filename
- the file to read from
public void read(java.io.InputStream is) throws java.io.IOException
is
- the InputStream to read from
java.io.IOException
public static java.awt.Image buildAverageFromWarped(java.util.Vector<java.awt.Image> images)
images
- the images to average
public double[] getVariance(double[] mean, int dim)
mean
- space to return the mean vectordim
- the dimension
public static void adjust(double[] params, int start, int end, double amount)
params
- start
- end
- amount
- public static void adjust(double[] params, double[] mean, double[] sd)
params
- the vector to whitenmean
- the meansd
- the standard deviationpublic static void deAdjust(double[] params, double[] mean, double[] sd)
params
- the vector to re-adjustmean
- the meansd
- the standard deviationpublic static void main(java.lang.String[] args)
args
- not currently usedpublic static void testAverage(java.lang.String[] args)
args
- the test args, reads the Tensor from args[0], reads a BigMat from args[1], writes results to args[2]public static void testAverageTransforms(java.lang.String[] args)
args
- args[0] is the training image-template list, args[1] the width, args[2] the height, args[3] the mask, args[4] the test image-template listpublic static double normalisedScalarProduct(double[] v, double[] u)
v
- the first vectoru
- the second vector
public static void testHOSVD(java.lang.String[] args)
args
- args[0] is the training set, args[1] - width, args[2] - height, args[3] - mask, args[4] test setpublic static void testLinear(java.lang.String[] args)
args
- args[0] training set, args[1]-width, args[2]-height, args[3]-mask, args[4]-test setpublic static void testFitting(java.lang.String[] args)
args
- args[0] training set, args[1]-width, args[2]-height, args[3]-mask, args[4]-test setpublic static void createExampleData(java.lang.String[] args)
args
- args[0] training set, args[1]-width, args[2]-height, args[3]-maskpublic java.util.Iterator<java.lang.Double> iterator()
iterator
in interface java.lang.Iterable
public java.util.Iterator<java.lang.Double> iterator(int dim)
dim
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |