public class PaceMatrix extends Matrix
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.
Constructor and Description |
---|
PaceMatrix(double[][] A)
Construct a PACE matrix from a 2-D array.
|
PaceMatrix(double[][] A,
int m,
int n)
Construct a PACE matrix quickly without checking arguments.
|
PaceMatrix(double[] vals,
int m)
Construct a PaceMatrix from a one-dimensional packed array
|
PaceMatrix(DoubleVector v)
Construct a PaceMatrix with a single column from a DoubleVector
|
PaceMatrix(int m,
int n)
Construct an m-by-n PACE matrix of zeros.
|
PaceMatrix(int m,
int n,
double s)
Construct an m-by-n constant PACE matrix.
|
PaceMatrix(Matrix X)
Construct a PaceMatrix from a Matrix
|
Modifier and Type | Method and Description |
---|---|
void |
backward(PaceMatrix b,
IntVector pvt,
int ks,
int k0)
Backward ordering of columns in terms of response explanation.
|
PaceMatrix |
cbind(PaceMatrix b)
Returns a new matrix which binds two matrices with columns.
|
java.lang.Object |
clone()
Clone the PaceMatrix object.
|
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.
|
void |
forward(PaceMatrix b,
IntVector pvt,
int k0)
Forward ordering of columns in terms of response explanation.
|
double[] |
g1(double a,
double b)
Constructs the Givens rotation
|
void |
g2(double[] cs,
int i0,
int i1,
int j)
Performs the Givens rotation
|
DoubleVector |
getColumn(int j)
Return a DoubleVector that stores a column of the matrix
|
DoubleVector |
getColumn(int i0,
int i1,
int j)
Return a DoubleVector that stores some elements of a column of the
matrix
|
java.lang.String |
getRevision()
Returns the revision string.
|
double[] |
h1(int j,
int k)
Constructs single Householder transformation for a column
|
void |
h2(int j,
int k,
double q,
PaceMatrix b,
int l)
Performs single Householder transformation on one column of a matrix
|
boolean |
isEmpty()
Check if the matrix is empty
|
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.
|
void |
lsqr(PaceMatrix b,
IntVector pvt,
int k0)
QR transformation for a least squares problem
A x = b implicitly both A and b are transformed. |
void |
lsqrSelection(PaceMatrix b,
IntVector pvt,
int k0)
QR transformation for a least squares problem
A x = b implicitly both A and b are transformed. |
static void |
main(java.lang.String[] args)
for testing only
|
double |
maxAbs()
Returns the maximum absolute value of all elements
|
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].
|
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].
|
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.
|
DoubleVector |
nnls(PaceMatrix b,
IntVector pvt)
Solves the nonnegative linear squares problem.
|
DoubleVector |
nnlse(PaceMatrix b,
PaceMatrix c,
PaceMatrix d,
IntVector pvt)
Solves the nonnegative least squares problem with equality
constraint.
|
DoubleVector |
nnlse1(PaceMatrix b,
IntVector pvt)
Solves the nonnegative least squares problem with equality
constraint.
|
void |
positiveDiagonal(PaceMatrix Y,
IntVector pvt)
Sets all diagonal elements to be positive (or nonnegative) without
changing the least squares solution
|
static Matrix |
randomNormal(int m,
int n)
Generate matrix with standard-normally distributed random elements
|
PaceMatrix |
rbind(PaceMatrix b)
Returns a new matrix which binds two matrices together with rows.
|
void |
rsolve(PaceMatrix b,
IntVector pvt,
int kp)
Solves upper-triangular equation
R x = b On output, the solution is stored in b |
void |
setColumnDimension(int columnDimension)
Set the column dimenion of the matrix
|
void |
setMatrix(double[] v,
boolean columnFirst)
Set the whole matrix from a 1-D array
|
void |
setMatrix(int i0,
int i1,
int j,
DoubleVector v)
Set the submatrix A[i0:i1][j] with the values stored in a
DoubleVector
|
void |
setMatrix(int i0,
int i1,
int j0,
int j1,
double s)
Set the submatrix A[i0:i1][j0:j1] with a same value
|
void |
setPlus(int i,
int j,
double s)
Add a value to an element and reset the element
|
void |
setRowDimension(int rowDimension)
Set the row dimenion of the matrix
|
void |
setTimes(int i,
int j,
double s)
Multiply a value with an element and reset the element
|
void |
steplsqr(PaceMatrix b,
IntVector pvt,
int ks,
int j,
boolean adjoin)
Stepwise least squares QR-decomposition of the problem
A x = b
|
double[] |
sum2(boolean col)
Squared sum of columns or rows of a matrix
|
double |
sum2(int j,
int i0,
int i1,
boolean col)
Squared sum of a column or row in a matrix
|
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.
|
java.lang.String |
toString()
Converts matrix to string
|
java.lang.String |
toString(int digits,
boolean trailing)
Converts matrix to string
|
arrayLeftDivide, arrayLeftDivideEquals, arrayRightDivide, arrayRightDivideEquals, arrayTimes, arrayTimesEquals, chol, cond, constructWithCopy, copy, det, eig, get, getArray, getArrayCopy, getColumnDimension, getColumnPackedCopy, getMatrix, getMatrix, getMatrix, getMatrix, getRowDimension, getRowPackedCopy, identity, inverse, isSquare, isSymmetric, lu, minus, minusEquals, norm1, norm2, normF, normInf, parseMatlab, plus, plusEquals, print, print, print, print, qr, random, rank, read, regression, regression, set, setMatrix, setMatrix, setMatrix, setMatrix, solve, solveTranspose, sqrt, svd, times, times, timesEquals, toMatlab, trace, transpose, uminus, write
public PaceMatrix(int m, int n)
m
- Number of rows.n
- Number of colums.public PaceMatrix(int m, int n, double s)
m
- Number of rows.n
- Number of colums.s
- Fill the matrix with this scalar value.public PaceMatrix(double[][] A)
A
- Two-dimensional array of doubles.java.lang.IllegalArgumentException
- All rows must have the same lengthpublic PaceMatrix(double[][] A, int m, int n)
A
- Two-dimensional array of doubles.m
- Number of rows.n
- Number of colums.public PaceMatrix(double[] vals, int m)
vals
- One-dimensional array of doubles, packed by columns (ala Fortran).m
- Number of rows.java.lang.IllegalArgumentException
- Array length must be a multiple of m.public PaceMatrix(DoubleVector v)
v
- DoubleVectorpublic PaceMatrix(Matrix X)
X
- Matrixpublic void setRowDimension(int rowDimension)
rowDimension
- the row dimensionpublic void setColumnDimension(int columnDimension)
columnDimension
- the column dimensionpublic java.lang.Object clone()
public void setPlus(int i, int j, double s)
i
- the row number of the elementj
- the column number of the elements
- the double value to be added withpublic void setTimes(int i, int j, double s)
i
- the row number of the elementj
- the column number of the elements
- the double value to be multiplied withpublic void setMatrix(int i0, int i1, int j0, int j1, double s)
i0
- the index of the first element of the columni1
- the index of the last element of the columnj0
- the index of the first columnj1
- the index of the last columns
- the value to be set topublic void setMatrix(int i0, int i1, int j, DoubleVector v)
i0
- the index of the first element of the columni1
- the index of the last element of the columnj
- the index of the columnv
- the vector that stores the valuespublic void setMatrix(double[] v, boolean columnFirst)
v
- 1-D array of doublescolumnFirst
- Whether to fill the column first or the row.java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic double maxAbs()
public double maxAbs(int i0, int i1, int j)
i0
- the index of the first element of the columni1
- the index of the last element of the columnj
- the index of the columnpublic double minAbs(int i0, int i1, int column)
i0
- the index of the first element of the columni1
- the index of the last element of the columncolumn
- the index of the columnpublic boolean isEmpty()
public DoubleVector getColumn(int j)
j
- the index of the columnpublic DoubleVector getColumn(int i0, int i1, int j)
i0
- the index of the first element of the columni1
- the index of the last element of the columnj
- the index of the columnpublic double times(int i, int j0, int j1, PaceMatrix B, int l)
i
- the index of the row in the first matrixj0
- the index of the first column in the first matrixj1
- the index of the last column in the first matrixB
- the second matrixl
- the index of the column in the second matrixpublic java.lang.String toString()
public java.lang.String toString(int digits, boolean trailing)
digits
- number of digits after decimal pointtrailing
- true if trailing zeros are paddedpublic double sum2(int j, int i0, int i1, boolean col)
j
- the index of the column or rowi0
- the index of the first elementi1
- the index of the last elementcol
- if true, sum over a column; otherwise, over a rowpublic double[] sum2(boolean col)
col
- if true, sum over columns; otherwise, over rowspublic double[] h1(int j, int k)
j
- the index of the columnk
- the index of the rowpublic void h2(int j, int k, double q, PaceMatrix b, int l)
j
- the index of the columnk
- the index of the rowq
- q = - u'u/2; must be negativeb
- the matrix to be transformedl
- the column of the matrix bpublic double[] g1(double a, double b)
a
- b
- public void g2(double[] cs, int i0, int i1, int j)
cs
- a array storing the cosine and sine valuesi0
- the index of the row of the first elementi1
- the index of the row of the second elementj
- the index of the columnpublic void forward(PaceMatrix b, IntVector pvt, int k0)
b
- the PaceMatrix bpvt
- the pivoting vectork0
- the first k0 columns (in pvt) of A are not to be changedpublic int mostExplainingColumn(PaceMatrix b, IntVector pvt, int ks)
b
- responsepvt
- pivoting index of Aks
- columns pvt[ks:] of A are to be testedpublic void backward(PaceMatrix b, IntVector pvt, int ks, int k0)
b
- PaceMatrix bpvt
- pivoting vectorks
- number of QR-transformed columns; psuedo-rank of Ak0
- first k0 columns in pvt[] are not to be ordered.public int leastExplainingColumn(PaceMatrix b, IntVector pvt, int ks, int k0)
b
- responsepvt
- pivoting index of Aks
- psudo-rank of Ak0
- A[][pvt[0:(k0-1)]] are excluded from the testing.public double columnResponseExplanation(PaceMatrix b, IntVector pvt, int j, int ks)
b
- PaceMatrix bpvt
- pivoting vectorj
- the column A[pvt[j]][] is to be movedks
- the target column A[pvt[ks]][]public void lsqr(PaceMatrix b, IntVector pvt, int k0)
b
- PaceMatrix bpvt
- pivoting vectork0
- 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.public void lsqrSelection(PaceMatrix b, IntVector pvt, int k0)
b
- PaceMatrix bpvt
- pivoting vectork0
- 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.public void positiveDiagonal(PaceMatrix Y, IntVector pvt)
Y
- the responsepvt
- the pivoted column indexpublic void steplsqr(PaceMatrix b, IntVector pvt, int ks, int j, boolean adjoin)
b
- PaceMatrix bpvt
- pivoting vectorks
- number of transformed columnsj
- pvt[j], the column to adjoin or deleteadjoin
- to adjoin if true; otherwise, to deletepublic void rsolve(PaceMatrix b, IntVector pvt, int kp)
b
- the responsepvt
- the pivoting vectorkp
- the number of the first columns involvedpublic PaceMatrix rbind(PaceMatrix b)
b
- the second matrixpublic PaceMatrix cbind(PaceMatrix b)
b
- the second matrixpublic DoubleVector nnls(PaceMatrix b, IntVector pvt)
For algorithm, refer to P161, Chapter 23 of C. L. Lawson and R. J. Hanson (1974). "Solving Least Squares Problems". Prentice-Hall.
b
- the responsepvt
- vector storing pivoting column indicespublic DoubleVector nnlse(PaceMatrix b, PaceMatrix c, PaceMatrix d, IntVector pvt)
b
- the responsec
- coeficients of equality constraintsd
- constants of equality constraintspvt
- vector storing pivoting column indicespublic DoubleVector nnlse1(PaceMatrix b, IntVector pvt)
b
- the responsepvt
- vector storing pivoting column indicespublic static Matrix randomNormal(int m, int n)
m
- Number of rows.n
- Number of colums.public java.lang.String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class Matrix
public static void main(java.lang.String[] args)
args
- the commandline arguments - ignored