mikera.vectorz.impl
Class SparseHashedVector
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<java.lang.Double>
-
- mikera.vectorz.AVector
-
- mikera.vectorz.impl.ASizedVector
-
- mikera.vectorz.impl.ASparseVector
-
- mikera.vectorz.impl.SparseHashedVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, INDArray, ISparse, ISparseVector, IVector
public class SparseHashedVector extends ASparseVector
Hashed sparse vector, intended for large vectors with very few randomly positioned non-zero elements. Maintains hash elements for non-zero values only. This is useful (and maybe better than SparseIndexedVector) if random individual elements are likely to be changed, accessed or set back to zero on a frequent basis Mutable in all elements, but performance will be reduced if density is high. In general, if density is more than about 1% then a dense Vector is likely to be better.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(ASparseVector v)voidaddAt(int i, double value)Adds a value to a specific element of the vector This function does not perform bounds checking, i.e.voidaddMultipleToArray(double factor, int offset, double[] array, int arrayOffset, int length)Adds a multiple of a subvector of this vector into a double array at the specified offsetvoidaddProductToArray(double factor, int offset, ADenseArrayVector other, int otherOffset, double[] array, int arrayOffset, int length)Adds the scaled elementwise product of this vector and another vector to the destimation arrayvoidaddProductToArray(double factor, int offset, AVector other, int otherOffset, double[] array, int arrayOffset, int length)voidaddToArray(double[] dest, int offset, int stride)Adds this vector to a double[] array, using the specified offset and stride into the destination arrayvoidaddToArray(int offset, double[] array, int arrayOffset, int length)Adds a subvector of this vector into a double array at the specified offsetSparseIndexedVectorclone()Clones the vector, creating a new mutable copy of all data.voidcopySparseValuesTo(double[] array, int offset)voidcopyTo(AVector v, int offset)Copies a the contents of a vector to a vector at the specified offsetstatic SparseHashedVectorcreate(AVector v)Creates a SparseHashedVector with the specified valuesstatic SparseHashedVectorcreate(int length, Index index, Vector values)Create a SparseHashedVector with specified non-zero indexes and values.static AVectorcreateFromRow(AMatrix m, int row)Creates a SparseIndexedVector from a row of an existing matrixstatic SparseHashedVectorcreateLength(int length)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 undefineddoubledotProduct(double[] data, int offset)Fast dot product with a double[] array.doubledotProduct(double[] data, int offset, int stride)Fast dot product with a double[] array and a stride.doubleelementMax()Returns the maximum element value in this array.doubleelementMin()Returns the maximum element value in this array.doubleelementSquaredSum()Returns the sum of squared elements in this array.doubleelementSum()Returns the sum of all elements in a vectorbooleanequalsArray(double[] data, int offset)Returns true if this vector exactly matches the elements in double[] array, starting from the specified offsetSparseHashedVectorexactClone()Returns an exact clone of this vector, i.e.doubleget(int i)Returns the double value at the specified position in a 1D vectorvoidgetElements(double[] array, int offset)Copies all elements of this array a double array at the specified offsetbooleanincludesIndex(int i)Returns true iff the sparse vector contains the index ibooleanisElementConstrained()Returns true if this array has some constraints on element valuesbooleanisFullyMutable()Returns true if this vector is fully mutable, i.e.booleanisMutable()Returns true if this vector is mutable.booleanisZero()Returns true if this vector is a zero vector (all components zero)doublemaxAbsElement()Returns the maximum absolute element value of a vectorintmaxAbsElementIndex()Returns the index of the maximum absolute element of a vectorintmaxElementIndex()Returns the index of the maximum element of a vectorintminElementIndex()Returns the index of the minimum element of a vectorvoidmultiply(double d)Multiplies the vector by a constant factorintnonSparseElementCount()Returns the number of non-sparse elements in the sparse vector.IndexnonSparseIndex()Returns an Index indicating which elements of this vector are defined as non-sparse.VectornonSparseValues()Returns the non-sparse elements as a compacted vector.longnonZeroCount()Returns the number of non-zero elements in the array.int[]nonZeroIndices()Return an int array specifying the positions in this vector which are non-zerovoidset(AVector v)Sets the vector to equal the value of another vectorvoidset(int i, double value)Sets a value at a given position in a mutable 1D arrayvoidset(SparseHashedVector v)SparseIndexedVectorsparseClone()Clones the vector into a sparse mutable formatdoubleunsafeGet(int i)Like get, but performs no bounds checking.voidunsafeSet(int i, double value)Like set, but performs no bounds checking.voidvalidate()Validates the internal data structure of the INDArray.-
Methods inherited from class mikera.vectorz.impl.ASparseVector
add, addMultiple, copyTo, copyTo, density, distanceL1, distanceLinf, distanceSquared, dotProduct, elementAbsPowSum, elementPowSum, elementProduct, equals, equals, getSlices, hasUncountable, innerProduct, isSparse, isView, reduce, reduce, reduceSlices, roundToZero, sparse, toDoubleArray, toSparseIndexedVector, visitNonZero
-
Methods inherited from class mikera.vectorz.impl.ASizedVector
checkIndex, checkLength, checkRange, elementCount, 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, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultipleCopy, addMultipleSparse, addMultipleSparse, addMultipleToArray, addPower, addPower, addProduct, addProduct, addProduct, addProductCopy, addProductCopy, addSparse, addSparse, addToArray, addWeighted, angle, applyOp, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, broadcast, broadcastLike, broadcastLike, broadcastLike, clamp, clampMax, clampMin, compareTo, compareTo, copy, copyTo, copyTo, crossProduct, crossProduct, dense, denseClone, dimensionality, distance, divide, divide, divide, divide, divideCopy, divideCopy, divideCopy, divideTo, dotProduct, elementIterator, elementMaxAbs, elementsEqual, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, fill, fillRange, get, get, get, get, get, getElement, getElements, getElements, getLongShape, getShape, getTranspose, getTransposeCopy, getTransposeView, hashCode, immutable, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, interpolate, isRangeZero, isSameShape, isUnitLengthVector, isUnitLengthVector, iterator, join, join, join, log, logistic, magnitude, magnitudeSquared, maxElement, minElement, multiply, multiply, multiply, multiply, multiplyCopy, multiplyCopy, multiplyCopy, multiplyTo, mutable, negate, negateCopy, 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, setApplyOp, setApplyOp, setApplyOp, setElements, setElements, setElements, setInnerProduct, setInnerProduct, setInnerProduct, setMultiple, setMultiple, setMultiple, setMultiple, setSparse, setSparse, setSparse, shiftCopy, signum, slice, slice, sliceValue, softmax, softmaxCopy, sqrtCopy, square, squareCopy, sub, sub, subArray, subAt, subCopy, subCopy, subMultiple, subVector, tanh, toDoubleBuffer, toList, toNormal, toSliceArray, toString, toStringFull, toVector, tryEfficientJoin
-
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, isSameShape, length, multiplyCopy, normalise, normaliseCopy, rotateCopy, rotateView, 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, elementMaxAbs, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, equals, equalsArray, exp, fill, get, get, get, get, get, get, get, get, getComponent, getComponents, getElement, getElements, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getSliceViews, getTranspose, getTransposeCopy, getTransposeView, immutable, innerProduct, innerProduct, innerProduct, innerProduct, isBoolean, isDense, isSameShape, join, join, log, 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, sqrt, square, squareCopy, sub, sub, subArray, subCopy, toDoubleBuffer, toSliceArray, toVector, withComponents
-
-
-
-
Method Detail
-
create
public static SparseHashedVector create(AVector v)
Creates a SparseHashedVector with the specified values
-
create
public static SparseHashedVector create(int length, Index index, Vector values)
Create a SparseHashedVector with specified non-zero indexes and values.
-
createLength
public static SparseHashedVector createLength(int length)
-
createFromRow
public static AVector createFromRow(AMatrix m, int row)
Creates a SparseIndexedVector from a row of an existing matrix
-
nonSparseElementCount
public int nonSparseElementCount()
Description copied from class:ASparseVectorReturns the number of non-sparse elements in the sparse vector. This will be greater or equal to the number of non-zero elements- Specified by:
nonSparseElementCountin classASparseVector- Returns:
-
isZero
public boolean isZero()
Description copied from class:AVectorReturns true if this vector is a zero vector (all components zero)- Specified by:
isZeroin interfaceINDArray- Overrides:
isZeroin classASparseVector
-
isElementConstrained
public boolean isElementConstrained()
Description copied from interface:INDArrayReturns true if this array has some constraints on element values- Specified by:
isElementConstrainedin interfaceINDArray- Overrides:
isElementConstrainedin classAVector
-
get
public double get(int i)
Description copied from interface:INDArrayReturns the double value at the specified position in a 1D vector
-
unsafeGet
public double unsafeGet(int i)
Description copied from class:AVectorLike get, but performs no bounds checking. Results are undefined if the index is out of range
-
isFullyMutable
public boolean isFullyMutable()
Description copied from class:AVectorReturns true if this vector is fully mutable, i.e. can contain any unconstrained double values- Specified by:
isFullyMutablein interfaceINDArray- Overrides:
isFullyMutablein classAVector
-
isMutable
public boolean isMutable()
Description copied from class:AVectorReturns true if this vector is mutable.
-
nonZeroCount
public long nonZeroCount()
Description copied from interface:INDArrayReturns the number of non-zero elements in the array.- Specified by:
nonZeroCountin interfaceINDArray- Overrides:
nonZeroCountin classASparseVector
-
multiply
public void multiply(double d)
Description copied from class:AVectorMultiplies the vector by a constant factor
-
dotProduct
public 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- Specified by:
dotProductin classASparseVector- Returns:
-
dotProduct
public double dotProduct(double[] data, int offset)Description copied from class:AVectorFast dot product with a double[] array. Performs no bounds checking. Likely to be faster than most other dot product operations- Specified by:
dotProductin classAVector
-
dotProduct
public double dotProduct(double[] data, int offset, int stride)Description copied from class:AVectorFast dot product with a double[] array and a stride. Performs no bounds checking. Likely to be faster than other dot product operations- Overrides:
dotProductin classAVector
-
addMultipleToArray
public void addMultipleToArray(double factor, int offset, double[] array, int arrayOffset, int length)Description copied from class:AVectorAdds a multiple of a subvector of this vector into a double array at the specified offset- Overrides:
addMultipleToArrayin classAVector
-
addToArray
public void addToArray(int offset, double[] array, int arrayOffset, int length)Description copied from class:AVectorAdds a subvector of this vector into a double array at the specified offset- Overrides:
addToArrayin classAVector
-
addToArray
public void addToArray(double[] dest, int offset, int stride)Description copied from class:AVectorAdds this vector to a double[] array, using the specified offset and stride into the destination array- Overrides:
addToArrayin classAVector
-
addProductToArray
public void addProductToArray(double factor, int offset, AVector other, int otherOffset, double[] array, int arrayOffset, int length)- Overrides:
addProductToArrayin classAVector
-
addProductToArray
public void addProductToArray(double factor, int offset, ADenseArrayVector other, int otherOffset, double[] array, int arrayOffset, int length)Description copied from class:AVectorAdds the scaled elementwise product of this vector and another vector to the destimation array- Overrides:
addProductToArrayin classAVector
-
getElements
public void getElements(double[] array, int offset)Description copied from interface:INDArrayCopies all elements of this array a double array at the specified offset- Specified by:
getElementsin interfaceINDArray- Overrides:
getElementsin classAVector
-
copySparseValuesTo
public void copySparseValuesTo(double[] array, int offset)
-
copyTo
public void copyTo(AVector v, int offset)
Description copied from class:AVectorCopies a the contents of a vector to a vector at the specified offset
-
set
public void set(int i, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 1D array
-
set
public void set(AVector v)
Description copied from class:AVectorSets the vector to equal the value of another vector
-
set
public void set(SparseHashedVector v)
-
unsafeSet
public void unsafeSet(int i, double value)Description copied from class:AVectorLike set, but performs no bounds checking. Results are undefined if the index is out of range
-
addAt
public void addAt(int i, double value)Description copied from class:AVectorAdds a value to a specific element of the vector This function does not perform bounds checking, i.e. is an unsafe operation
-
maxAbsElement
public double maxAbsElement()
Description copied from class:AVectorReturns the maximum absolute element value of a vector- Overrides:
maxAbsElementin classAVector- 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 classAVector
-
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 classAVector
-
maxElementIndex
public int maxElementIndex()
Description copied from class:AVectorReturns the index of the maximum element of a vector- Overrides:
maxElementIndexin classAVector- Returns:
-
maxAbsElementIndex
public int maxAbsElementIndex()
Description copied from class:AVectorReturns the index of the maximum absolute element of a vector- Overrides:
maxAbsElementIndexin classAVector- Returns:
-
minElementIndex
public int minElementIndex()
Description copied from class:AVectorReturns the index of the minimum element of a vector- Overrides:
minElementIndexin classAVector
-
elementSum
public double elementSum()
Description copied from class:AVectorReturns the sum of all elements in a vector- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classASparseVector
-
elementSquaredSum
public double elementSquaredSum()
Description copied from interface:INDArrayReturns the sum of squared elements in this array.- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classASparseVector
-
nonSparseValues
public Vector 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- Specified by:
nonSparseValuesin classASparseVector- Returns:
-
nonZeroIndices
public int[] nonZeroIndices()
Description copied from class:AVectorReturn an int array specifying the positions in this vector which are non-zero- Overrides:
nonZeroIndicesin classAVector- Returns:
-
nonSparseIndex
public 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- Specified by:
nonSparseIndexin classASparseVector- Returns:
-
includesIndex
public boolean includesIndex(int i)
Description copied from class:ASparseVectorReturns true iff the sparse vector contains the index i- Specified by:
includesIndexin classASparseVector- Returns:
-
add
public void add(ASparseVector v)
- Specified by:
addin classASparseVector
-
equalsArray
public boolean equalsArray(double[] data, int offset)Description copied from class:AVectorReturns true if this vector exactly matches the elements in double[] array, starting from the specified offset- Specified by:
equalsArrayin interfaceINDArray- Overrides:
equalsArrayin classASizedVector- Parameters:
data- Array of double element values to check for equalityoffset- Offset into the data array- Returns:
-
clone
public SparseIndexedVector 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)
-
exactClone
public SparseHashedVector exactClone()
Description copied from class:AVectorReturns an exact clone of this vector, i.e. of the same type- Specified by:
exactClonein interfaceINDArray- Specified by:
exactClonein classAVector- Returns:
- A clone of the original array
-
sparseClone
public SparseIndexedVector sparseClone()
Description copied from class:AVectorClones the vector into a sparse mutable format- Specified by:
sparseClonein interfaceINDArray- Overrides:
sparseClonein classAVector
-
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.
-
-
DMelt 3.0 © DataMelt by jWork.ORG