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 theRealVector
interface with aOpenIntToDoubleHashMap
backing store.- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.commons.math.linear.RealVector
RealVector.Entry
-
-
Field Summary
Fields Modifier and Type Field Description static double
DEFAULT_ZERO_TOLERANCE
Default Tolerance for having a value considered zero.
-
Constructor Summary
Constructors 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.OpenMapRealVector(RealVector v)
Generic copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description OpenMapRealVector
add(OpenMapRealVector v)
Optimized method to add two OpenMapRealVectors.RealVector
add(RealVector v)
Compute the sum of this vector andv
.OpenMapRealVector
append(double d)
Construct a vector by appending a double to this vector.OpenMapRealVector
append(double[] a)
Construct a vector by appending a double array to this vector.OpenMapRealVector
append(OpenMapRealVector v)
Optimized method to append a OpenMapRealVector.OpenMapRealVector
append(RealVector v)
Construct a vector by appending a vector to this vector.OpenMapRealVector
copy()
Returns a (deep) copy of this vector.double
dotProduct(OpenMapRealVector v)
Optimized method to compute the dot product with an OpenMapRealVector.double
dotProduct(RealVector v)
Compute the dot product.OpenMapRealVector
ebeDivide(double[] v)
Element-by-element division.OpenMapRealVector
ebeDivide(RealVector v)
Element-by-element division.OpenMapRealVector
ebeMultiply(double[] v)
Element-by-element multiplication.OpenMapRealVector
ebeMultiply(RealVector v)
Element-by-element multiplication.boolean
equals(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.int
getDimension()
Returns the size of the vector.double
getDistance(double[] v)
Distance between two vectors.double
getDistance(OpenMapRealVector v)
Optimized method to compute distance.double
getDistance(RealVector v)
Distance between two vectors.double
getEntry(int index)
Returns the entry in the specified index.double
getL1Distance(double[] v)
Distance between two vectors.double
getL1Distance(OpenMapRealVector v)
Distance between two vectors.double
getL1Distance(RealVector v)
Distance between two vectors.double
getLInfDistance(double[] v)
Distance between two vectors.double
getLInfDistance(RealVector v)
Distance between two vectors.double
getSparcity()
Deprecated.as of 2.2 replaced by the correctly spelledgetSparsity()
double
getSparsity()
OpenMapRealVector
getSubVector(int index, int n)
Get a subvector from consecutive elements.int
hashCode()
boolean
isInfinite()
Check whether any coordinate of this vector is infinite and none areNaN
.boolean
isNaN()
Check whether any coordinate of this vector isNaN
.OpenMapRealVector
mapAdd(double d)
Add a value to each entry.OpenMapRealVector
mapAddToSelf(double d)
Add a value to each entry.RealMatrix
outerProduct(double[] v)
Compute the outer product.OpenMapRealVector
projection(double[] v)
Find the orthogonal projection of this vector onto another vector.RealVector
projection(RealVector v)
Find the orthogonal projection of this vector onto another vector.void
set(double value)
Set all elements to a single value.void
setEntry(int index, double value)
Set a single element.void
setSubVector(int index, double[] v)
Set a set of consecutive elements.void
setSubVector(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.OpenMapRealVector
subtract(double[] v)
Subtractv
from this vector.OpenMapRealVector
subtract(OpenMapRealVector v)
Optimized method to subtract OpenMapRealVectors.OpenMapRealVector
subtract(RealVector v)
Subtractv
from this vector.double[]
toArray()
Convert the vector to a double array.void
unitize()
Converts this vector into a unit vector.OpenMapRealVector
unitVector()
Creates a unit vector pointing in the direction of this vector.-
Methods inherited from class org.apache.commons.math.linear.AbstractRealVector
add, 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
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 theappend
method (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
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
-
add
public RealVector add(RealVector v) throws java.lang.IllegalArgumentException
Compute the sum of this vector andv
.- Specified by:
add
in interfaceRealVector
- Overrides:
add
in classAbstractRealVector
- Parameters:
v
- Vector to be added.- Returns:
this
+v
.- Throws:
DimensionMismatchException
- ifv
is 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
this
withv
- 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
v
to self
-
append
public OpenMapRealVector append(RealVector v)
Construct a vector by appending a vector to this vector.- Specified by:
append
in 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:
append
in 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:
append
in interfaceRealVector
- Parameters:
a
- double array to append.- Returns:
- a new vector
-
copy
public OpenMapRealVector copy()
Returns a (deep) copy of this vector.- Specified by:
copy
in interfaceRealVector
- Specified by:
copy
in 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
this
andv
- 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:
dotProduct
in interfaceRealVector
- Overrides:
dotProduct
in classAbstractRealVector
- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
DimensionMismatchException
- ifv
is 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:
ebeDivide
in interfaceRealVector
- Parameters:
v
- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
DimensionMismatchException
- ifv
is 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:
ebeDivide
in interfaceRealVector
- Overrides:
ebeDivide
in classAbstractRealVector
- Parameters:
v
- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
DimensionMismatchException
- ifv
is 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:
ebeMultiply
in interfaceRealVector
- Parameters:
v
- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
DimensionMismatchException
- ifv
is 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:
ebeMultiply
in interfaceRealVector
- Overrides:
ebeMultiply
in classAbstractRealVector
- Parameters:
v
- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
DimensionMismatchException
- ifv
is 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:
getSubVector
in 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:
getData
in interfaceRealVector
- Overrides:
getData
in classAbstractRealVector
- Returns:
- double array of entries
-
getDimension
public int getDimension()
Returns the size of the vector.- Specified by:
getDimension
in 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
this
andv
- 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:
getDistance
in interfaceRealVector
- Overrides:
getDistance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is 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.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:
getDistance
in interfaceRealVector
- Overrides:
getDistance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is 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 MatrixIndexException
Returns the entry in the specified index.- Specified by:
getEntry
in 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:
getL1Distance
in interfaceRealVector
- Overrides:
getL1Distance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is 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.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:
getL1Distance
in interfaceRealVector
- Overrides:
getL1Distance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is 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:
getLInfDistance
in interfaceRealVector
- Overrides:
getLInfDistance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is 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.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:
getLInfDistance
in interfaceRealVector
- Overrides:
getLInfDistance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is 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:
isInfinite
in interfaceRealVector
- Returns:
true
if any coordinate of this vector is infinite and none areNaN
,false
otherwise.
-
isNaN
public boolean isNaN()
Check whether any coordinate of this vector isNaN
.- Specified by:
isNaN
in interfaceRealVector
- Returns:
true
if any coordinate of this vector isNaN
,false
otherwise.
-
mapAdd
public OpenMapRealVector mapAdd(double d)
Add a value to each entry.- Specified by:
mapAdd
in interfaceRealVector
- Overrides:
mapAdd
in 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:
mapAddToSelf
in interfaceRealVector
- Overrides:
mapAddToSelf
in 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:
outerProduct
in interfaceRealVector
- Overrides:
outerProduct
in classAbstractRealVector
- Parameters:
v
- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
DimensionMismatchException
- ifv
is 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:
projection
in interfaceRealVector
- Parameters:
v
- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
DimensionMismatchException
- ifv
is 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:
projection
in interfaceRealVector
- Overrides:
projection
in classAbstractRealVector
- Parameters:
v
- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
setEntry
public void setEntry(int index, double value) throws MatrixIndexException
Set a single element.- Specified by:
setEntry
in 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 MatrixIndexException
Set a set of consecutive elements.- Specified by:
setSubVector
in interfaceRealVector
- Overrides:
setSubVector
in 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 MatrixIndexException
Set a set of consecutive elements.- Specified by:
setSubVector
in interfaceRealVector
- Overrides:
setSubVector
in 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:
set
in interfaceRealVector
- Overrides:
set
in 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
this
andv
- Throws:
java.lang.IllegalArgumentException
- If the dimensions don't match
-
subtract
public OpenMapRealVector subtract(RealVector v) throws java.lang.IllegalArgumentException
Subtractv
from this vector.- Specified by:
subtract
in interfaceRealVector
- Overrides:
subtract
in classAbstractRealVector
- Parameters:
v
- Vector to be subtracted.- Returns:
this
-v
.- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
subtract
public OpenMapRealVector subtract(double[] v) throws java.lang.IllegalArgumentException
Subtractv
from this vector.- Specified by:
subtract
in interfaceRealVector
- Overrides:
subtract
in classAbstractRealVector
- Parameters:
v
- Vector to be subtracted.- Returns:
this
-v
.- Throws:
DimensionMismatchException
- ifv
is 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:
unitVector
in interfaceRealVector
- Overrides:
unitVector
in 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:
unitize
in interfaceRealVector
- Overrides:
unitize
in 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:
toArray
in interfaceRealVector
- Overrides:
toArray
in 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:
hashCode
in 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:
equals
in 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:
sparseIterator
in interfaceRealVector
- Overrides:
sparseIterator
in classAbstractRealVector
- Returns:
- a sparse iterator
-
-