mpv2
Class PermutationMatrix

java.lang.Object
  extended by mpv2.AllMatrices
      extended by mpv2.PermutationMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class PermutationMatrix
extends AllMatrices
implements java.lang.Cloneable, java.io.Serializable

This is a permutation matrix class made by implementing AllMatrices.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class mpv2.AllMatrices
K, N
 
Constructor Summary
PermutationMatrix(double[] ord)
          Construct an n-by-n permutation matrix which will make the given array when the matrix is applied to the sorted sequence, ord = A*ascending(ord).
PermutationMatrix(int n)
          Construct an n-by-n permutation matrix with ones on the diagonal, i.e. identity matrix.
PermutationMatrix(int[] p)
          Construct an N-by-N permutation matrix from a vector p, A(n,k)==1 <=> p[n]==k.
 
Method Summary
 java.lang.Object clone()
          Clone the Matrix object.
 double cond()
          Matrix condition (2 norm)
 PermutationMatrix copy()
          Make a deep copy of a matrix
 double det()
          Matrix determinant
 double get(int n, int k)
          Get a single element, A(n,k).
 int[] getPos()
          Access the internal array pos, we have A(n,k)==1 <=> pos[n]==k.
static PermutationMatrix identity(int n)
          Generate identity matrix
 double innerProduct(int k1, int k2)
          Returns the inner product of two matrix column vectors, which for a diagonal matrix is zero.
 double norm2()
          Two norm
 double normF()
          Frobenius norm
static PermutationMatrix perfectShuffle(int n, int s)
          Generate perfect shuffle (stride) permutation matrix.
static PermutationMatrix random(int n)
          Generate randon permutation matrix
 int rank()
          Matrix rank
static PermutationMatrix reverse(int n)
          Generate reverse matrix
 void set(int n, int k, double s)
          Set a single element, A(n,k)=s, this is not allowed som method just return.
 void times(double[] y, double[] x)
          Multiplies the matrix by an array, x = A*y.
 void transposeTimes(double[] x, double[] y)
          Multiplies the transposed matrix by an array, y = A'*x.
 
Methods inherited from class mpv2.AllMatrices
addColumn, chol, columnNorm0, columnNorm1, columnNorm2, columnNormInf, eig, eqConstant, eqCopy, eqCopy, eqCopy, eqCopy, eqCopy, eqDifference, eqEProduct, eqEQuotient, eqIdentity, eqInverse, eqIProduct, eqNegate, eqOnes, eqPermuteColumns, eqPermuteRows, eqProduct, eqProduct, eqRandom, eqScaleColumns, eqScaleRows, eqSum, eqTProduct, eqTranspose, eqZeros, getAll, getAll, getColumn, getColumn, getColumnDimension, getK, getN, getRow, getRow, getRowDimension, getSubMatrix, getSubMatrix, getSubMatrix, getSubMatrix, getValue, lu, lup, norm1, normInf, pluseqOuterProduct, print, print, print, print, qr, setAll, setColumn, setRow, setValue, sumAll, svd, times, times, times, trace, transposeTimes, transposeTimes, transposeTimes
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PermutationMatrix

public PermutationMatrix(int n)
Construct an n-by-n permutation matrix with ones on the diagonal, i.e. identity matrix.

Parameters:
n - Number of rows and columns

PermutationMatrix

public PermutationMatrix(int[] p)
Construct an N-by-N permutation matrix from a vector p, A(n,k)==1 <=> p[n]==k. p must be a permutation of the integers from 0 to (N-1).

Parameters:
p - the vector that gives p.
Throws:
java.lang.IllegalArgumentException

PermutationMatrix

public PermutationMatrix(double[] ord)
Construct an n-by-n permutation matrix which will make the given array when the matrix is applied to the sorted sequence, ord = A*ascending(ord). Note that A'*ord will give an ordered sequence, i.e. ascending(ord).

Parameters:
ord - the sequence that the permutation matrix will put the ordered sequence into
Method Detail

random

public static PermutationMatrix random(int n)
Generate randon permutation matrix

Parameters:
n - Number of rows and colums.
Returns:
An n-by-n permutation matrix

identity

public static PermutationMatrix identity(int n)
Generate identity matrix

Parameters:
n - Number of rows and colums.
Returns:
An n-by-n identity matrix

reverse

public static PermutationMatrix reverse(int n)
Generate reverse matrix

Parameters:
n - Number of rows and colums.
Returns:
An n-by-n reverse matrix

perfectShuffle

public static PermutationMatrix perfectShuffle(int n,
                                               int s)
Generate perfect shuffle (stride) permutation matrix. This permutation always start with the first element, i.e. P(0,0)=1. The next element is found by going s positions forward (mod n), and if that element is already used go forward until next unused ek\lement is found.

Parameters:
n - Number of rows and colums.
s - The stride, how many elements to go forward on each, normally a factor of n.
Returns:
An n-by-n perfect shuffle (stride) permutation matrix

copy

public PermutationMatrix copy()
Make a deep copy of a matrix


clone

public java.lang.Object clone()
Clone the Matrix object.

Overrides:
clone in class java.lang.Object

get

public double get(int n,
                  int k)
Get a single element, A(n,k).

Specified by:
get in class AllMatrices
Parameters:
n - Row index.
k - Column index.
Returns:
A(n,k)
Throws:
java.lang.ArrayIndexOutOfBoundsException

getPos

public int[] getPos()
Access the internal array pos, we have A(n,k)==1 <=> pos[n]==k.

Returns:
Pointer to the one-dimensional array of column numbers.

set

public void set(int n,
                int k,
                double s)
Set a single element, A(n,k)=s, this is not allowed som method just return.

Specified by:
set in class AllMatrices
Parameters:
n - Row index.
k - Column index.
s - A(n,k).
Throws:
java.lang.ArrayIndexOutOfBoundsException

normF

public double normF()
Frobenius norm

Overrides:
normF in class AllMatrices
Returns:
sqrt of sum of squares of all elements.

det

public double det()
Matrix determinant

Overrides:
det in class AllMatrices
Returns:
determinant

rank

public int rank()
Matrix rank

Overrides:
rank in class AllMatrices
Returns:
effective numerical rank, obtained from SVD.

cond

public double cond()
Matrix condition (2 norm)

Overrides:
cond in class AllMatrices
Returns:
ratio of largest to smallest singular value.

norm2

public double norm2()
Two norm

Overrides:
norm2 in class AllMatrices
Returns:
maximum singular value.

innerProduct

public double innerProduct(int k1,
                           int k2)
Returns the inner product of two matrix column vectors, which for a diagonal matrix is zero.

Overrides:
innerProduct in class AllMatrices
Parameters:
k1 - number for the first dictionary element.
k2 - number for the second dictionary element.

times

public void times(double[] y,
                  double[] x)
Multiplies the matrix by an array, x = A*y.

Overrides:
times in class AllMatrices
Parameters:
y - the input array
x - the results as an array of length N.

transposeTimes

public void transposeTimes(double[] x,
                           double[] y)
Multiplies the transposed matrix by an array, y = A'*x. Note that the transposed of a permutation matrix is its inverse.

Overrides:
transposeTimes in class AllMatrices
Parameters:
x - the input array
y - the results as an array of length K.