All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.classifiers.functions.pace.PaceMatrix

java.lang.Object
    |
    +----weka.classifiers.functions.pace.Matrix
            |
            +----weka.classifiers.functions.pace.PaceMatrix

public class PaceMatrix
extends Matrix
Class for matrix manipulation used for pace regression.

REFERENCES

Wang, Y. (2000). "A new approach to fitting linear models in high dimensional spaces." PhD Thesis. Department of Computer Science, University of Waikato, New Zealand.

Wang, Y. and Witten, I. H. (2002). "Modeling for optimal probability prediction." Proceedings of ICML'2002. Sydney.

Version:
$Revision: 1.1 $
Author:
Yong Wang (yongwang@cs.waikato.ac.nz)

Constructor Index

 o PaceMatrix(double[][])
Construct a PACE matrix from a 2-D array.
 o PaceMatrix(double[][], int, int)
Construct a PACE matrix quickly without checking arguments.
 o PaceMatrix(double[], int)
Construct a PaceMatrix from a one-dimensional packed array
 o PaceMatrix(DoubleVector)
Construct a PaceMatrix with a single column from a DoubleVector
 o PaceMatrix(int, int)
Construct an m-by-n PACE matrix of zeros.
 o PaceMatrix(int, int, double)
Construct an m-by-n constant PACE matrix.
 o PaceMatrix(Matrix)
Construct a PaceMatrix from a Matrix

Method Index

 o backward(PaceMatrix, IntVector, int, int)
Backward ordering of columns in terms of response explanation.
 o cbind(PaceMatrix)
Returns a new matrix which binds two matrices with columns.
 o clone()
Clone the PaceMatrix object.
 o columnResponseExplanation(PaceMatrix, IntVector, int, int)
Returns the squared ks-th response value if the j-th column becomes the ks-th after orthogonal transformation.
 o forward(PaceMatrix, IntVector, int)
Forward ordering of columns in terms of response explanation.
 o g1(double, double)
Constructs the Givens rotation
 o g2(double[], int, int, int)
 
 o getColumn(int)
Return a DoubleVector that stores a column of the matrix
 o getColumn(int, int, int)
Return a DoubleVector that stores some elements of a column of the matrix
 o h1(int, int)
Constructs single Householder transformation for a column
 o h2(int, int, double, PaceMatrix, int)
Performs single Householder transformation on one column of a matrix
 o isEmpty()
Check if the matrix is empty
 o leastExplainingColumn(PaceMatrix, IntVector, int, int)
Returns the index of the column that has the smallest (squared) response, when the column is moved to become the (ks-1)-th column.
 o lsqr(PaceMatrix, IntVector, int)
QR transformation for a least squares problem A x = b
 o lsqrSelection(PaceMatrix, IntVector, int)
QR transformation for a least squares problem A x = b
 o main(String[])
 
 o maxAbs()
Returns the maximum absolute value of all elements
 o maxAbs(int, int, int)
Returns the maximum absolute value of some elements of a column, that is, the elements of A[i0:i1][j].
 o minAbs(int, int, int)
Returns the minimum absolute value of some elements of a column, that is, the elements of A[i0:i1][j].
 o mostExplainingColumn(PaceMatrix, IntVector, int)
Returns the index of the column that has the largest (squared) response, when each of columns pvt[ks:] is moved to become the ks-th column.
 o nnls(PaceMatrix, IntVector)
Solves the nonnegative linear squares problem.
 o nnlse(PaceMatrix, PaceMatrix, PaceMatrix, IntVector)
Solves the nonnegative least squares problem with equality constraint.
 o nnlse1(PaceMatrix, IntVector)
Solves the nonnegative least squares problem with equality constraint.
 o positiveDiagonal(PaceMatrix, IntVector)
Sets all diagonal elements to be positive (or nonnegative) without changing the least squares solution
 o randomNormal(int, int)
Generate matrix with standard-normally distributed random elements
 o rbind(PaceMatrix)
Returns a new matrix which binds two matrices together with rows.
 o rsolve(PaceMatrix, IntVector, int)
Solves upper-triangular equation R x = b
 o setColumnDimension(int)
Set the column dimenion of the matrix
 o setMatrix(double[], boolean)
Set the whole matrix from a 1-D array
 o setMatrix(int, int, int, DoubleVector)
Set the submatrix A[i0:i1][j] with the values stored in a DoubleVector
 o setMatrix(int, int, int, int, double)
Set the submatrix A[i0:i1][j0:j1] with a same value
 o setPlus(int, int, double)
Add a value to an element and reset the element
 o setRowDimension(int)
Set the row dimenion of the matrix
 o setTimes(int, int, double)
Multiply a value with an element and reset the element
 o steplsqr(PaceMatrix, IntVector, int, int, boolean)
Stepwise least squares QR-decomposition of the problem A x = b
 o sum2(boolean)
Squared sum of columns or rows of a matrix
 o sum2(int, int, int, boolean)
Squared sum of a column or row in a matrix
 o times(int, int, int, PaceMatrix, int)
Multiplication between a row (or part of a row) of the first matrix and a column (or part or a column) of the second matrix.
 o toString()
Converts matrix to string
 o toString(int, boolean)
Converts matrix to string

Constructor Detail

 o PaceMatrix
public PaceMatrix(int m,
                  int n)
          Construct an m-by-n PACE matrix of zeros.
Parameters:
m - Number of rows.
n - Number of colums.
 o PaceMatrix
public PaceMatrix(int m,
                  int n,
                  double s)
          Construct an m-by-n constant PACE matrix.
Parameters:
m - Number of rows.
n - Number of colums.
s - Fill the matrix with this scalar value.
 o PaceMatrix
public PaceMatrix(double A[][])
          Construct a PACE matrix from a 2-D array.
Parameters:
A - Two-dimensional array of doubles.
Throws:
java.lang.IllegalArgumentException - All rows must have the same length
 o PaceMatrix
public PaceMatrix(double A[][],
                  int m,
                  int n)
          Construct a PACE matrix quickly without checking arguments.
Parameters:
A - Two-dimensional array of doubles.
m - Number of rows.
n - Number of colums.
 o PaceMatrix
public PaceMatrix(double vals[],
                  int m)
          Construct a PaceMatrix from a one-dimensional packed array
Parameters:
vals - One-dimensional array of doubles, packed by columns (ala Fortran).
m - Number of rows.
Throws:
java.lang.IllegalArgumentException - Array length must be a multiple of m.
 o PaceMatrix
public PaceMatrix(DoubleVector v)
          Construct a PaceMatrix with a single column from a DoubleVector
Parameters:
v - DoubleVector
 o PaceMatrix
public PaceMatrix(Matrix X)
          Construct a PaceMatrix from a Matrix
Parameters:
X - Matrix

Method Detail

 o setRowDimension
public void setRowDimension(int rowDimension)
          Set the row dimenion of the matrix
Parameters:
rowDimension - the row dimension
 o setColumnDimension
public void setColumnDimension(int columnDimension)
          Set the column dimenion of the matrix
Parameters:
columnDimension - the column dimension
 o clone
public java.lang.Object clone()
          Clone the PaceMatrix object.
Overrides:
clone in class Matrix
 o setPlus
public void setPlus(int i,
                    int j,
                    double s)
          Add a value to an element and reset the element
Parameters:
i - the row number of the element
j - the column number of the element
s - the double value to be added with
 o setTimes
public void setTimes(int i,
                     int j,
                     double s)
          Multiply a value with an element and reset the element
Parameters:
i - the row number of the element
j - the column number of the element
s - the double value to be multiplied with
 o setMatrix
public void setMatrix(int i0,
                      int i1,
                      int j0,
                      int j1,
                      double s)
          Set the submatrix A[i0:i1][j0:j1] with a same value
Parameters:
i0 - the index of the first element of the column
i1 - the index of the last element of the column
j0 - the index of the first column
j1 - the index of the last column
s - the value to be set to
 o setMatrix
public void setMatrix(int i0,
                      int i1,
                      int j,
                      DoubleVector v)
          Set the submatrix A[i0:i1][j] with the values stored in a DoubleVector
Parameters:
i0 - the index of the first element of the column
i1 - the index of the last element of the column
j - the index of the column
v - the vector that stores the values
 o setMatrix
public void setMatrix(double v[],
                      boolean columnFirst)
          Set the whole matrix from a 1-D array
Parameters:
v - 1-D array of doubles
columnFirst - Whether to fill the column first or the row.
Throws:
java.lang.ArrayIndexOutOfBoundsException - Submatrix indices
 o maxAbs
public double maxAbs()
          Returns the maximum absolute value of all elements
Returns:
the maximum value
 o maxAbs
public double maxAbs(int i0,
                     int i1,
                     int j)
          Returns the maximum absolute value of some elements of a column, that is, the elements of A[i0:i1][j].
Parameters:
i0 - the index of the first element of the column
i1 - the index of the last element of the column
j - the index of the column
Returns:
the maximum value
 o minAbs
public double minAbs(int i0,
                     int i1,
                     int column)
          Returns the minimum absolute value of some elements of a column, that is, the elements of A[i0:i1][j].
Parameters:
i0 - the index of the first element of the column
i1 - the index of the last element of the column
j - the index of the column
Returns:
the minimum value
 o isEmpty
public boolean isEmpty()
          Check if the matrix is empty
Returns:
true if the matrix is empty
 o getColumn
public DoubleVector getColumn(int j)
          Return a DoubleVector that stores a column of the matrix
Parameters:
j - the index of the column
 o getColumn
public DoubleVector getColumn(int i0,
                              int i1,
                              int j)
          Return a DoubleVector that stores some elements of a column of the matrix
Parameters:
i0 - the index of the first element of the column
i1 - the index of the last element of the column
j - the index of the column
Returns:
the DoubleVector
 o times
public double times(int i,
                    int j0,
                    int j1,
                    PaceMatrix B,
                    int l)
          Multiplication between a row (or part of a row) of the first matrix and a column (or part or a column) of the second matrix.
Parameters:
i - the index of the row in the first matrix
j0 - the index of the first column in the first matrix
j1 - the index of the last column in the first matrix
B - the second matrix
l - the index of the column in the second matrix
 o toString
public java.lang.String toString()
          Converts matrix to string
Overrides:
toString in class java.lang.Object
 o toString
public java.lang.String toString(int digits,
                       boolean trailing)
          Converts matrix to string
Parameters:
digits - number of digits after decimal point
trailing - true if trailing zeros are padded
 o sum2
public double sum2(int j,
                   int i0,
                   int i1,
                   boolean col)
          Squared sum of a column or row in a matrix
Parameters:
j - the index of the column or row
i0 - the index of the first element
i1 - the index of the last element
col - if true, sum over a column; otherwise, over a row
 o sum2
public double[] sum2(boolean col)
          Squared sum of columns or rows of a matrix
Parameters:
col - if true, sum over columns; otherwise, over rows
 o h1
public double[] h1(int j,
                   int k)
          Constructs single Householder transformation for a column
Parameters:
j - the index of the column
k - the index of the row
Returns:
d and q
 o h2
public void h2(int j,
               int k,
               double q,
               PaceMatrix b,
               int l)
          Performs single Householder transformation on one column of a matrix
Parameters:
j - the index of the column
k - the index of the row
q - q = - u'u/2; must be negative
b - the matrix to be transformed
l - the column of the matrix b
 o g1
public double[] g1(double a,
                   double b)
          Constructs the Givens rotation
Parameters:
a -
b -
Returns:
a double array that stores the cosine and sine values
 o g2
public void g2(double cs[],
               int i0,
               int i1,
               int j)
 o forward
public void forward(PaceMatrix b,
                    IntVector pvt,
                    int k0)
          Forward ordering of columns in terms of response explanation. On input, matrices A and b are already QR-transformed. The indices of transformed columns are stored in the pivoting vector.
Parameters:
b - the PaceMatrix b
pvt - the pivoting vector
k0 - the first k0 columns (in pvt) of A are not to be changed
 o mostExplainingColumn
public int mostExplainingColumn(PaceMatrix b,
                                IntVector pvt,
                                int ks)
          Returns the index of the column that has the largest (squared) response, when each of columns pvt[ks:] is moved to become the ks-th column. On input, A and b are both QR-transformed.
Parameters:
b - response
pvt - pivoting index of A
ks - columns pvt[ks:] of A are to be tested
 o backward
public void backward(PaceMatrix b,
                     IntVector pvt,
                     int ks,
                     int k0)
          Backward ordering of columns in terms of response explanation. On input, matrices A and b are already QR-transformed. The indices of transformed columns are stored in the pivoting vector. A and b must have the same number of rows, being the (pseudo-)rank.
Parameters:
b - PaceMatrix b
pvt - pivoting vector
ks - number of QR-transformed columns; psuedo-rank of A
k0 - first k0 columns in pvt[] are not to be ordered.
Returns:
void
 o leastExplainingColumn
public int leastExplainingColumn(PaceMatrix b,
                                 IntVector pvt,
                                 int ks,
                                 int k0)
          Returns the index of the column that has the smallest (squared) response, when the column is moved to become the (ks-1)-th column. On input, A and b are both QR-transformed.
Parameters:
b - response
pvt - pivoting index of A
ks - psudo-rank of A
k0 - A[][pvt[0:(k0-1)]] are excluded from the testing.
 o columnResponseExplanation
public double columnResponseExplanation(PaceMatrix b,
                                        IntVector pvt,
                                        int j,
                                        int ks)
          Returns the squared ks-th response value if the j-th column becomes the ks-th after orthogonal transformation. A[][pvt[ks:j]] (or A[][pvt[j:ks]], if ks > j) and b[] are already QR-transformed on input and will remain unchanged on output. More generally, it returns the inner product of the corresponding row vector of the response PaceMatrix. (To be implemented.)
Parameters:
b - PaceMatrix b
pvt - pivoting vector
j - the column A[pvt[j]][] is to be moved
ks - the target column A[pvt[ks]][]
Returns:
the squared response value
 o lsqr
public void lsqr(PaceMatrix b,
                 IntVector pvt,
                 int k0)
          QR transformation for a least squares problem A x = b
Parameters:
b - PaceMatrix b
pvt - pivoting vector
k0 - the first k0 columns of A (indexed by pvt) are pre-chosen. (But subject to rank examination.) For example, the constant term may be reserved, in which case k0 = 1.
Returns:
void; implicitly both A and b are transformed. pvt.size() is is the psuedo-rank of A.
 o lsqrSelection
public void lsqrSelection(PaceMatrix b,
                          IntVector pvt,
                          int k0)
          QR transformation for a least squares problem A x = b
Parameters:
b - PaceMatrix b
pvt - pivoting vector
k0 - the first k0 columns of A (indexed by pvt) are pre-chosen. (But subject to rank examination.) For example, the constant term may be reserved, in which case k0 = 1.
Returns:
void; implicitly both A and b are transformed. pvt.size() is is the psuedo-rank of A.
 o positiveDiagonal
public void positiveDiagonal(PaceMatrix Y,
                             IntVector pvt)
          Sets all diagonal elements to be positive (or nonnegative) without changing the least squares solution
Parameters:
Y - the response
pvt - the pivoted column index
 o steplsqr
public void steplsqr(PaceMatrix b,
                     IntVector pvt,
                     int ks,
                     int j,
                     boolean adjoin)
          Stepwise least squares QR-decomposition of the problem A x = b
Parameters:
b - PaceMatrix b
pvt - pivoting vector
ks - number of transformed columns
j - pvt[j], the column to adjoin or delete
adjoin - to adjoin if true; otherwise, to delete
 o rsolve
public void rsolve(PaceMatrix b,
                   IntVector pvt,
                   int kp)
          Solves upper-triangular equation R x = b
Parameters:
b - the response
pvt - the pivoting vector
kp - the number of the first columns involved
Returns:
void. On output, the solution is stored in b
 o rbind
public PaceMatrix rbind(PaceMatrix b)
          Returns a new matrix which binds two matrices together with rows.
Parameters:
b - the second matrix
Returns:
the combined matrix
 o cbind
public PaceMatrix cbind(PaceMatrix b)
          Returns a new matrix which binds two matrices with columns.
Parameters:
b - the second matrix
Returns:
the combined matrix
 o nnls
public DoubleVector nnls(PaceMatrix b,
                         IntVector pvt)
          Solves the nonnegative linear squares problem. That is,

min || A x - b||, subject to x >= 0.

For algorithm, refer to P161, Chapter 23 of C. L. Lawson and R. J. Hanson (1974). "Solving Least Squares Problems". Prentice-Hall.

Parameters:
b - the response
pvt - vector storing pivoting column indices
Returns:
solution
 o nnlse
public DoubleVector nnlse(PaceMatrix b,
                          PaceMatrix c,
                          PaceMatrix d,
                          IntVector pvt)
          Solves the nonnegative least squares problem with equality constraint. That is,

min ||A x - b||, subject to x >= 0 and c x = d.

Parameters:
b - the response
c - coeficients of equality constraints
d - constants of equality constraints
pvt - vector storing pivoting column indices
 o nnlse1
public DoubleVector nnlse1(PaceMatrix b,
                           IntVector pvt)
          Solves the nonnegative least squares problem with equality constraint. That is,

min ||A x - b||, subject to x >= 0 and || x || = 1.

Parameters:
b - the response
pvt - vector storing pivoting column indices
 o randomNormal
public static Matrix randomNormal(int m,
                                  int n)
          Generate matrix with standard-normally distributed random elements
Parameters:
m - Number of rows.
n - Number of colums.
Returns:
An m-by-n matrix with random elements.
 o main
public static void main(java.lang.String args[])

All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home