mikera.matrixx.impl
Class DiagonalMatrix
- java.lang.Object
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, INDArray, ISparse, IMatrix, IFastBands
public final class DiagonalMatrix extends ADiagonalMatrix
Specialised diagonal matrix class, with dense double[] array storage for the leading diagonal only. Not fully mutable - only the diagonal values can be changed- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DiagonalMatrix(int dimensions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddSparse(double c)Adds to the non-sparse elements of this arrayAMatrixclone()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.static DiagonalMatrixcreate(AMatrix m)static DiagonalMatrixcreate(AVector v)static DiagonalMatrixcreate(double... values)static DiagonalMatrixcreateDimensions(int dims)doubledeterminant()Calculates the determinant of the matrix.doublediagonalProduct()Computes the product of entries on the main diagonal of a matrixdoubleelementSum()Returns the sum of all elements in this matrixDiagonalMatrixexactClone()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 matrixdoublegetDiagonalValue(int i)VectorgetLeadingDiagonal()Returns a vector view of the leading diagonal values of the matrixAMatrixinnerProduct(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.DiagonalMatrixinverse()Computes the inverse of a matrix.booleanisBoolean()Returns true if the array is boolean (contains only 0.0 or 1.0 values)booleanisFullyMutable()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.booleanisMutable()Returns true if the INDArray is mutable (at least partially)booleanisZero()Returns true if the matrix is the zero matrix (all components zero)voidmultiply(double factor)Multiplies all elements of the array in place by a given double valueDiagonalMatrixmultiplyCopy(double factor)Returns a copy of the array with all elements multiplied by a single constant valuelongnonZeroCount()Returns the number of non-zero elements in the array.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(AMatrix a)Sets the non-sparse elements in this matrix to the corresponding values in the source matrixdoubletrace()Computes the trace of a matrix, i.e.voidtransform(Vector source, Vector dest)voidtransformInPlace(ADenseArrayVector v)voidtransformInPlace(AVector v)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.doubleunsafeGetDiagonalValue(int i)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 DiagonalMatrixwrap(double[] data)static DiagonalMatrixwrap(Vector data)-
Methods inherited from class mikera.matrixx.impl.ADiagonalMatrix
addCopy, addOuterProductSparse, addToArray, checkSquare, columnCount, copyColumnTo, copyRowTo, dimensions, elementAbsPowSum, elementMax, elementMin, elementPowSum, elementSquaredSum, equalsTranspose, getBand, getColumn, getNonZeroBand, getRow, getTranspose, getTransposeView, hasUncountable, isDiagonal, isLowerTriangular, isRectangularDiagonal, isSameShape, isSameShape, isSquare, isSymmetric, isUpperTriangular, lowerBandwidthLimit, nonZeroBand, rank, rowCount, setSparse, toDoubleArray, toMatrix, toMatrixTranspose, transposeInnerProduct, transposeInPlace, upperBandwidthLimit
-
Methods inherited from class mikera.matrixx.impl.ASingleBandMatrix
isSparse, subMatrix
-
Methods inherited from class mikera.matrixx.impl.ABandedMatrix
density, fill, getRowView, lowerBandwidth, 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, 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, isElementConstrained, isHermitian, isInvertible, isOrthogonal, isOrthogonal, isPositiveDefinite, isSameShape, isView, iterator, join, log, mul, multiply, multiply, multiply, 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, 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
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
absCopy, absDiff, absDiffCopy, add, addApplyOp, addAt, addCopy, addInnerProduct, addInnerProduct, addMultipleSparse, addPower, addPower, 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, 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
-
createDimensions
public static DiagonalMatrix createDimensions(int dims)
-
create
public static DiagonalMatrix create(double... values)
-
create
public static DiagonalMatrix create(AVector v)
-
create
public static DiagonalMatrix create(AMatrix m)
-
wrap
public static DiagonalMatrix wrap(double[] data)
-
wrap
public static DiagonalMatrix wrap(Vector data)
-
addSparse
public void addSparse(double c)
Description copied from interface:INDArrayAdds to the non-sparse elements of this array- Specified by:
addSparsein interfaceINDArray- Overrides:
addSparsein classAbstractArray<AVector>
-
setSparse
public void setSparse(AMatrix a)
Description copied from class:AMatrixSets the non-sparse elements in this matrix to the corresponding values in the source matrix
-
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 classADiagonalMatrix- 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 classADiagonalMatrix- Returns:
-
elementSum
public double elementSum()
Description copied from class:AMatrixReturns the sum of all elements in this matrix- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classADiagonalMatrix
-
nonZeroCount
public long nonZeroCount()
Description copied from interface:INDArrayReturns the number of non-zero elements in the array.- Specified by:
nonZeroCountin interfaceINDArray- Overrides:
nonZeroCountin classADiagonalMatrix
-
get
public double get(int row, int column)Description copied from interface:INDArrayReturns the double value at the specified position in a 2D matrix
-
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
-
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.
-
isMutable
public boolean isMutable()
Description copied from interface:INDArrayReturns true if the INDArray is mutable (at least partially)- Specified by:
isMutablein interfaceINDArray- Specified by:
isMutablein classADiagonalMatrix
-
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 classADiagonalMatrix
-
multiply
public void multiply(double factor)
Description copied from interface:INDArrayMultiplies all elements of the array in place by a given double value- Specified by:
multiplyin interfaceINDArray- Overrides:
multiplyin classABandedMatrix
-
multiplyCopy
public DiagonalMatrix multiplyCopy(double factor)
Description copied from interface:INDArrayReturns a copy of the array with all elements multiplied by a single constant value- Specified by:
multiplyCopyin interfaceINDArray- Overrides:
multiplyCopyin classAMatrix- Parameters:
factor- A scalar factor- Returns:
- A new array, with all element values scaled by the given factor
-
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 classADiagonalMatrix- Returns:
-
transform
public void transform(Vector source, Vector dest)
- Overrides:
transformin classADiagonalMatrix
-
transformInPlace
public void transformInPlace(AVector v)
- Specified by:
transformInPlacein interfaceIMatrix- Overrides:
transformInPlacein classADiagonalMatrix
-
transformInPlace
public void transformInPlace(ADenseArrayVector v)
- Overrides:
transformInPlacein classADiagonalMatrix
-
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 classADiagonalMatrix- Returns:
- true if this matrix is a square identity matrix, false otherwise.
-
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 classADiagonalMatrix
-
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 classADiagonalMatrix
-
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.- Specified by:
clonein interfaceINDArray- Overrides:
clonein classADiagonalMatrix
-
determinant
public double determinant()
Description copied from class:AMatrixCalculates the determinant of the matrix.- Overrides:
determinantin classADiagonalMatrix
-
inverse
public DiagonalMatrix 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
-
getDiagonalValue
public double getDiagonalValue(int i)
- Overrides:
getDiagonalValuein classADiagonalMatrix
-
unsafeGetDiagonalValue
public double unsafeGetDiagonalValue(int i)
- Overrides:
unsafeGetDiagonalValuein classADiagonalMatrix
-
getLeadingDiagonal
public Vector getLeadingDiagonal()
Description copied from class:AMatrixReturns a vector view of the leading diagonal values of the matrix- Specified by:
getLeadingDiagonalin classADiagonalMatrix- 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 classADiagonalMatrix- Returns:
-
innerProduct
public AMatrix innerProduct(ADiagonalMatrix a)
Description copied from class:ADiagonalMatrixComputes 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.- Overrides:
innerProductin classADiagonalMatrix- Returns:
-
exactClone
public DiagonalMatrix 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 classADiagonalMatrix- Returns:
- A clone of the original array
-
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 classADiagonalMatrix
-
-
DMelt 3.0 © DataMelt by jWork.ORG