public class PermutationMatrix extends Object implements Matrix
Constructor and Description |
---|
PermutationMatrix(int dim)
Construct an identity permutation matrix.
|
PermutationMatrix(int[] data)
Construct a permutation matrix from an 1D
double[] . |
PermutationMatrix(PermutationMatrix P)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
Matrix |
add(Matrix that)
this + that
|
PermutationMatrix |
deepCopy()
The implementation returns an instance created from
this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
boolean |
equals(Object obj) |
double |
get(int i,
int j)
Get the matrix entry at [i,j].
|
Vector |
getColumn(int j)
Get the specified column in the matrix as a vector.
|
Vector |
getRow(int i)
Get the specified row in the matrix as a vector.
|
int |
hashCode() |
Matrix |
minus(Matrix that)
this - that
|
void |
moveColumn2End(int j)
Swaps a column of a permutation matrix with the last column.
|
void |
moveRow2End(int i)
Swaps a row of the permutation matrix with the last row.
|
Matrix |
multiply(Matrix A)
Left multiplication by P.
|
Vector |
multiply(Vector v)
Left multiplication by P.
|
int |
nCols()
Gets the number of columns.
|
int |
nRows()
Gets the number of rows.
|
PermutationMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix.
|
Matrix |
opposite()
Get the opposite of this matrix.
|
Matrix |
rightMultiply(Matrix A)
Right multiplication by P.
|
Matrix |
scaled(double scalar)
Scale this matrix, A, by a constant.
|
void |
set(int i,
int j,
double value)
Deprecated.
use the swap functions instead
|
double |
sign()
Gets the sign of the permutation matrix which is also the determinant.
|
void |
swapColumn(int j1,
int j2)
Swaps two columns of a permutation matrix.
|
void |
swapRow(int i1,
int i2)
Swaps two rows of a permutation matrix.
|
PermutationMatrix |
t()
The transpose of a permutation matric is the same as its inverse.
|
String |
toString() |
Matrix |
ZERO()
Get a zero matrix that has the same dimension as this matrix.
|
public PermutationMatrix(int dim)
dim
- the matrix dimensionpublic PermutationMatrix(int[] data)
double[]
.data
- the 1D double[]
indicating the column position of the 1 in each rowIllegalArgumentException
- if data
is not a permutation matrixpublic PermutationMatrix(PermutationMatrix P)
P
- a permutation matrixpublic PermutationMatrix deepCopy()
DeepCopyable
this
by the copy
constructor of the class, or just this
if the instance itself is
immutable.deepCopy
in interface Matrix
deepCopy
in interface DeepCopyable
public int nRows()
Table
public int nCols()
Table
public double sign()
public void swapRow(int i1, int i2)
i1
- row 1i2
- row 2public void swapColumn(int j1, int j2)
j1
- column 1j2
- column 2public void moveRow2End(int i)
i
- the row to be swapped with the last rowpublic void moveColumn2End(int j)
j
- the column to be swapped with the last columnpublic double get(int i, int j) throws MatrixAccessException
MatrixAccess
get
in interface MatrixAccess
i
- the row indexj
- the column indexMatrixAccessException
- if i or j is out of rangepublic Vector getRow(int i) throws MatrixAccessException
Matrix
getRow
in interface Matrix
i
- the row indexMatrixAccessException
- when i < 1, or when i > the number of rowspublic Vector getColumn(int j) throws MatrixAccessException
Matrix
getColumn
in interface Matrix
j
- the column indexMatrixAccessException
- when j < 1, or when j > the number of columnspublic Matrix rightMultiply(Matrix A)
A
- a matrixpublic Vector multiply(Vector v)
public Matrix multiply(Matrix A)
multiply
in interface MatrixRing
multiply
in interface Monoid<Matrix>
A
- a matrixpublic Matrix add(Matrix that)
MatrixRing
add
in interface MatrixRing
add
in interface AbelianGroup<Matrix>
that
- a matrixthis
and that
public Matrix minus(Matrix that)
MatrixRing
minus
in interface MatrixRing
minus
in interface AbelianGroup<Matrix>
that
- a matrixthis
and that
public Matrix scaled(double scalar)
Matrix
public Matrix opposite()
MatrixRing
opposite
in interface MatrixRing
opposite
in interface AbelianGroup<Matrix>
public PermutationMatrix t()
P.multiply(P.t()) == P.t().multiply(P) == P.toDense().ONE()
t
in interface MatrixRing
public PermutationMatrix ONE()
MatrixRing
ONE
in interface MatrixRing
ONE
in interface Monoid<Matrix>
public Matrix ZERO()
MatrixRing
ZERO
in interface MatrixRing
ZERO
in interface AbelianGroup<Matrix>
@Deprecated public void set(int i, int j, double value) throws MatrixAccessException
swapRow(int, int)
,
swapColumn(int, int)
,
moveRow2End(int)
,
moveColumn2End(int)
,set
in interface MatrixAccess
i
- the row indexj
- the column indexvalue
- the value to set A[i,j] toUnsupportedOperationException
- when calledMatrixAccessException
- if i or j is out of rangeCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.