mikera.vectorz.impl
Class ASparseVector
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<java.lang.Double>
-
- mikera.vectorz.AVector
-
- mikera.vectorz.impl.ASizedVector
-
- mikera.vectorz.impl.ASparseVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, INDArray, ISparse, ISparseVector, IVector
- Direct Known Subclasses:
- ASingleElementVector, ASparseIndexedVector, SparseHashedVector, ZeroVector
public abstract class ASparseVector extends ASizedVector implements ISparseVector
Abstract base class for Sparse vector implementations- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description abstract voidadd(ASparseVector v)voidadd(AVector v)Adds another vector to this onevoidaddMultiple(AVector src, double factor)Adds a scaled multiple of another vector to this vectorAVectorclone()Clones the vector, creating a new mutable copy of all data.voidcopyTo(int offset, double[] destData, int destOffset, int length)Copies a subset of this vector to a specified destination array offsetvoidcopyTo(int offset, double[] destData, int destOffset, int length, int stride)Copies a subset of this vector to a specified destination array offset using the given stride.doubledensity()Computes the density ratio of this sparse array (proportion of non-zero elements)doubledistanceL1(AVector v)Returns the distance from this vector to another vector according to the L1 (Taxicab) norm.doubledistanceLinf(AVector v)Returns the distance from this vector to another vector according to the Linf norm.doubledistanceSquared(AVector v)Returns the squared Euclidean distance to another vector.doubledotProduct(ADenseArrayVector v)Returns the dot product of this vector with a target ADenseArrayVector.abstract doubledotProduct(AVector v)Returns the dot product of this vector with another vector The vectors must have the same length: if not the result is undefineddoubleelementAbsPowSum(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 powerdoubleelementProduct()Returns the product of all elements in the array.doubleelementSquaredSum()Returns the sum of squared elements in this array.doubleelementSum()Returns the sum of all elements in a vectorbooleanequals(ASparseVector v)booleanequals(AVector v)Returns true if this array is exactly equal to a vector.java.util.List<java.lang.Double>getSlices()Returns a list of all major slices of this array.booleanhasUncountable()Returns true if any element is this array is NaN or infiniteabstract booleanincludesIndex(int i)Returns true iff the sparse vector contains the index iAVectorinnerProduct(AMatrix m)Computes the inner product of this vector with a matrixbooleanisSparse()Returns true if the array is in a sparse formatbooleanisView()Returns true if this vector is of a view type that references other vectors / data.booleanisZero()Returns true if this vector is a zero vector (all components zero)abstract intnonSparseElementCount()Returns the number of non-sparse elements in the sparse vector.abstract IndexnonSparseIndex()Returns an Index indicating which elements of this vector are defined as non-sparse.abstract AVectornonSparseValues()Returns the non-sparse elements as a compacted vector.longnonZeroCount()Returns the number of non-zero elements in the array.doublereduce(Op2 op)Reduces over all elements of the array in row-major order.doublereduce(Op2 op, double init)Reduces over all elements of the array in row-major order.AVectorreduceSlices(Op2 op, double init)Reduces each slice of the array by the given binary operator.ASparseVectorroundToZero(double precision)Returns a vector after replacing all elements with absolute values less-than-or-equal to precision with zeros.ASparseVectorsparse()Coerces this INDArray to a sparse format, without changing its element values.double[]toDoubleArray()Copies the elements of this array to a new double[] array.SparseIndexedVectortoSparseIndexedVector()Coerces this vector to a SparseIndexedVector.doublevisitNonZero(IndexedElementVisitor elementVisitor)Visits all non-zero elements of this vector.-
Methods inherited from class mikera.vectorz.impl.ASizedVector
checkIndex, checkLength, checkRange, elementCount, equalsArray, equalsArray, get, getShape, getShapeClone, isSameShape, length, sliceCount
-
Methods inherited from class mikera.vectorz.AVector
abs, absCopy, absDiff, absDiff, absDiff, absDiffCopy, add, add, add, add, add, add, add, add, addAt, addAt, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultipleCopy, addMultipleSparse, addMultipleSparse, addMultipleToArray, addMultipleToArray, addPower, addPower, addProduct, addProduct, addProduct, addProductCopy, addProductCopy, addProductToArray, addProductToArray, addSparse, addSparse, addToArray, addToArray, addToArray, addWeighted, angle, applyOp, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, broadcast, broadcastLike, broadcastLike, broadcastLike, clamp, clampMax, clampMin, compareTo, compareTo, copy, copyTo, copyTo, copyTo, crossProduct, crossProduct, dense, denseClone, dimensionality, distance, divide, divide, divide, divide, divideCopy, divideCopy, divideCopy, divideTo, dotProduct, dotProduct, dotProduct, elementIterator, elementMax, elementMaxAbs, elementMin, elementsEqual, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, exactClone, fill, fillRange, get, get, get, get, get, get, getElement, getElements, getElements, getElements, getLongShape, getShape, getTranspose, getTransposeCopy, getTransposeView, hashCode, immutable, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, interpolate, isElementConstrained, isFullyMutable, isMutable, isRangeZero, isSameShape, isUnitLengthVector, isUnitLengthVector, iterator, join, join, join, log, logistic, magnitude, magnitudeSquared, maxAbsElement, maxAbsElementIndex, maxElement, maxElementIndex, minElement, minElementIndex, multiply, multiply, multiply, multiply, multiply, multiplyCopy, multiplyCopy, multiplyCopy, multiplyTo, mutable, negate, negateCopy, nonZeroIndices, nonZeroValues, normalise, normaliseCopy, normaliseMaxAbsElement, outerProduct, outerProduct, pow, projectToPlane, reciprocal, reciprocalCopy, reduceSlices, reorder, reorder, reshape, rotateCopy, rotateView, rotateView, scale, scaleAdd, scaleAdd, scaleAdd, scaleAdd, scaleCopy, scaleToMagnitude, select, selectClone, selectView, set, set, set, set, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setApplyOp, setElements, setElements, setElements, setInnerProduct, setInnerProduct, setInnerProduct, setMultiple, setMultiple, setMultiple, setMultiple, setSparse, setSparse, setSparse, shiftCopy, signum, slice, slice, sliceValue, softmax, softmaxCopy, sparseClone, sqrtCopy, square, squareCopy, sub, sub, subArray, subAt, subCopy, subCopy, subMultiple, subVector, tanh, toDoubleBuffer, toList, toNormal, toSliceArray, toString, toStringFull, toVector, tryEfficientJoin, unsafeGet, unsafeSet, validate
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
add, addApplyOp, addCopy, addInnerProduct, addInnerProduct, addOuterProduct, addOuterProductSparse, addSparse, broadcastCloneLike, broadcastCopyLike, componentCount, ensureMutable, epsilonEquals, exp, get, get, getComponent, getComponents, getElements, getElements, getSlices, getSliceViews, isBoolean, isDense, scale, set, set, signumCopy, sqrt, sub, sub, withComponents
-
Methods inherited from interface mikera.vectorz.IVector
addCopy, divideCopy, epsilonEquals, get, isSameShape, length, multiplyCopy, normalise, normaliseCopy, rotateCopy, rotateView, set, shiftCopy, sqrtCopy, subCopy
-
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, addToArray, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, broadcastLike, clamp, componentCount, copy, dense, denseClone, dimensionality, divide, divide, divideCopy, divideCopy, elementCount, elementIterator, elementMax, elementMaxAbs, elementMin, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, equals, equalsArray, equalsArray, exactClone, exp, fill, get, get, get, get, get, get, get, get, getComponent, getComponents, getElement, getElements, getElements, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getSliceViews, getTranspose, getTransposeCopy, getTransposeView, immutable, innerProduct, innerProduct, innerProduct, innerProduct, isBoolean, isDense, isElementConstrained, isFullyMutable, isMutable, isSameShape, join, join, log, multiply, multiply, multiplyCopy, multiplyCopy, mutable, negate, negateCopy, outerProduct, pow, reciprocal, reciprocalCopy, 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, sparseClone, sqrt, square, squareCopy, sub, sub, subArray, subCopy, toDoubleBuffer, toSliceArray, toVector, validate, withComponents
-
-
-
-
Method Detail
-
nonSparseElementCount
public abstract int nonSparseElementCount()
Returns the number of non-sparse elements in the sparse vector. This will be greater or equal to the number of non-zero elements- Returns:
-
nonSparseValues
public abstract AVector nonSparseValues()
Description copied from interface:ISparseVectorReturns the non-sparse elements as a compacted vector. May or may not be a view.- Specified by:
nonSparseValuesin interfaceISparseVector- Returns:
-
nonSparseIndex
public abstract Index nonSparseIndex()
Description copied from class:AVectorReturns an Index indicating which elements of this vector are defined as non-sparse. A sparse index must be zero. A non-sparse element may be zero, but is typically expected be non-zero.- Specified by:
nonSparseIndexin interfaceISparseVector- Overrides:
nonSparseIndexin classAVector- Returns:
-
visitNonZero
public double visitNonZero(IndexedElementVisitor elementVisitor)
Description copied from class:AVectorVisits all non-zero elements of this vector. Visitor may return a non-zero value to terminate early, which will return the given value. Returns 0.0 otherwise.- Overrides:
visitNonZeroin classASizedVector
-
includesIndex
public abstract boolean includesIndex(int i)
Returns true iff the sparse vector contains the index i- Parameters:
i-- Returns:
-
roundToZero
public ASparseVector roundToZero(double precision)
Returns a vector after replacing all elements with absolute values less-than-or-equal to precision with zeros. May return either this vector or a new vector. If this vector is return, it may have been mutated.- Parameters:
precision-- Returns:
-
copyTo
public void copyTo(int offset, double[] destData, int destOffset, int length)Description copied from class:AVectorCopies a subset of this vector to a specified destination array offset
-
copyTo
public void copyTo(int offset, double[] destData, int destOffset, int length, int stride)Description copied from class:AVectorCopies a subset of this vector to a specified destination array offset using the given stride. Unsafe operation: performs no bounds checking
-
isZero
public boolean isZero()
Description copied from class:AVectorReturns true if this vector is a zero vector (all components zero)
-
isView
public boolean isView()
Description copied from class:AVectorReturns true if this vector is of a view type that references other vectors / data.
-
reduce
public double reduce(Op2 op, double init)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the initial/previous result at each step. Returns the final result.
-
reduce
public double reduce(Op2 op)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the previous result at each step. Returns the final result.
-
reduceSlices
public final AVector reduceSlices(Op2 op, double init)
Description copied from interface:INDArrayReduces each slice of the array by the given binary operator. Results are returned in a vector with one element for each slice. Uses the specified initial value for reduction of each slice.- Specified by:
reduceSlicesin interfaceINDArray- Overrides:
reduceSlicesin classAVector
-
distanceSquared
public double distanceSquared(AVector v)
Description copied from class:AVectorReturns the squared Euclidean distance to another vector.- Overrides:
distanceSquaredin classAVector- Returns:
-
dotProduct
public abstract double dotProduct(AVector v)
Description copied from class:AVectorReturns the dot product of this vector with another vector The vectors must have the same length: if not the result is undefined- Overrides:
dotProductin classAVector- Returns:
-
dotProduct
public final double dotProduct(ADenseArrayVector v)
Description copied from class:AVectorReturns the dot product of this vector with a target ADenseArrayVector.- Overrides:
dotProductin classAVector- Returns:
-
innerProduct
public AVector innerProduct(AMatrix m)
Description copied from class:AVectorComputes the inner product of this vector with a matrix- Overrides:
innerProductin classAVector- Returns:
- a vector representing the inner product
-
isSparse
public final boolean isSparse()
Description copied from interface:INDArrayReturns true if the array is in a sparse format- Specified by:
isSparsein interfaceINDArray- Overrides:
isSparsein classAbstractArray<java.lang.Double>
-
add
public void add(AVector v)
Description copied from class:AVectorAdds another vector to this one
-
addMultiple
public void addMultiple(AVector src, double factor)
Description copied from class:AVectorAdds a scaled multiple of another vector to this vector- Overrides:
addMultiplein classAVector
-
add
public abstract void add(ASparseVector v)
-
getSlices
public java.util.List<java.lang.Double> getSlices()
Description copied from interface:INDArrayReturns a list of all major slices of this array. Returns a list of Double values if a 1-dimensional array is sliced, otherwise a list of INDArray instances
-
elementProduct
public double elementProduct()
Description copied from interface:INDArrayReturns the product of all elements in the array.- Specified by:
elementProductin interfaceINDArray- Overrides:
elementProductin classAVector- Returns:
-
sparse
public ASparseVector sparse()
Description copied from interface:INDArrayCoerces this INDArray to a sparse format, without changing its element values. May return the same INDArray if already sparse. May also mutate the internal structure of the original NDArray, or create a view over parts of the original INDArray. You should take a defensive copy of the original NDArray if any of this concerns you. The returned sparse array may not be fully mutable in all elements.
-
clone
public AVector clone()
Description copied from class:AVectorClones the vector, creating a new mutable copy of all data. The clone is: - not guaranteed to be of the same type. - guaranteed to be fully mutable - guaranteed not to contain a reference (i.e. is a full deep copy)
-
equals
public boolean equals(ASparseVector v)
-
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 classAVector
-
nonZeroCount
public long nonZeroCount()
Description copied from interface:INDArrayReturns the number of non-zero elements in the array.- Specified by:
nonZeroCountin interfaceINDArray- Overrides:
nonZeroCountin classAVector
-
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<java.lang.Double>- Returns:
-
equals
public boolean equals(AVector v)
Description copied from class:AbstractArrayReturns true if this array is exactly equal to a vector.
-
hasUncountable
public boolean hasUncountable()
Description copied from class:AbstractArrayReturns true if any element is this array is NaN or infinite- Specified by:
hasUncountablein interfaceINDArray- Overrides:
hasUncountablein classAVector- Returns:
- True if any element is this array is NaN or infinite, false otherwise
-
elementPowSum
public double elementPowSum(double p)
Returns the sum of all the elements raised to a specified power- Specified by:
elementPowSumin interfaceINDArray- Overrides:
elementPowSumin classAVector- 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 classAVector- Returns:
-
elementSum
public double elementSum()
Description copied from class:AVectorReturns the sum of all elements in a vector- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classAVector
-
elementSquaredSum
public double elementSquaredSum()
Description copied from interface:INDArrayReturns the sum of squared elements in this array.- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classAVector
-
distanceL1
public double distanceL1(AVector v)
Description copied from class:AVectorReturns the distance from this vector to another vector according to the L1 (Taxicab) norm.- Overrides:
distanceL1in classAVector- Returns:
-
distanceLinf
public double distanceLinf(AVector v)
Description copied from class:AVectorReturns the distance from this vector to another vector according to the Linf norm.- Overrides:
distanceLinfin classAVector- Returns:
-
toSparseIndexedVector
public SparseIndexedVector toSparseIndexedVector()
Description copied from interface:ISparseVectorCoerces this vector to a SparseIndexedVector. May return this vector if already a SparseIndexedVector- Specified by:
toSparseIndexedVectorin interfaceISparseVector- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG