mikera.matrixx.impl
Class PermutationMatrix
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<AVector>
-
- mikera.matrixx.AMatrix
-
- mikera.matrixx.impl.ARectangularMatrix
-
- mikera.matrixx.impl.ABooleanMatrix
-
- mikera.matrixx.impl.PermutationMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, INDArray, ISparse, IMatrix, IFastColumns, IFastRows
public final class PermutationMatrix extends ABooleanMatrix implements IFastRows, IFastColumns, ISparse
Class representing a square permutation matrix i.e. has single 1.0 in every row and column Mutable only for swapping rows and columns- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddToArray(double[] data, int offset)Adds all the elements of this array to a double array at the specified offset, in row-major ordervoidcopyColumnTo(int col, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double arrayvoidcopyRowTo(int row, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double arraystatic PermutationMatrixcreate(Index rowPermutations)static PermutationMatrixcreate(int... rowPermutations)static PermutationMatrixcreateIdentity(int length)static PermutationMatrixcreateRandomPermutation(int length)static PermutationMatrixcreateSwap(int i, int j, int length)doubledensity()Computes the density ratio of this sparse array (proportion of non-zero elements)doubledeterminant()Calculates the determinant of the matrix.doubleelementAbsPowSum(double p)Returns the sum of the absolute values of all the elements raised to a specified powerdoubleelementPowSum(double p)Returns the sum of all the elements raised to a specified powerdoubleelementSquaredSum()Returns the squared sum of all elements in this matrixdoubleelementSum()Returns the sum of all elements in this matrixPermutationMatrixexactClone()Creates a deep clone of an array, using the same class implementation as the original arraydoubleget(int row, int column)Returns the double value at the specified position in a 2D matrixAxisVectorgetColumn(int j)Returns a column of the matrix.AxisVectorgetRow(int i)Returns a row of the matrix.PermutationMatrixgetTranspose()Returns the transpose of this array.booleanhasOrthonormalColumns()Tests whether all columns in the matrix are orthonormal vectorsbooleanhasOrthonormalRows()Tests whether all rows in the matrix are orthonormal vectorsbooleanhasUncountable()Checks to see if any element in the matrix is NaN of Infinite.MatrixinnerProduct(AMatrix a)Computes the inner product of this matrix with another.PermutationMatrixinverse()Computes the inverse of a matrix.booleanisBoolean()Returns true if the array is boolean (contains only 0.0 or 1.0 values)booleanisDiagonal()Returns true iff this matrix is a square diagonal matrixbooleanisIdentity()Checks if this is an identity matrix (i.e.booleanisLowerTriangular()Returns true if a matrix is lower triangular.booleanisMutable()Returns true if the INDArray is mutable (at least partially)booleanisOrthogonal()Check to see if the matrix is orthogonal (default tolerance: 1e-8)booleanisOrthogonal(double tolerance)Check to see if the matrix is orthogonalbooleanisSymmetric()Returns true if a matrix is symmetricbooleanisUpperTriangular()Returns true if a matrix is upper triangular An upper triangular matrix is defined as having all elements equal to 0.0 where i > jbooleanisZero()Returns true if the matrix is the zero matrix (all components zero)longnonZeroCount()Returns the number of non-zero elements in the array.intrank()Calculate the rank of a matrix.doublerowDotProduct(int i, AVector v)Returns the dot product of a specific row with a vector.voidset(int row, int column, double value)Sets a value at a given position in a mutable 2D arrayvoidswapColumns(int i, int j)Swaps two columns of the matrix in placevoidswapRows(int i, int j)Swaps two rows of the matrix in place This is an elementary row operationdoubletrace()Computes the trace of a matrix, i.e.voidtransform(AVector source, AVector dest)Transforms a source vector into a destination vector, using matrix multiplication (inner product).voidtransform(Vector source, Vector dest)MatrixtransposeInnerProduct(Matrix s)doubleunsafeGet(int row, int column)Gets an element in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.voidunsafeSet(int row, int column, double value)Sets an element value in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.voidvalidate()Validates the internal data structure of the INDArray.static PermutationMatrixwrap(Index rowPermutations)static PermutationMatrixwrap(int[] rowPermutations)-
Methods inherited from class mikera.matrixx.impl.ABooleanMatrix
absCopy, elementMax, isFullyMutable, signumCopy, squareCopy
-
Methods inherited from class mikera.matrixx.impl.ARectangularMatrix
bandLength, checkColumn, checkRow, checkSquare, columnCount, elementCount, getElement, getShape, getShape, getShapeClone, isSameShape, isSameShape, isSameShape, isSquare, rowCount
-
Methods inherited from class mikera.matrixx.AMatrix
abs, add, add, add, add, add2, addAt, addCopy, addCopy, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addOuterProduct, addOuterProduct, addOuterProductSparse, addOuterProductSparse, addRowMultiple, addSparse, addSparse, applyOp, applyOp, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, bandIndex, bandPosition, bandStartColumn, bandStartRow, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, clamp, clone, composeWith, copy, dense, denseClone, diagonalProduct, dimensionality, divide, divide, divide, divide, divideCopy, elementIterator, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, equals, equalsArray, equalsTranspose, exp, fill, get, get, get, get, getBand, getBandWrapped, getColumnClone, getColumns, getColumnView, getElements, getLeadingDiagonal, getLongShape, getRowClone, getRows, getRowView, getSlices, getSlices, getSliceViews, getTransposeCopy, getTransposeView, hashCode, immutable, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, inputDimensions, isElementConstrained, isHermitian, isInvertible, isPositiveDefinite, isRectangularDiagonal, isView, iterator, join, log, lowerBandwidth, lowerBandwidthLimit, mul, multiply, multiply, multiply, multiply, multiplyCopy, multiplyRow, mutable, negate, outerProduct, outputDimensions, pow, reciprocal, reduce, reduce, reduceSlices, reduceSlices, reorder, reorder, replaceColumn, replaceRow, reshape, reshape, rotateView, scaleAdd, scaleAdd, set, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setColumn, setElements, setElements, setMultiple, setMultiple, setMultiple, setMultiple, setMultiple, setRow, setSparse, setSparse, signum, slice, slice, sliceCount, sparse, sparseClone, sqrt, square, sub, sub, sub, subArray, subCopy, subMatrix, toAffineTransform, toDoubleArray, toDoubleBuffer, toMatrix, toMatrixTranspose, toMutableMatrix, toNestedDoubleArrays, toSliceArray, toString, toStringFull, toVector, transformInPlace, transformInPlace, transposeInnerProduct, transposeInPlace, upperBandwidth, upperBandwidthLimit
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
absDiff, absDiffCopy, add, addApplyOp, addAt, addCopy, addInnerProduct, addInnerProduct, addMultipleSparse, addPower, addPower, addSparse, broadcastLike, compareTo, componentCount, divideCopy, elementMaxAbs, elementMin, elementProduct, epsilonEquals, equals, equalsArray, get, get, get, get, getComponent, getComponents, getElements, getElements, getElements, isDense, isSparse, join, multiplyCopy, negateCopy, reciprocalCopy, scale, scaleCopy, setElements, setInnerProduct, setSparse, sliceValue, sub, sub, subCopy, withComponents
-
Methods inherited from interface mikera.matrixx.IMatrix
add2, addAt, addCopy, addCopy, columnCount, diagonalProduct, getBand, getColumnClone, getColumns, getColumnView, getRowClone, getRows, getRowView, getTransposeView, innerProduct, innerProduct, isInvertible, isRectangularDiagonal, isSquare, rowCount, subMatrix, toNestedDoubleArrays, transformInPlace, transposeInPlace
-
Methods inherited from interface mikera.arrayz.INDArray
abs, absCopy, absDiff, absDiffCopy, add, add, addApplyOp, addAt, addCopy, addCopy, addInnerProduct, addInnerProduct, addMultiple, addMultipleSparse, addOuterProduct, addOuterProductSparse, addPower, addPower, addSparse, addSparse, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, broadcastLike, clamp, clone, componentCount, copy, dense, denseClone, dimensionality, divide, divide, divideCopy, divideCopy, elementCount, elementIterator, elementMax, elementMaxAbs, elementMin, elementProduct, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, equals, equalsArray, equalsArray, exp, fill, get, get, get, get, get, get, get, get, getComponent, getComponents, getElement, getElements, getElements, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getSlices, getSliceViews, getTransposeCopy, immutable, innerProduct, innerProduct, innerProduct, isDense, isElementConstrained, isFullyMutable, isSameShape, isSparse, isView, join, join, log, multiply, multiply, multiplyCopy, multiplyCopy, mutable, negate, negateCopy, outerProduct, pow, reciprocal, reciprocalCopy, reduce, reduce, reduceSlices, reduceSlices, reorder, reorder, reshape, rotateView, scale, scaleAdd, scaleAdd, scaleCopy, set, set, set, set, set, set, setApplyOp, setElements, setElements, setElements, setInnerProduct, setMultiple, setMultiple, setSparse, setSparse, signum, signumCopy, slice, slice, sliceCount, sliceValue, sparse, sparseClone, sqrt, square, squareCopy, sub, sub, subArray, subCopy, toDoubleArray, toDoubleBuffer, toSliceArray, toVector, withComponents
-
-
-
-
Method Detail
-
createIdentity
public static PermutationMatrix createIdentity(int length)
-
createSwap
public static PermutationMatrix createSwap(int i, int j, int length)
-
create
public static PermutationMatrix create(Index rowPermutations)
-
wrap
public static PermutationMatrix wrap(Index rowPermutations)
-
create
public static PermutationMatrix create(int... rowPermutations)
-
wrap
public static PermutationMatrix wrap(int[] rowPermutations)
-
createRandomPermutation
public static PermutationMatrix createRandomPermutation(int length)
-
addToArray
public void addToArray(double[] data, int offset)Description copied from interface:INDArrayAdds all the elements of this array to a double array at the specified offset, in row-major order- Specified by:
addToArrayin interfaceINDArray- Overrides:
addToArrayin classAMatrix
-
isMutable
public boolean isMutable()
Description copied from interface:INDArrayReturns true if the INDArray is mutable (at least partially)
-
isSymmetric
public boolean isSymmetric()
Description copied from class:AMatrixReturns true if a matrix is symmetric- Specified by:
isSymmetricin interfaceIMatrix- Overrides:
isSymmetricin classAMatrix- Returns:
-
determinant
public double determinant()
Description copied from class:AMatrixCalculates the determinant of the matrix.- Overrides:
determinantin classAMatrix
-
rank
public int rank()
Description copied from class:AMatrixCalculate the rank of a matrix. This is equivalent to the maximum number of linearly independent rows or columns.
-
isIdentity
public boolean isIdentity()
Description copied from interface:IMatrixChecks if this is an identity matrix (i.e. 1.0 in leading diagonal, 0.0 elsewhere)- Specified by:
isIdentityin interfaceIMatrix- Overrides:
isIdentityin classAMatrix- Returns:
- true if this matrix is a square identity matrix, false otherwise.
-
isOrthogonal
public boolean isOrthogonal()
Description copied from class:AMatrixCheck to see if the matrix is orthogonal (default tolerance: 1e-8)- Overrides:
isOrthogonalin classAMatrix- Returns:
-
isOrthogonal
public boolean isOrthogonal(double tolerance)
Description copied from class:AMatrixCheck to see if the matrix is orthogonal- Overrides:
isOrthogonalin classAMatrix- Parameters:
tolerance- inner product of a column with all of the next columns should be less than tolerance- Returns:
-
hasOrthonormalColumns
public boolean hasOrthonormalColumns()
Description copied from class:AMatrixTests whether all columns in the matrix are orthonormal vectors- Overrides:
hasOrthonormalColumnsin classAMatrix- Returns:
-
hasOrthonormalRows
public boolean hasOrthonormalRows()
Description copied from class:AMatrixTests whether all rows in the matrix are orthonormal vectors- Overrides:
hasOrthonormalRowsin classAMatrix- Returns:
-
isDiagonal
public boolean isDiagonal()
Description copied from interface:IMatrixReturns true iff this matrix is a square diagonal matrix- Specified by:
isDiagonalin interfaceIMatrix- Overrides:
isDiagonalin classAMatrix
-
isBoolean
public boolean isBoolean()
Description copied from interface:INDArrayReturns true if the array is boolean (contains only 0.0 or 1.0 values)- Specified by:
isBooleanin interfaceINDArray- Overrides:
isBooleanin classABooleanMatrix
-
isUpperTriangular
public boolean isUpperTriangular()
Description copied from class:AMatrixReturns true if a matrix is upper triangular An upper triangular matrix is defined as having all elements equal to 0.0 where i > j- Overrides:
isUpperTriangularin classAMatrix
-
isLowerTriangular
public boolean isLowerTriangular()
Description copied from class:AMatrixReturns true if a matrix is lower triangular. A lower triangular matrix is defined as having all elements equal to 0.0 where i < j- Overrides:
isLowerTriangularin classAMatrix
-
elementSum
public double elementSum()
Description copied from class:AMatrixReturns the sum of all elements in this matrix- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classABooleanMatrix
-
elementSquaredSum
public double elementSquaredSum()
Description copied from class:AMatrixReturns the squared sum of all elements in this matrix- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classABooleanMatrix
-
nonZeroCount
public long nonZeroCount()
Description copied from interface:INDArrayReturns the number of non-zero elements in the array.- Specified by:
nonZeroCountin interfaceINDArray- Overrides:
nonZeroCountin classAMatrix
-
trace
public double trace()
Description copied from interface:IMatrixComputes the trace of a matrix, i.e. the sum of all elements on the leading diagonal
-
inverse
public PermutationMatrix inverse()
Description copied from class:AMatrixComputes the inverse of a matrix. Returns null if the matrix is singular. Throws an Exception is the matrix is not square
-
getTranspose
public PermutationMatrix getTranspose()
Description copied from interface:INDArrayReturns the transpose of this array. A transpose of an array is equivalent to reversing the order of dimensions. May or may not return a view depending on the array type.- Specified by:
getTransposein interfaceINDArray- Specified by:
getTransposein interfaceIMatrix- Overrides:
getTransposein classAMatrix- Returns:
- the transpose of this matrix
-
get
public double get(int row, int column)Description copied from interface:INDArrayReturns the double value at the specified position in a 2D matrix
-
unsafeSet
public void unsafeSet(int row, int column, double value)Description copied from class:AMatrixSets an element value in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.
-
unsafeGet
public double unsafeGet(int row, int column)Description copied from class:AMatrixGets an element in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.
-
set
public void set(int row, int column, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 2D array
-
getRow
public AxisVector getRow(int i)
Description copied from interface:IMatrixReturns a row of the matrix. May or may not be a view, depending on matrix type. Intended for the fastest possible read access of the row. This often means a view, but might not be (e.g. getRow on a Matrix33 returns a Vector3).
-
getColumn
public AxisVector getColumn(int j)
Description copied from interface:IMatrixReturns a column of the matrix. May or may not be a view, depending on matrix type. Intended for the fastest possible read access of the column. This often means a view, but might not be (e.g. getColumn on a Matrix33 returns a Vector3).
-
copyRowTo
public void copyRowTo(int row, double[] dest, int destOffset)Description copied from class:AMatrixCopies the elements in a selected row of this matrix to a double array
-
copyColumnTo
public void copyColumnTo(int col, double[] dest, int destOffset)Description copied from class:AMatrixCopies the elements in a selected row of this matrix to a double array- Overrides:
copyColumnToin classAMatrixdest- Destination double[] array
-
swapRows
public void swapRows(int i, int j)Description copied from class:AMatrixSwaps two rows of the matrix in place This is an elementary row operation
-
swapColumns
public void swapColumns(int i, int j)Description copied from class:AMatrixSwaps two columns of the matrix in place- Overrides:
swapColumnsin classAMatrix
-
transform
public void transform(AVector source, AVector dest)
Description copied from interface:IMatrixTransforms a source vector into a destination vector, using matrix multiplication (inner product). The destination vector is overwritten.
-
rowDotProduct
public double rowDotProduct(int i, AVector v)Description copied from class:AMatrixReturns the dot product of a specific row with a vector. Unsafe operation: performs no bounds checking- Overrides:
rowDotProductin classAMatrix- Returns:
-
innerProduct
public Matrix innerProduct(AMatrix a)
Description copied from interface:IMatrixComputes the inner product of this matrix with another. Equivalent to matrix x matrix multiplication- Specified by:
innerProductin interfaceIMatrix- Overrides:
innerProductin classAMatrix- Returns:
-
transposeInnerProduct
public Matrix transposeInnerProduct(Matrix s)
- Overrides:
transposeInnerProductin classAMatrix
-
validate
public void validate()
Description copied from interface:INDArrayValidates the internal data structure of the INDArray. Throws an exception on failure. Failure indicates a serious bug and/or data corruption.- Specified by:
validatein interfaceINDArray- Overrides:
validatein classABooleanMatrix
-
density
public double density()
Description copied from interface:ISparseComputes the density ratio of this sparse array (proportion of non-zero elements)- Specified by:
densityin interfaceISparse- Overrides:
densityin classAbstractArray<AVector>- Returns:
-
exactClone
public PermutationMatrix exactClone()
Description copied from interface:INDArrayCreates a deep clone of an array, using the same class implementation as the original array- Specified by:
exactClonein interfaceINDArray- Specified by:
exactClonein classAMatrix- Returns:
- A clone of the original array
-
hasUncountable
public boolean hasUncountable()
Description copied from class:AMatrixChecks to see if any element in the matrix is NaN of Infinite.- Specified by:
hasUncountablein interfaceINDArray- Overrides:
hasUncountablein classABooleanMatrix- Returns:
- True if any element in the matrix is NaN of Infinite.
-
elementPowSum
public double elementPowSum(double p)
Returns the sum of all the elements raised to a specified power- Specified by:
elementPowSumin interfaceINDArray- Overrides:
elementPowSumin classABooleanMatrix- Returns:
-
elementAbsPowSum
public double elementAbsPowSum(double p)
Returns the sum of the absolute values of all the elements raised to a specified power- Specified by:
elementAbsPowSumin interfaceINDArray- Overrides:
elementAbsPowSumin classABooleanMatrix- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG