mikera.matrixx.impl
Class ADiagonalMatrix
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<AVector>
-
- mikera.matrixx.AMatrix
-
- mikera.matrixx.impl.ABandedMatrix
-
- mikera.matrixx.impl.ASingleBandMatrix
-
- mikera.matrixx.impl.ADiagonalMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, INDArray, ISparse, IMatrix, IFastBands
- Direct Known Subclasses:
- DiagonalMatrix, IdentityMatrix, ScalarMatrix, WrappedDiagonalMatrix
public abstract class ADiagonalMatrix extends ASingleBandMatrix
Abstract base class for square diagonal matrices- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description AMatrixaddCopy(AMatrix a)Adds another matrix to this matrix, returning a new matrixvoidaddOuterProductSparse(AVector a, AVector b)Adds the outer product of two vectors to this matrix.voidaddToArray(double[] dest, int offset)Adds all the elements of this array to a double array at the specified offset, in row-major orderintcheckSquare()Checks if a matrix is square.AMatrixclone()Returns a clone of the array data, as a new array which will be fully mutable and may be of a different class to the original.intcolumnCount()Gets the number of columns in this matrix (dimension 1)voidcopyColumnTo(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 arraydoubledeterminant()Calculates the determinant of the matrix.doublediagonalProduct()Computes the product of entries on the main diagonal of a matrixintdimensions()Returns the number of dimensions of this diagonal matrixdoubleelementAbsPowSum(double p)Returns the sum of the absolute values of all the elements raised to a specified powerdoubleelementMax()Returns the maximum element value in this array.doubleelementMin()Returns the maximum element value in this array.doubleelementPowSum(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 matrixbooleanequalsTranspose(AMatrix m)Tests if this matrix is exactly equal to the transpose of another matrixabstract ADiagonalMatrixexactClone()Creates a deep clone of an array, using the same class implementation as the original arrayAVectorgetBand(int band)Gets a specific band of the matrix, as a view vector.ASingleElementVectorgetColumn(int col)Returns a column of the matrix.doublegetDiagonalValue(int i)abstract AVectorgetLeadingDiagonal()Returns a vector view of the leading diagonal values of the matrixAVectorgetNonZeroBand()Gets the non-zero band from the matrixASingleElementVectorgetRow(int row)Returns a row of the matrix.ADiagonalMatrixgetTranspose()Returns the transpose of this array.ADiagonalMatrixgetTransposeView()Returns a transposed view of the array.booleanhasUncountable()Checks to see if any element in the matrix is NaN of Infinite.AMatrixinnerProduct(ADiagonalMatrix a)Computes the inner product of this matrix with another diagonal matrix of the same shape.AMatrixinnerProduct(AMatrix a)Computes the inner product of this matrix with another.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 matrixbooleanisFullyMutable()If this method returns true, the INDArray is guaranteed to be fully mutable in all positions i.e.booleanisIdentity()Checks if this is an identity matrix (i.e.booleanisLowerTriangular()Returns true if a matrix is lower triangular.abstract booleanisMutable()Returns true if the INDArray is mutable (at least partially)booleanisRectangularDiagonal()Returns true iff this matrix is a diagonal matrix (might not be square)booleanisSameShape(AMatrix m)Returns true iff this matrix is exactly the same shape as another matrixbooleanisSameShape(ARectangularMatrix m)booleanisSquare()Checks if this is a square matrixbooleanisSymmetric()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)intlowerBandwidthLimit()A limit on the lower bandwidth of the banded matrix.intnonZeroBand()Specifies which band of the matrix is nonzerolongnonZeroCount()Returns the number of non-zero elements in the array.intrank()Calculate the rank of a matrix.introwCount()Gets the number of rows in this matrix (dimension 0)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 arrayvoidsetSparse(double value)Sets the non-sparse elements of this array to the specified value May throw an exception if non-sparse elements are not mutabledouble[]toDoubleArray()Copies the elements of this array to a new double[] array.MatrixtoMatrix()Coerces the matrix to the standard mutable Matrix type in row major order.MatrixtoMatrixTranspose()Coerces the transpose of a matrix to the standard mutable Matrix type in row major order.doubletrace()Computes the trace of a matrix, i.e.voidtransform(Vector source, Vector dest)voidtransformInPlace(ADenseArrayVector v)voidtransformInPlace(AVector v)AMatrixtransposeInnerProduct(AMatrix s)voidtransposeInPlace()Transposes a matrix in place, if possible.doubleunsafeGetDiagonalValue(int i)intupperBandwidthLimit()A limit on the upper bandwidth of the banded matrix.voidvalidate()Validates the internal data structure of the INDArray.-
Methods inherited from class mikera.matrixx.impl.ASingleBandMatrix
isSparse, subMatrix
-
Methods inherited from class mikera.matrixx.impl.ABandedMatrix
density, fill, getRowView, lowerBandwidth, multiply, upperBandwidth
-
Methods inherited from class mikera.matrixx.AMatrix
abs, add, add, add, add, add2, addAt, addCopy, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addOuterProduct, addOuterProduct, addOuterProductSparse, addRowMultiple, addSparse, addSparse, applyOp, applyOp, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, bandIndex, bandLength, bandPosition, bandStartColumn, bandStartRow, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, checkColumn, checkRow, clamp, composeWith, copy, dense, denseClone, dimensionality, divide, divide, divide, divide, divideCopy, elementCount, elementIterator, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, equals, equalsArray, exp, get, get, get, get, get, getBandWrapped, getColumnClone, getColumns, getColumnView, getElement, getElements, getLongShape, getRowClone, getRows, getShape, getShape, getShapeClone, getSlices, getSlices, getSliceViews, getTransposeCopy, hashCode, hasOrthonormalColumns, hasOrthonormalRows, immutable, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, inputDimensions, inverse, isElementConstrained, isHermitian, isInvertible, isOrthogonal, isOrthogonal, isPositiveDefinite, isSameShape, isView, iterator, join, log, mul, 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, swapColumns, swapRows, toAffineTransform, toDoubleBuffer, toMutableMatrix, toNestedDoubleArrays, toSliceArray, toString, toStringFull, toVector, transform, transposeInnerProduct, unsafeGet, unsafeSet
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
absCopy, absDiff, absDiffCopy, add, addApplyOp, addAt, addCopy, addInnerProduct, addInnerProduct, addMultipleSparse, addPower, addPower, addSparse, broadcastLike, compareTo, componentCount, divideCopy, elementMaxAbs, elementProduct, epsilonEquals, equals, equalsArray, get, get, get, get, getComponent, getComponents, getElements, getElements, getElements, isDense, join, multiplyCopy, negateCopy, reciprocalCopy, scale, scaleCopy, setElements, setInnerProduct, signumCopy, sliceValue, squareCopy, sub, sub, subCopy, withComponents
-
Methods inherited from interface mikera.arrayz.INDArray
absCopy, absDiff, absDiffCopy, addApplyOp, addAt, addInnerProduct, addMultipleSparse, addPower, addPower, addSparse, broadcastLike, componentCount, divideCopy, elementMaxAbs, elementProduct, epsilonEquals, equalsArray, get, get, get, get, getComponent, getComponents, getElements, getElements, getElements, isDense, join, multiplyCopy, negateCopy, reciprocalCopy, scale, scaleCopy, setElements, setInnerProduct, signumCopy, sliceValue, squareCopy, sub, subCopy, withComponents
-
-
-
-
Method Detail
-
nonZeroBand
public int nonZeroBand()
Description copied from class:ASingleBandMatrixSpecifies which band of the matrix is nonzero- Specified by:
nonZeroBandin classASingleBandMatrix- Returns:
-
isSquare
public boolean isSquare()
Description copied from interface:IMatrixChecks if this is a square matrix
-
isZero
public boolean isZero()
Description copied from class:AMatrixReturns true if the matrix is the zero matrix (all components zero)- Specified by:
isZeroin interfaceINDArray- Overrides:
isZeroin classASingleBandMatrix
-
isBoolean
public boolean isBoolean()
Description copied from interface:INDArrayReturns true if the array is boolean (contains only 0.0 or 1.0 values)
-
isSymmetric
public boolean isSymmetric()
Description copied from class:AMatrixReturns true if a matrix is symmetric- Specified by:
isSymmetricin interfaceIMatrix- Overrides:
isSymmetricin classASingleBandMatrix- 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
-
isRectangularDiagonal
public boolean isRectangularDiagonal()
Description copied from interface:IMatrixReturns true iff this matrix is a diagonal matrix (might not be square)- Specified by:
isRectangularDiagonalin interfaceIMatrix- Overrides:
isRectangularDiagonalin classAMatrix
-
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 classABandedMatrix
-
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 classABandedMatrix
-
isMutable
public abstract boolean isMutable()
Description copied from interface:INDArrayReturns true if the INDArray is mutable (at least partially)- Specified by:
isMutablein interfaceINDArray- Overrides:
isMutablein classABandedMatrix
-
isFullyMutable
public boolean isFullyMutable()
Description copied from interface:INDArrayIf this method returns true, the INDArray is guaranteed to be fully mutable in all positions i.e. every position can store any valid double value- Specified by:
isFullyMutablein interfaceINDArray- Overrides:
isFullyMutablein classABandedMatrix
-
isSameShape
public final boolean isSameShape(ARectangularMatrix m)
-
upperBandwidthLimit
public final int upperBandwidthLimit()
Description copied from class:AMatrixA limit on the upper bandwidth of the banded matrix. Actual upper bandwidth is guaranteed to be less than or equal to this value. Implementation should be O(1).- Specified by:
upperBandwidthLimitin classABandedMatrix- Returns:
-
lowerBandwidthLimit
public final int lowerBandwidthLimit()
Description copied from class:AMatrixA limit on the lower bandwidth of the banded matrix. Actual lower bandwidth is guaranteed to be less than or equal to this value. Implementation should be O(1).- Specified by:
lowerBandwidthLimitin classABandedMatrix- Returns:
-
getBand
public AVector getBand(int band)
Description copied from class:AMatrixGets a specific band of the matrix, as a view vector. The band is truncated at the edges of the matrix, i.e. it does not wrap around the matrix.- Specified by:
getBandin interfaceIMatrix- Specified by:
getBandin interfaceIFastBands- Overrides:
getBandin classASingleBandMatrix- Returns:
-
getNonZeroBand
public AVector getNonZeroBand()
Description copied from class:ASingleBandMatrixGets the non-zero band from the matrix- Specified by:
getNonZeroBandin classASingleBandMatrix- 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.- Overrides:
rankin classASingleBandMatrix
-
dimensions
public int dimensions()
Returns the number of dimensions of this diagonal matrix- Returns:
-
isSameShape
public boolean isSameShape(AMatrix m)
Description copied from class:AMatrixReturns true iff this matrix is exactly the same shape as another matrix- Overrides:
isSameShapein classAMatrix- Returns:
-
checkSquare
public int checkSquare()
Description copied from class:AMatrixChecks if a matrix is square. Returns the size if true, throws an exception otherwise;- Overrides:
checkSquarein classAMatrix- Returns:
-
elementMax
public double elementMax()
Description copied from interface:INDArrayReturns the maximum element value in this array. Throws an error if there are no elements.- Specified by:
elementMaxin interfaceINDArray- Overrides:
elementMaxin classAbstractArray<AVector>
-
elementMin
public double elementMin()
Description copied from interface:INDArrayReturns the maximum element value in this array. Throws an error if there are no elements.- Specified by:
elementMinin interfaceINDArray- Overrides:
elementMinin classAbstractArray<AVector>
-
elementSum
public double elementSum()
Description copied from class:AMatrixReturns the sum of all elements in this matrix- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classABandedMatrix
-
elementSquaredSum
public double elementSquaredSum()
Description copied from class:AMatrixReturns the squared sum of all elements in this matrix- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classABandedMatrix
-
nonZeroCount
public long nonZeroCount()
Description copied from interface:INDArrayReturns the number of non-zero elements in the array.- Specified by:
nonZeroCountin interfaceINDArray- Overrides:
nonZeroCountin classASingleBandMatrix
-
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- Overrides:
copyRowToin classABandedMatrix- Parameters:
row- The index of the selected rowdest- Destination double[] arraydestOffset- Offset into destination array
-
addToArray
public void addToArray(double[] dest, 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 classABandedMatrix
-
addCopy
public AMatrix addCopy(AMatrix a)
Description copied from interface:IMatrixAdds another matrix to this matrix, returning a new matrix
-
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
-
innerProduct
public AMatrix innerProduct(ADiagonalMatrix a)
Computes the inner product of this matrix with another diagonal matrix of the same shape. The result will be a diagnonal matrix of the same shape.- Parameters:
a-- Returns:
-
innerProduct
public AMatrix 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:
-
addOuterProductSparse
public void addOuterProductSparse(AVector a, AVector b)
Description copied from class:AMatrixAdds the outer product of two vectors to this matrix. Mutates only the non-sparse elements in this matrix- Overrides:
addOuterProductSparsein classAMatrix
-
transposeInnerProduct
public AMatrix transposeInnerProduct(AMatrix s)
- Overrides:
transposeInnerProductin classAMatrix
-
transformInPlace
public void transformInPlace(AVector v)
- Specified by:
transformInPlacein interfaceIMatrix- Overrides:
transformInPlacein classAMatrix
-
transformInPlace
public void transformInPlace(ADenseArrayVector v)
- Overrides:
transformInPlacein classAMatrix
-
rowCount
public int rowCount()
Description copied from interface:IMatrixGets the number of rows in this matrix (dimension 0)- Returns:
-
columnCount
public int columnCount()
Description copied from interface:IMatrixGets the number of columns in this matrix (dimension 1)- Returns:
-
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 classASingleBandMatrix- Returns:
- true if this matrix is a square identity matrix, false otherwise.
-
transposeInPlace
public void transposeInPlace()
Description copied from interface:IMatrixTransposes a matrix in place, if possible. Throws an exception if this is not possible (e.g. if the matrix is not square or not sufficiently mutable)- Specified by:
transposeInPlacein interfaceIMatrix- Overrides:
transposeInPlacein classAMatrix
-
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:
-
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
-
setSparse
public void setSparse(double value)
Description copied from interface:INDArraySets the non-sparse elements of this array to the specified value May throw an exception if non-sparse elements are not mutable- Specified by:
setSparsein interfaceINDArray- Overrides:
setSparsein classABandedMatrix
-
getLeadingDiagonal
public abstract AVector getLeadingDiagonal()
Description copied from class:AMatrixReturns a vector view of the leading diagonal values of the matrix- Overrides:
getLeadingDiagonalin classAMatrix- Returns:
-
getDiagonalValue
public double getDiagonalValue(int i)
-
getRow
public ASingleElementVector getRow(int row)
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 ASingleElementVector getColumn(int col)
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).
-
unsafeGetDiagonalValue
public double unsafeGetDiagonalValue(int i)
-
getTranspose
public ADiagonalMatrix 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
-
getTransposeView
public ADiagonalMatrix getTransposeView()
Description copied from interface:INDArrayReturns a transposed view of the array. May throw UnsupportedOperationException if the array type does not support this capability- Specified by:
getTransposeViewin interfaceINDArray- Specified by:
getTransposeViewin interfaceIMatrix- Overrides:
getTransposeViewin classAMatrix- Returns:
- the transpose of this matrix, as a view
-
toMatrix
public Matrix toMatrix()
Description copied from class:AMatrixCoerces the matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.- Overrides:
toMatrixin classABandedMatrix
-
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- Specified by:
tracein interfaceIMatrix- Overrides:
tracein classABandedMatrix- Returns:
-
diagonalProduct
public double diagonalProduct()
Description copied from class:AMatrixComputes the product of entries on the main diagonal of a matrix- Specified by:
diagonalProductin interfaceIMatrix- Overrides:
diagonalProductin classABandedMatrix- Returns:
-
toDoubleArray
public double[] toDoubleArray()
Description copied from interface:INDArrayCopies the elements of this array to a new double[] array.- Specified by:
toDoubleArrayin interfaceINDArray- Overrides:
toDoubleArrayin classABandedMatrix
-
toMatrixTranspose
public final Matrix toMatrixTranspose()
Description copied from class:AMatrixCoerces the transpose of a matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.- Overrides:
toMatrixTransposein classABandedMatrix
-
equalsTranspose
public boolean equalsTranspose(AMatrix m)
Description copied from class:AMatrixTests if this matrix is exactly equal to the transpose of another matrix- Overrides:
equalsTransposein classAMatrix- Returns:
-
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 classABandedMatrix
-
exactClone
public abstract ADiagonalMatrix 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
-
clone
public AMatrix clone()
Description copied from interface:INDArrayReturns a clone of the array data, as a new array which will be fully mutable and may be of a different class to the original. Clone should attempt to return the most efficient possible array type. Clone should preserve sparsity property where possible, but this is not guaranteed.
-
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 classASingleBandMatrix- 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 classASingleBandMatrix- 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 classASingleBandMatrix- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG