| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectFacemorph.BigMat
public class BigMat
Arbitrary size matrix utility class particularly useful are the singular value decomposition (SVD) and jacobi routines SVD is used to do least-squares matrix inversion and eigen analysis jacobi is used for eigen analysis
| Constructor Summary | |
|---|---|
BigMat()
A (possibly large) rectangular matrix  | 
|
BigMat(BigMat P)
 | 
|
BigMat(BigMat P,
       int x,
       int y)
 | 
|
BigMat(double[][] d)
Constuct a BigMat using an array of doubles (row major)  | 
|
BigMat(int x,
       int y)
Construct a BigMat with the size specified  | 
|
| Method Summary | |
|---|---|
 void | 
add(BigMat mat)
Adds mat to this  | 
 void | 
add(int x,
    int y,
    double val)
Set the matrix value (matrix[x][y]=val)  | 
 BigMat | 
copy()
Create a copy of this matrix  | 
 void | 
copy(BigMat mat)
Copy the matrix given into this  | 
 void | 
display(java.lang.String name)
Write this matrix out to the console for debugging  | 
static double | 
dotProduct(double[] left,
           double[] right)
Return the inner (dot) product for two vectors  | 
 boolean | 
equals(BigMat mat)
Checks if the two matrices are identical  | 
 boolean | 
equals(BigMat mat,
       double delta)
Checks if the two matrices are the same to within a given tollerance  | 
 double | 
get(int x,
    int y)
Retrieve the value of the matrix  | 
 double[] | 
getColumn(int colIndex)
 | 
 double[] | 
getColumnCopy(int colIndex)
Returns copy of a particular column  | 
 int | 
getHeight()
Get the height  | 
 double[] | 
getRowCopy(int rowIndex)
Returns copy of a particular row  | 
 int | 
getWidth()
Get the width  | 
 BigMat | 
invertSVD(double threshold)
find the inverse (possibly in the least squares sense) using SVD  | 
 boolean | 
jacobi(double[] d,
       BigMat v,
       int[] nrot)
Jacobi computes all eigenvalues and eigenvectors of a real symmetric matrix The input matrix elements above the diagonal are destroyed.  | 
 double | 
magnitude()
Returns the magnitude of this matrix, there are probably more efficient ways of doing this  | 
static void | 
main(java.lang.String[] args)
Main method just used for testing  | 
 BigMat | 
multiply(BigMat m)
Multiply this matrix by another matrix  | 
 void | 
multiply(double x)
Multiply this BigMat by a scalar  | 
 double[] | 
multiply(double[] x)
Multiply a vector by this matrix  | 
 BigMat | 
multiplyOtherTranspose(BigMat m)
Multiply the this matrix by the transpose of another matrix  | 
 BigMat | 
multiplySelfTranspose(boolean transpose,
                      boolean skipFirst)
Multiply this matrix by the transpose of itself  | 
 BigMat | 
multiplyTranspose(BigMat m)
Multiply this matrix by another matrix  | 
 double[] | 
multiplyTranspose(double[] x)
Multiply the vector x by the transpos of this matrix  | 
 void | 
normaliseColumns()
Normalise the columns of this matrix  | 
 void | 
normaliseRows()
Normalise the rows of this matrix  | 
 void | 
put(int x,
    int y,
    double val)
Set the matrix value (matrix[x][y]=val)  | 
 boolean | 
qrdcmp(BigMat Q,
       BigMat R)
Decomposes this square matrix into an orthonormal matrix Q and an upper triangular matrix R such that this = R.multiply(Q)  | 
 boolean | 
qrdcmp(BigMat a,
       double[] c,
       double[] d)
From numerical recipies in C ch2.10 Constructs the QR decomposition of this matrix returning the result in a[1..n][1..n].  | 
 void | 
qrsolv(double[] c,
       double[] d,
       double[] b,
       double[] x)
Solves the set of n linear equations A.x=b .  | 
 boolean | 
read(java.io.DataInputStream in)
Read this Template from the DataInputStream provided  | 
 boolean | 
read(java.io.StreamTokenizer st)
Reads the matrix from the StreamTokenizer  | 
 boolean | 
read(java.lang.String file)
Reads this BigMat from the file given  | 
 void | 
readBinary(java.io.DataInputStream in)
Reads a BigMat from a binary file  | 
 void | 
readBinary(java.lang.String filename)
Reads this BigMat in from a binary file format  | 
 BigMat | 
reconstructQR(double[] c,
              double[] d)
Construct the Q and R matrices explicitly, using the output from qrdcmp R.multiply(Q) will give the original input matrix  | 
static BigMat | 
removeNaNRecords(BigMat in)
Removes any rows from the matrix that have NaNs of INF etc.  | 
 void | 
rsolv(double[] d,
      double[] b,
      double[] x)
solves the set of n linear equations R.x = b, where is R an upper triangular matrix stored in (a) this BigMat and b.  | 
 void | 
setColumn(int col,
          double[] vec)
 | 
 void | 
setRow(int row,
       double[] vec)
 | 
 void | 
setSize(int x,
        int y)
Set the size of this matrix  | 
 double | 
SIGN(double a,
     double b)
returns sign(b)*abs(a)  | 
 void | 
sort(double[] d)
sorting routine for jacobi method  | 
 BigMat | 
subMat(int[] rowIndex,
       int[] colIndex)
Return a sub matrix containing only those columns points to by the indices.  | 
 BigMat | 
subMat(int x,
       int y)
Returns a matrix with row x and column y removed  | 
 BigMat | 
subMat(int xstart,
       int xend,
       int ystart,
       int yend)
Retrieve a sub-part of this matrix  | 
 BigMat | 
subMatCols(int[] colIndex)
Return a sub matrix containing only those columns pointed to by the indices.  | 
 BigMat | 
subMatRows(int[] rowIndex)
Return a sub matrix containing only those rows pointed to by the indices.  | 
 void | 
subtract(BigMat mat)
Subtracts mat to this  | 
 double | 
sumSquares()
 | 
 BigMat | 
svbksb(double[] w,
       BigMat V,
       BigMat A,
       double threshold)
SVD back substitution routine  | 
 void | 
svbksb(double[] w,
       BigMat V,
       double[] b,
       double[] x,
       double threshold)
Back substitution routine for SVD.  | 
 BigMat | 
svbksbt(double[] w,
        BigMat V,
        BigMat A,
        double threshold)
SVD back substitution routine (transposed)  | 
 void | 
svbksbt(double[] w,
        BigMat V,
        double[] b,
        double[] x,
        double threshold)
Back substitution routine for SVD.  | 
 boolean | 
svdcmp(BigMat v,
       double[] w)
Performs Singular Value Decomposition A = UwVt U replace A on output (this goes from being A to being U) v and w are filled in returns true if successful, false otherwise.  | 
 boolean | 
svdcmpt(BigMat v,
        double[] w)
Performs Singular Value Decomposition A = UwVt U replace A on output (this goes from being A to being U) v and w are filled in returns true if successful, false otherwise.  | 
 BigMat | 
transposeCopy()
Create a transposed copy of this matrix  | 
 boolean | 
upperTriangularBacksub(double[] X,
                       double[] T)
Solves AT=X for T where A = this and T and X are column vectors A must be upper triangular  | 
 BigMat | 
upperTriangularInverseMultiply(BigMat M)
Calculates A^(-1)M where A = this is upper triangular, by using repeated backsubstitutions.  | 
 double[] | 
vectorise()
Scan this matrix into a 1D vector  | 
 boolean | 
write(java.io.PrintStream ps)
Write this matrix out a file  | 
 boolean | 
write(java.lang.String filename)
Write this matrix out a file  | 
 void | 
writeBinary(java.io.DataOutputStream out)
Reads a BigMat from a binary file  | 
 void | 
writeBinary(java.lang.String filename)
Writes this BigMat out in a binary format  | 
| Methods inherited from class java.lang.Object | 
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public BigMat()
public BigMat(int x,
              int y)
x - The width of the matrixy - The height of the matrixpublic BigMat(double[][] d)
d - array of datapublic BigMat(BigMat P)
public BigMat(BigMat P,
              int x,
              int y)
| Method Detail | 
|---|
public void setSize(int x,
                    int y)
             throws BigMatException
x - The width of the matrixy - The height of the matrix
BigMatException - Thrown if width or height are negativepublic int getWidth()
public int getHeight()
public double[] vectorise()
public void normaliseColumns()
public void normaliseRows()
public void display(java.lang.String name)
name - The name to display above the matrix on the output.public boolean write(java.lang.String filename)
filename - The name of the file to write to
public boolean write(java.io.PrintStream ps)
ps - The PrintStream to write to
public boolean read(java.lang.String file)
file - The name of the file to read
public boolean read(java.io.DataInputStream in)
in - The DataInputStream to read from
public boolean read(java.io.StreamTokenizer st)
st - The StreamTokenizer to read from
public void readBinary(java.io.DataInputStream in)
in - The DataInputStream to read frompublic void writeBinary(java.io.DataOutputStream out)
out - The DataOutputStream to write topublic void writeBinary(java.lang.String filename)
filename - The name of the file to write topublic void readBinary(java.lang.String filename)
filename - The file to read from
public void put(int x,
                int y,
                double val)
x - The row to updatey - The column to updateval - The updated value
public void add(int x,
                int y,
                double val)
x - The row to updatey - The column to updateval - The updated value
public double get(int x,
                  int y)
x - The row to gety - The column to get
public double[] multiply(double[] x)
                  throws BigMatException
x - The 1D vector to multiply
BigMatException - Thrown if the size of the vector and matrix don't match
public BigMat multiply(BigMat m)
                throws BigMatException
m - he matrix to multiply
BigMatException - thrown if wrong sized matrices used
public BigMat multiplyTranspose(BigMat m)
                         throws BigMatException
m - he matrix to multiply
BigMatException - thrown if wrong sized matrices used
public BigMat multiplyOtherTranspose(BigMat m)
                              throws BigMatException
m - he matrix to multiply
BigMatException - thrown if wrong sized matrices usedpublic void multiply(double x)
x - the scalar to multiply this bypublic double[] multiplyTranspose(double[] x)
x - the vector to multiply
public BigMat copy()
public void copy(BigMat mat)
mat - The matrix to copy frompublic BigMat transposeCopy()
public BigMat multiplySelfTranspose(boolean transpose,
                                    boolean skipFirst)
transpose - flag to indicate that MtM should be calculated rather than MMt (or is it the other way around?)skipFirst - flag to indicate if the first row should be skipped
public BigMat subMat(int xstart,
                     int xend,
                     int ystart,
                     int yend)
xstart - The starting x coordinatexend - The ending x coordinateystart - The starting y coordinateyend - The ending y coordinate
public BigMat subMat(int x,
                     int y)
x - row to removey - column to remove
public double magnitude()
public boolean svdcmpt(BigMat v,
                       double[] w)
v - Storage space for the output matrix Vw - 1D array that stores the diagonal of the W matrix (hoding any singular values)
public BigMat svbksbt(double[] w,
                      BigMat V,
                      BigMat A,
                      double threshold)
               throws BigMatException
w - vector of (possibly) singluar valuesV - Orthogonal matrix VA - The matrix to multiply by the invesrse of the original decomposed matrixthreshold - Threshold below which values are treated as singluar
BigMatException - Thrown if wrong sized matrices or vectors are used
public void svbksbt(double[] w,
                    BigMat V,
                    double[] b,
                    double[] x,
                    double threshold)
w - The diagonal matrix of possibly singular values, calculated by SVDV - The orthogonal matrix V calculated by SVDb - The known vector of values (the equations RHS).x - The unknown vector of values tosolve forthreshold - The largest value that will be treated as singular.
public boolean svdcmp(BigMat v,
                      double[] w)
v - Storage space for the output matrix Vw - 1D array that stores the diagonal of the W matrix (hoding any singular values)
public BigMat svbksb(double[] w,
                     BigMat V,
                     BigMat A,
                     double threshold)
w - vector of (possibly) singluar valuesV - Orthogonal matrix VA - The matrix to multiply by the invesrse of the original decomposed matrixthreshold - Threshold below which values are treated as singluar
public BigMat invertSVD(double threshold)
threshold - The threshold below which values are treated as singular
public void svbksb(double[] w,
                   BigMat V,
                   double[] b,
                   double[] x,
                   double threshold)
w - The diagonal matrix of possibly singular values, calculated by SVDV - The orthogonal matrix V calculated by SVDb - The known vector of values (the equations RHS).x - The unknown vector of values tosolve forthreshold - The largest value that will be treated as singular.
public boolean jacobi(double[] d,
                      BigMat v,
                      int[] nrot)
d - Output space for the Eigenvalues of this matrixv - Output space for the Eigenvectors of this matrixnrot - A int array (of size 1) used to return the number of rotations performed
public void sort(double[] d)
d - The vector to sort
public double SIGN(double a,
                   double b)
a - Gives the valueb - Gives the sign
public boolean qrdcmp(BigMat a,
                      double[] c,
                      double[] d)
a - The above diagonal elements of R and the non-zero values of the vectors u are returned herec - The array of weights 0.5*(u.u)d - The diagonal of the matrix R
public boolean qrdcmp(BigMat Q,
                      BigMat R)
Q - The orthonormal matrix Q is returned hereR - The upper diagonal matrix is returned here
public boolean upperTriangularBacksub(double[] X,
                                      double[] T)
X - The input vector XT - the output vector T
public BigMat upperTriangularInverseMultiply(BigMat M)
M - The matrix to multiply by the inverse of this
public BigMat reconstructQR(double[] c,
                            double[] d)
c - The weights 0.5*u.u as returned from qrdcmpd - The diagonal of the matrix R as returned from qrdcmp
public void qrsolv(double[] c,
                   double[] d,
                   double[] b,
                   double[] x)
c - The weights 0.5*u.u as output from qrdcmpd - The diagonal of the matrix R as output from qrdcmpb - the rhs of the equation to solvex - The result of solving the linear system is returned in x
public void rsolv(double[] d,
                  double[] b,
                  double[] x)
d - The diagonal of the upper diagonal matrix Rb - The rhs of the linear system to solvex - The result of solving the linear systemis returned here.public static void main(java.lang.String[] args)
args - Some arguments...
public void add(BigMat mat)
         throws BigMatException
mat - The matrix to add to this
BigMatException - thrown if matrices are different sizes
public void subtract(BigMat mat)
              throws BigMatException
mat - The matrix subtract add to this
BigMatException - thrown if matrices are different sizespublic boolean equals(BigMat mat)
mat - The matrix to compare with this
public boolean equals(BigMat mat,
                      double delta)
mat - The matrix to compare todelta - The tolerance within which they matrices are considered to match
public BigMat subMatRows(int[] rowIndex)
rowIndex - 
public BigMat subMatCols(int[] colIndex)
colIndex - 
public BigMat subMat(int[] rowIndex,
                     int[] colIndex)
rowIndex - indices to the row numberscolIndex - indices to the column number
public double[] getColumn(int colIndex)
public double[] getColumnCopy(int colIndex)
colIndex - the index for the column to return
public double[] getRowCopy(int rowIndex)
rowIndex - the index for the row to return
public void setRow(int row,
                   double[] vec)
public void setColumn(int col,
                      double[] vec)
public static BigMat removeNaNRecords(BigMat in)
in - matrix to purge
public static double dotProduct(double[] left,
                                double[] right)
left - first vectorright - second vector
BigMatException - if the two vectors are no the same lengthpublic double sumSquares()
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||