Class OpenMapRealVector
- java.lang.Object
-
- org.apache.commons.math.linear.AbstractRealVector
-
- org.apache.commons.math.linear.OpenMapRealVector
-
- All Implemented Interfaces:
java.io.Serializable,RealVector,SparseRealVector
public class OpenMapRealVector extends AbstractRealVector implements SparseRealVector, java.io.Serializable
This class implements theRealVectorinterface with aOpenIntToDoubleHashMapbacking store.- Since:
- 2.0
- Version:
- $Revision: 1073262 $ $Date: 2011-02-22 10:02:25 +0100 (mar. 22 févr. 2011) $
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classOpenMapRealVector.OpenMapEntryImplementation ofEntryoptimized for OpenMap.protected classOpenMapRealVector.OpenMapSparseIteratorIterator class to do iteration over just the non-zero elements.-
Nested classes/interfaces inherited from class org.apache.commons.math.linear.AbstractRealVector
AbstractRealVector.EntryImpl, AbstractRealVector.SparseEntryIterator
-
Nested classes/interfaces inherited from interface org.apache.commons.math.linear.RealVector
RealVector.Entry
-
-
Field Summary
Fields Modifier and Type Field Description static doubleDEFAULT_ZERO_TOLERANCEDefault Tolerance for having a value considered zero.
-
Constructor Summary
Constructors Modifier Constructor Description OpenMapRealVector()Build a 0-length vector.OpenMapRealVector(double[] values)Create from a double array.OpenMapRealVector(double[] values, double epsilon)Create from a double array, specifying zero tolerance.OpenMapRealVector(int dimension)Construct a (dimension)-length vector of zeros.OpenMapRealVector(int dimension, double epsilon)Construct a (dimension)-length vector of zeros, specifying zero tolerance.OpenMapRealVector(int dimension, int expectedSize)Build a vector with known the sparseness (for advanced use only).OpenMapRealVector(int dimension, int expectedSize, double epsilon)Build a vector with known the sparseness and zero tolerance setting (for advanced use only).OpenMapRealVector(java.lang.Double[] values)Create from a Double array.OpenMapRealVector(java.lang.Double[] values, double epsilon)Create from a Double array.OpenMapRealVector(OpenMapRealVector v)Copy constructor.protectedOpenMapRealVector(OpenMapRealVector v, int resize)Build a resized vector, for use with append.OpenMapRealVector(RealVector v)Generic copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description OpenMapRealVectoradd(OpenMapRealVector v)Optimized method to add two OpenMapRealVectors.RealVectoradd(RealVector v)Compute the sum of this vector andv.OpenMapRealVectorappend(double d)Construct a vector by appending a double to this vector.OpenMapRealVectorappend(double[] a)Construct a vector by appending a double array to this vector.OpenMapRealVectorappend(OpenMapRealVector v)Optimized method to append a OpenMapRealVector.OpenMapRealVectorappend(RealVector v)Construct a vector by appending a vector to this vector.OpenMapRealVectorcopy()Returns a (deep) copy of this vector.doubledotProduct(OpenMapRealVector v)Optimized method to compute the dot product with an OpenMapRealVector.doubledotProduct(RealVector v)Compute the dot product.OpenMapRealVectorebeDivide(double[] v)Element-by-element division.OpenMapRealVectorebeDivide(RealVector v)Element-by-element division.OpenMapRealVectorebeMultiply(double[] v)Element-by-element multiplication.OpenMapRealVectorebeMultiply(RealVector v)Element-by-element multiplication.booleanequals(java.lang.Object obj)Implementation Note: This performs an exact comparison, and as a result it is possible fora.subtract(b} to be the zero vector, whilea.equals(b) == false.double[]getData()Returns vector entries as a double array.intgetDimension()Returns the size of the vector.doublegetDistance(double[] v)Distance between two vectors.doublegetDistance(OpenMapRealVector v)Optimized method to compute distance.doublegetDistance(RealVector v)Distance between two vectors.doublegetEntry(int index)Returns the entry in the specified index.doublegetL1Distance(double[] v)Distance between two vectors.doublegetL1Distance(OpenMapRealVector v)Distance between two vectors.doublegetL1Distance(RealVector v)Distance between two vectors.doublegetLInfDistance(double[] v)Distance between two vectors.doublegetLInfDistance(RealVector v)Distance between two vectors.doublegetSparcity()Deprecated.as of 2.2 replaced by the correctly spelledgetSparsity()doublegetSparsity()OpenMapRealVectorgetSubVector(int index, int n)Get a subvector from consecutive elements.inthashCode()protected booleanisDefaultValue(double value)Determine if this value is within epsilon of zero.booleanisInfinite()Check whether any coordinate of this vector is infinite and none areNaN.booleanisNaN()Check whether any coordinate of this vector isNaN.OpenMapRealVectormapAdd(double d)Add a value to each entry.OpenMapRealVectormapAddToSelf(double d)Add a value to each entry.RealMatrixouterProduct(double[] v)Compute the outer product.OpenMapRealVectorprojection(double[] v)Find the orthogonal projection of this vector onto another vector.RealVectorprojection(RealVector v)Find the orthogonal projection of this vector onto another vector.voidset(double value)Set all elements to a single value.voidsetEntry(int index, double value)Set a single element.voidsetSubVector(int index, double[] v)Set a set of consecutive elements.voidsetSubVector(int index, RealVector v)Set a set of consecutive elements.java.util.Iterator<RealVector.Entry>sparseIterator()Specialized implementations may choose to not iterate over all dimensions, either because those values are unset, or are equal to defaultValue(), or are small enough to be ignored for the purposes of iteration.OpenMapRealVectorsubtract(double[] v)Subtractvfrom this vector.OpenMapRealVectorsubtract(OpenMapRealVector v)Optimized method to subtract OpenMapRealVectors.OpenMapRealVectorsubtract(RealVector v)Subtractvfrom this vector.double[]toArray()Convert the vector to a double array.voidunitize()Converts this vector into a unit vector.OpenMapRealVectorunitVector()Creates a unit vector pointing in the direction of this vector.-
Methods inherited from class org.apache.commons.math.linear.AbstractRealVector
add, checkIndex, checkVectorDimensions, checkVectorDimensions, dotProduct, getL1Norm, getLInfNorm, getMaxIndex, getMaxValue, getMinIndex, getMinValue, getNorm, iterator, map, mapAbs, mapAbsToSelf, mapAcos, mapAcosToSelf, mapAsin, mapAsinToSelf, mapAtan, mapAtanToSelf, mapCbrt, mapCbrtToSelf, mapCeil, mapCeilToSelf, mapCos, mapCosh, mapCoshToSelf, mapCosToSelf, mapDivide, mapDivideToSelf, mapExp, mapExpm1, mapExpm1ToSelf, mapExpToSelf, mapFloor, mapFloorToSelf, mapInv, mapInvToSelf, mapLog, mapLog10, mapLog10ToSelf, mapLog1p, mapLog1pToSelf, mapLogToSelf, mapMultiply, mapMultiplyToSelf, mapPow, mapPowToSelf, mapRint, mapRintToSelf, mapSignum, mapSignumToSelf, mapSin, mapSinh, mapSinhToSelf, mapSinToSelf, mapSqrt, mapSqrtToSelf, mapSubtract, mapSubtractToSelf, mapTan, mapTanh, mapTanhToSelf, mapTanToSelf, mapToSelf, mapUlp, mapUlpToSelf, outerProduct
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.math.linear.RealVector
add, dotProduct, getL1Norm, getLInfNorm, getNorm, iterator, map, mapAbs, mapAbsToSelf, mapAcos, mapAcosToSelf, mapAsin, mapAsinToSelf, mapAtan, mapAtanToSelf, mapCbrt, mapCbrtToSelf, mapCeil, mapCeilToSelf, mapCos, mapCosh, mapCoshToSelf, mapCosToSelf, mapDivide, mapDivideToSelf, mapExp, mapExpm1, mapExpm1ToSelf, mapExpToSelf, mapFloor, mapFloorToSelf, mapInv, mapInvToSelf, mapLog, mapLog10, mapLog10ToSelf, mapLog1p, mapLog1pToSelf, mapLogToSelf, mapMultiply, mapMultiplyToSelf, mapPow, mapPowToSelf, mapRint, mapRintToSelf, mapSignum, mapSignumToSelf, mapSin, mapSinh, mapSinhToSelf, mapSinToSelf, mapSqrt, mapSqrtToSelf, mapSubtract, mapSubtractToSelf, mapTan, mapTanh, mapTanhToSelf, mapTanToSelf, mapToSelf, mapUlp, mapUlpToSelf, outerProduct
-
-
-
-
Field Detail
-
DEFAULT_ZERO_TOLERANCE
public static final double DEFAULT_ZERO_TOLERANCE
Default Tolerance for having a value considered zero.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OpenMapRealVector
public OpenMapRealVector()
Build a 0-length vector.Zero-length vectors may be used to initialized construction of vectors by data gathering. We start with zero-length and use either the
OpenMapRealVector(OpenMapRealVector, int)constructor or one of theappendmethod (append(double),append(double[]),append(RealVector)) to gather data into this vector.
-
OpenMapRealVector
public OpenMapRealVector(int dimension)
Construct a (dimension)-length vector of zeros.- Parameters:
dimension- size of the vector
-
OpenMapRealVector
public OpenMapRealVector(int dimension, double epsilon)Construct a (dimension)-length vector of zeros, specifying zero tolerance.- Parameters:
dimension- Size of the vectorepsilon- The tolerance for having a value considered zero
-
OpenMapRealVector
protected OpenMapRealVector(OpenMapRealVector v, int resize)
Build a resized vector, for use with append.- Parameters:
v- The original vectorresize- The amount to resize it
-
OpenMapRealVector
public OpenMapRealVector(int dimension, int expectedSize)Build a vector with known the sparseness (for advanced use only).- Parameters:
dimension- The size of the vectorexpectedSize- The expected number of non-zero entries
-
OpenMapRealVector
public OpenMapRealVector(int dimension, int expectedSize, double epsilon)Build a vector with known the sparseness and zero tolerance setting (for advanced use only).- Parameters:
dimension- The size of the vectorexpectedSize- The expected number of non-zero entriesepsilon- The tolerance for having a value considered zero
-
OpenMapRealVector
public OpenMapRealVector(double[] values)
Create from a double array. Only non-zero entries will be stored- Parameters:
values- The set of values to create from
-
OpenMapRealVector
public OpenMapRealVector(double[] values, double epsilon)Create from a double array, specifying zero tolerance. Only non-zero entries will be stored- Parameters:
values- The set of values to create fromepsilon- The tolerance for having a value considered zero
-
OpenMapRealVector
public OpenMapRealVector(java.lang.Double[] values)
Create from a Double array. Only non-zero entries will be stored- Parameters:
values- The set of values to create from
-
OpenMapRealVector
public OpenMapRealVector(java.lang.Double[] values, double epsilon)Create from a Double array. Only non-zero entries will be stored- Parameters:
values- The set of values to create fromepsilon- The tolerance for having a value considered zero
-
OpenMapRealVector
public OpenMapRealVector(OpenMapRealVector v)
Copy constructor.- Parameters:
v- The instance to copy from
-
OpenMapRealVector
public OpenMapRealVector(RealVector v)
Generic copy constructor.- Parameters:
v- The instance to copy from
-
-
Method Detail
-
isDefaultValue
protected boolean isDefaultValue(double value)
Determine if this value is within epsilon of zero.- Parameters:
value- The value to test- Returns:
trueif this value is within epsilon to zero,falseotherwise- Since:
- 2.1
-
add
public RealVector add(RealVector v) throws java.lang.IllegalArgumentException
Compute the sum of this vector andv.- Specified by:
addin interfaceRealVector- Overrides:
addin classAbstractRealVector- Parameters:
v- Vector to be added.- Returns:
this+v.- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
add
public OpenMapRealVector add(OpenMapRealVector v) throws java.lang.IllegalArgumentException
Optimized method to add two OpenMapRealVectors. Copies the larger vector, iterates over the smaller.- Parameters:
v- Vector to add with- Returns:
- The sum of
thiswithv - Throws:
java.lang.IllegalArgumentException- If the dimensions don't match
-
append
public OpenMapRealVector append(OpenMapRealVector v)
Optimized method to append a OpenMapRealVector.- Parameters:
v- vector to append- Returns:
- The result of appending
vto self
-
append
public OpenMapRealVector append(RealVector v)
Construct a vector by appending a vector to this vector.- Specified by:
appendin interfaceRealVector- Parameters:
v- vector to append to this one.- Returns:
- a new vector
-
append
public OpenMapRealVector append(double d)
Construct a vector by appending a double to this vector.- Specified by:
appendin interfaceRealVector- Parameters:
d- double to append.- Returns:
- a new vector
-
append
public OpenMapRealVector append(double[] a)
Construct a vector by appending a double array to this vector.- Specified by:
appendin interfaceRealVector- Parameters:
a- double array to append.- Returns:
- a new vector
-
copy
public OpenMapRealVector copy()
Returns a (deep) copy of this vector.- Specified by:
copyin interfaceRealVector- Specified by:
copyin classAbstractRealVector- Returns:
- a vector copy.
- Since:
- 2.1
-
dotProduct
public double dotProduct(OpenMapRealVector v) throws java.lang.IllegalArgumentException
Optimized method to compute the dot product with an OpenMapRealVector. Iterates over the smaller of the two.- Parameters:
v- The vector to compute the dot product with- Returns:
- The dot product of
thisandv - Throws:
java.lang.IllegalArgumentException- If the dimensions don't match
-
dotProduct
public double dotProduct(RealVector v) throws java.lang.IllegalArgumentException
Compute the dot product.- Specified by:
dotProductin interfaceRealVector- Overrides:
dotProductin classAbstractRealVector- Parameters:
v- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
ebeDivide
public OpenMapRealVector ebeDivide(RealVector v) throws java.lang.IllegalArgumentException
Element-by-element division.- Specified by:
ebeDividein interfaceRealVector- Parameters:
v- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
ebeDivide
public OpenMapRealVector ebeDivide(double[] v) throws java.lang.IllegalArgumentException
Element-by-element division.- Specified by:
ebeDividein interfaceRealVector- Overrides:
ebeDividein classAbstractRealVector- Parameters:
v- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
ebeMultiply
public OpenMapRealVector ebeMultiply(RealVector v) throws java.lang.IllegalArgumentException
Element-by-element multiplication.- Specified by:
ebeMultiplyin interfaceRealVector- Parameters:
v- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
ebeMultiply
public OpenMapRealVector ebeMultiply(double[] v) throws java.lang.IllegalArgumentException
Element-by-element multiplication.- Specified by:
ebeMultiplyin interfaceRealVector- Overrides:
ebeMultiplyin classAbstractRealVector- Parameters:
v- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
getSubVector
public OpenMapRealVector getSubVector(int index, int n) throws MatrixIndexException
Get a subvector from consecutive elements.- Specified by:
getSubVectorin interfaceRealVector- Parameters:
index- index of first element.n- number of elements to be retrieved.- Returns:
- a vector containing n elements.
- Throws:
MatrixIndexException
-
getData
public double[] getData()
Returns vector entries as a double array.- Specified by:
getDatain interfaceRealVector- Overrides:
getDatain classAbstractRealVector- Returns:
- double array of entries
-
getDimension
public int getDimension()
Returns the size of the vector.- Specified by:
getDimensionin interfaceRealVector- Returns:
- size
-
getDistance
public double getDistance(OpenMapRealVector v) throws java.lang.IllegalArgumentException
Optimized method to compute distance.- Parameters:
v- The vector to compute distance to- Returns:
- The distance from
thisandv - Throws:
java.lang.IllegalArgumentException- If the dimensions don't match
-
getDistance
public double getDistance(RealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
- Specified by:
getDistancein interfaceRealVector- Overrides:
getDistancein classAbstractRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException- See Also:
RealVector.getL1Distance(RealVector),RealVector.getLInfDistance(RealVector),RealVector.getNorm()
-
getDistance
public double getDistance(double[] v) throws java.lang.IllegalArgumentExceptionDistance between two vectors.This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
- Specified by:
getDistancein interfaceRealVector- Overrides:
getDistancein classAbstractRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException- See Also:
RealVector.getL1Distance(double[]),RealVector.getLInfDistance(double[]),RealVector.getNorm()
-
getEntry
public double getEntry(int index) throws MatrixIndexExceptionReturns the entry in the specified index.- Specified by:
getEntryin interfaceRealVector- Parameters:
index- Index location of entry to be fetched.- Returns:
- the vector entry at
index. - Throws:
MatrixIndexException- See Also:
RealVector.setEntry(int, double)
-
getL1Distance
public double getL1Distance(OpenMapRealVector v)
Distance between two vectors.This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
-
getL1Distance
public double getL1Distance(RealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
- Specified by:
getL1Distancein interfaceRealVector- Overrides:
getL1Distancein classAbstractRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException- See Also:
RealVector.getDistance(RealVector),RealVector.getLInfDistance(RealVector),RealVector.getL1Norm()
-
getL1Distance
public double getL1Distance(double[] v) throws java.lang.IllegalArgumentExceptionDistance between two vectors.This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
- Specified by:
getL1Distancein interfaceRealVector- Overrides:
getL1Distancein classAbstractRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException- See Also:
RealVector.getDistance(double[]),RealVector.getLInfDistance(double[]),RealVector.getL1Norm()
-
getLInfDistance
public double getLInfDistance(RealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
- Specified by:
getLInfDistancein interfaceRealVector- Overrides:
getLInfDistancein classAbstractRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException- See Also:
RealVector.getDistance(RealVector),RealVector.getL1Distance(RealVector),RealVector.getLInfNorm()
-
getLInfDistance
public double getLInfDistance(double[] v) throws java.lang.IllegalArgumentExceptionDistance between two vectors.This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
- Specified by:
getLInfDistancein interfaceRealVector- Overrides:
getLInfDistancein classAbstractRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException- See Also:
RealVector.getDistance(double[]),RealVector.getL1Distance(double[]),RealVector.getLInfNorm()
-
isInfinite
public boolean isInfinite()
Check whether any coordinate of this vector is infinite and none areNaN.- Specified by:
isInfinitein interfaceRealVector- Returns:
trueif any coordinate of this vector is infinite and none areNaN,falseotherwise.
-
isNaN
public boolean isNaN()
Check whether any coordinate of this vector isNaN.- Specified by:
isNaNin interfaceRealVector- Returns:
trueif any coordinate of this vector isNaN,falseotherwise.
-
mapAdd
public OpenMapRealVector mapAdd(double d)
Add a value to each entry.- Specified by:
mapAddin interfaceRealVector- Overrides:
mapAddin classAbstractRealVector- Parameters:
d- Value to be added to each entry.- Returns:
this+d.
-
mapAddToSelf
public OpenMapRealVector mapAddToSelf(double d)
Add a value to each entry. The instance is changed in-place.- Specified by:
mapAddToSelfin interfaceRealVector- Overrides:
mapAddToSelfin classAbstractRealVector- Parameters:
d- Value to be added to each entry.- Returns:
this.
-
outerProduct
public RealMatrix outerProduct(double[] v) throws java.lang.IllegalArgumentException
Compute the outer product.- Specified by:
outerProductin interfaceRealVector- Overrides:
outerProductin classAbstractRealVector- Parameters:
v- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
projection
public RealVector projection(RealVector v) throws java.lang.IllegalArgumentException
Find the orthogonal projection of this vector onto another vector.- Specified by:
projectionin interfaceRealVector- Parameters:
v- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
projection
public OpenMapRealVector projection(double[] v) throws java.lang.IllegalArgumentException
Find the orthogonal projection of this vector onto another vector.- Specified by:
projectionin interfaceRealVector- Overrides:
projectionin classAbstractRealVector- Parameters:
v- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
setEntry
public void setEntry(int index, double value) throws MatrixIndexExceptionSet a single element.- Specified by:
setEntryin interfaceRealVector- Parameters:
index- element index.value- new value for the element.- Throws:
MatrixIndexException- See Also:
RealVector.getEntry(int)
-
setSubVector
public void setSubVector(int index, RealVector v) throws MatrixIndexExceptionSet a set of consecutive elements.- Specified by:
setSubVectorin interfaceRealVector- Overrides:
setSubVectorin classAbstractRealVector- Parameters:
index- index of first element to be set.v- vector containing the values to set.- Throws:
MatrixIndexException- See Also:
RealVector.setSubVector(int, double[])
-
setSubVector
public void setSubVector(int index, double[] v) throws MatrixIndexExceptionSet a set of consecutive elements.- Specified by:
setSubVectorin interfaceRealVector- Overrides:
setSubVectorin classAbstractRealVector- Parameters:
index- index of first element to be set.v- vector containing the values to set.- Throws:
MatrixIndexException- See Also:
RealVector.setSubVector(int, RealVector)
-
set
public void set(double value)
Set all elements to a single value.- Specified by:
setin interfaceRealVector- Overrides:
setin classAbstractRealVector- Parameters:
value- single value to set for all elements
-
subtract
public OpenMapRealVector subtract(OpenMapRealVector v) throws java.lang.IllegalArgumentException
Optimized method to subtract OpenMapRealVectors.- Parameters:
v- The vector to subtract fromthis- Returns:
- The difference of
thisandv - Throws:
java.lang.IllegalArgumentException- If the dimensions don't match
-
subtract
public OpenMapRealVector subtract(RealVector v) throws java.lang.IllegalArgumentException
Subtractvfrom this vector.- Specified by:
subtractin interfaceRealVector- Overrides:
subtractin classAbstractRealVector- Parameters:
v- Vector to be subtracted.- Returns:
this-v.- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
subtract
public OpenMapRealVector subtract(double[] v) throws java.lang.IllegalArgumentException
Subtractvfrom this vector.- Specified by:
subtractin interfaceRealVector- Overrides:
subtractin classAbstractRealVector- Parameters:
v- Vector to be subtracted.- Returns:
this-v.- Throws:
DimensionMismatchException- ifvis not the same size as this vector.java.lang.IllegalArgumentException
-
unitVector
public OpenMapRealVector unitVector()
Creates a unit vector pointing in the direction of this vector.The instance is not changed by this method.
- Specified by:
unitVectorin interfaceRealVector- Overrides:
unitVectorin classAbstractRealVector- Returns:
- a unit vector pointing in direction of this vector
-
unitize
public void unitize()
Converts this vector into a unit vector.The instance itself is changed by this method.
- Specified by:
unitizein interfaceRealVector- Overrides:
unitizein classAbstractRealVector
-
toArray
public double[] toArray()
Convert the vector to a double array.The array is independent from vector data, it's elements are copied.
- Specified by:
toArrayin interfaceRealVector- Overrides:
toArrayin classAbstractRealVector- Returns:
- array containing a copy of vector elements
-
hashCode
public int hashCode()
Implementation Note: This works on exact values, and as a result it is possible for
a.subtract(b)to be the zero vector, whilea.hashCode() != b.hashCode().- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Implementation Note: This performs an exact comparison, and as a result it is possible for
a.subtract(b} to be the zero vector, whilea.equals(b) == false.- Overrides:
equalsin classjava.lang.Object
-
getSparcity
@Deprecated public double getSparcity()
Deprecated.as of 2.2 replaced by the correctly spelledgetSparsity()- Returns:
- the percentage of none zero elements as a decimal percent.
-
getSparsity
public double getSparsity()
- Returns:
- the percentage of none zero elements as a decimal percent.
- Since:
- 2.2
-
sparseIterator
public java.util.Iterator<RealVector.Entry> sparseIterator()
Specialized implementations may choose to not iterate over all dimensions, either because those values are unset, or are equal to defaultValue(), or are small enough to be ignored for the purposes of iteration. No guarantees are made about order of iteration. In dense implementations, this method will often delegate toRealVector.iterator().- Specified by:
sparseIteratorin interfaceRealVector- Overrides:
sparseIteratorin classAbstractRealVector- Returns:
- a sparse iterator
-
-