|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl<PermutationMatrix>
com.numericalmethod.suanshu.matrix.doubles.matrixtype.PermutationMatrix
public class PermutationMatrix
A permutation matrix is a square matrix that has exactly one entry 1 in each row and each column and 0's elsewhere.
This implementation uses a row view. We only store the column position of the 1 in each row. For examples,
| 1 0 0 |
| 0 1 0 | is
| 0 0 1 |
[1, 2, 3];
| 0 0 1 |
| 0 1 0 | is
| 1 0 0 |
[3, 2, 1]
Suppose P is a permutation matrix, A any matrix, then
P %*% A swaps the rows of A;
A %*% P swaps the columns of A;
There is no set function in this class. The matrix entries can only be modified by the various swap functions. This is to ensure that the matrix represents a consistent permutation.
| Constructor Summary | |
|---|---|
PermutationMatrix(int dim)
Construct an identity permutation matrix. |
|
PermutationMatrix(int[] data)
Construct a permutation matrix from a 1D double[] array. |
|
PermutationMatrix(PermutationMatrix P)
Copy constructor. |
|
| Method Summary | |
|---|---|
Matrix |
add(Matrix that)
this + that |
PermutationMatrix |
deepCopy()
The implementation can return an instance created from this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
boolean |
equals(java.lang.Object obj)
Compares this matrix to another matrix. |
double |
get(int row,
int col)
Get the matrix entry at [row, col]. |
Vector |
getColumn(int col)
Get a specified column as a vector. |
Vector |
getRow(int row)
Get a specified row as a vector. |
int |
hashCode()
|
Matrix |
minus(Matrix that)
this - that |
void |
moveColumn2End(int col)
This swaps a column of a permutation matrix with the last column. |
void |
moveRow2End(int row)
This swaps a row of a permutation matrix with the last row. |
Matrix |
multiply(Matrix A)
Left multiplication by P. |
Vector |
multiply(Vector v)
Left multiplication by P. |
PermutationMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix. |
Matrix |
rightMultiply(Matrix A)
Right multiplication by P. |
Matrix |
scaled(double scalar)
scalar * this |
void |
set(int row,
int col,
double value)
Deprecated. use the swap functions instead |
double |
sign()
Get the sign of this Permutation matrix which is essentially the determinant. |
void |
swapColumn(int col1,
int col2)
This swaps two columns of a permutation matrix. |
void |
swapRow(int row1,
int row2)
This swaps two rows of a permutation matrix. |
PermutationMatrix |
t()
The transpose of a permutation matric is the same as its inverse. |
Matrix |
ZERO()
The additive element 0 in the group, such that for all elements a in the group,
the equation 0 + a = a + 0 = a holds. |
| Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl |
|---|
call, getSample, nCols, nRows, opposite, setColumn, setColumn, setRow, setRow, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PermutationMatrix(int dim)
dim - dimension of the permutation matrixpublic PermutationMatrix(int[] data)
data - the 1D double[] array indicating the column position of the 1 on each row
java.lang.IllegalArgumentException - if data is not a permutation matrixpublic PermutationMatrix(PermutationMatrix P)
P - a permutation matrix to be copied| Method Detail |
|---|
public PermutationMatrix deepCopy()
Matrixthis by the copy
constructor of the class, or just this if the instance itself is
immutable.
Override the return type.
Matrix instancepublic double sign()
public void swapRow(int row1,
int row2)
row1 - row 1/index 1row2 - row 2/index 2
public void swapColumn(int col1,
int col2)
col1 - column 1/index 1col2 - column 2/index 2public void moveRow2End(int row)
row - the row to be swapped with the last rowpublic void moveColumn2End(int col)
col - the column to be swapped with the last column
public double get(int row,
int col)
throws MatrixAccessException
MatrixAccessor[row, col].
row - the row indexcol - the column index
A[row, col]
MatrixAccessException - if row or col is out of range
public Vector getRow(int row)
throws MatrixAccessException
MatrixAccessor
getRow in interface MatrixAccessorgetRow in class MatrixMathImpl<PermutationMatrix>row - the row index
A[row, ]
MatrixAccessException - when row < 1, or when row > number of rows
public Vector getColumn(int col)
throws MatrixAccessException
MatrixAccessor
getColumn in interface MatrixAccessorgetColumn in class MatrixMathImpl<PermutationMatrix>col - the column index
A[, col]
MatrixAccessException - when col < 1, or when col > number of columnspublic Matrix rightMultiply(Matrix A)
P.
A %*% P is the same as swapping columns in A according to P.
A - a matrix to be right multiplied
A %*% Ppublic Vector multiply(Vector v)
P.
P %*% vector is the same as swapping the vector entries/rows according to P.
multiply in interface Matrixmultiply in class MatrixMathImpl<PermutationMatrix>v - column vector whose rows are to be swapped
public Matrix multiply(Matrix A)
P.
P %*% A is the same as swapping rows in A according to P.
multiply in interface Monoid<Matrix>multiply in interface MatrixRingmultiply in class MatrixMathImpl<PermutationMatrix>A - a matrix to be left multiplied
P %*% Apublic Matrix add(Matrix that)
MatrixRingthis + that
add in interface AbelianGroup<Matrix>add in interface MatrixRingadd in class MatrixMathImpl<PermutationMatrix>that - another matrix
this and thatpublic Matrix minus(Matrix that)
MatrixRingthis - that
minus in interface AbelianGroup<Matrix>minus in interface MatrixRingminus in class MatrixMathImpl<PermutationMatrix>that - another matrix
this and thatpublic Matrix scaled(double scalar)
Matrixscalar * this
scaled in interface Matrixscaled in class MatrixMathImpl<PermutationMatrix>scalar - a double
scalar * thispublic PermutationMatrix t()
P.multiply(P.t()) == P.t().multiply(P) == P.toDense().ONE()
t in interface MatrixRingt in class MatrixMathImpl<PermutationMatrix>public PermutationMatrix ONE()
MatrixRingFor a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).
public Matrix ZERO()
AbelianGroupa in the group,
the equation 0 + a = a + 0 = a holds.
0public boolean equals(java.lang.Object obj)
This implementation is optimized if both matrices are subclass of PermutationMatrix.
equals in class java.lang.Objectobj - a matrix (of any implementation)
true iff all entries are equals, entry by entrypublic int hashCode()
hashCode in class java.lang.Object
@Deprecated
public void set(int row,
int col,
double value)
throws MatrixAccessException
swapRow(int, int),
swapColumn(int, int),
moveRow2End(int),
moveColumn2End(int),
row - the row indexcol - the column indexvalue - the value to set A[row, col] to
java.lang.UnsupportedOperationException - when called
MatrixAccessException - if row or col is out of range
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||