public class OpenMapRealVector extends AbstractRealVector implements SparseRealVector, java.io.Serializable
RealVector
interface with a OpenIntToDoubleHashMap
backing store.RealVector.Entry
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_ZERO_TOLERANCE
Default Tolerance for having a value considered zero.
|
Constructor and Description |
---|
OpenMapRealVector()
Build a 0-length vector.
|
OpenMapRealVector(double[] values)
Create from a double array.
|
OpenMapRealVector(java.lang.Double[] values)
Create from a Double array.
|
OpenMapRealVector(double[] values,
double epsilon)
Create from a double array, specifying zero tolerance.
|
OpenMapRealVector(java.lang.Double[] values,
double epsilon)
Create from a Double array.
|
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(OpenMapRealVector v)
Copy constructor.
|
OpenMapRealVector(RealVector v)
Generic copy constructor.
|
Modifier and Type | Method and Description |
---|---|
OpenMapRealVector |
add(OpenMapRealVector v)
Optimized method to add two OpenMapRealVectors.
|
RealVector |
add(RealVector v)
Compute the sum of this vector and
v . |
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 for
a.subtract(b } to be the zero vector, while
a.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 spelled
getSparsity() |
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 are
NaN . |
boolean |
isNaN()
Check whether any coordinate of this vector is
NaN . |
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)
Subtract
v from this vector. |
OpenMapRealVector |
subtract(OpenMapRealVector v)
Optimized method to subtract OpenMapRealVectors.
|
OpenMapRealVector |
subtract(RealVector v)
Subtract
v 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.
|
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
getClass, notify, notifyAll, toString, wait, wait, wait
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
public static final double DEFAULT_ZERO_TOLERANCE
public OpenMapRealVector()
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 the append
method (append(double)
, append(double[])
, append(RealVector)
) to gather data
into this vector.
public OpenMapRealVector(int dimension)
dimension
- size of the vectorpublic OpenMapRealVector(int dimension, double epsilon)
dimension
- Size of the vectorepsilon
- The tolerance for having a value considered zeropublic OpenMapRealVector(int dimension, int expectedSize)
dimension
- The size of the vectorexpectedSize
- The expected number of non-zero entriespublic OpenMapRealVector(int dimension, int expectedSize, double epsilon)
dimension
- The size of the vectorexpectedSize
- The expected number of non-zero entriesepsilon
- The tolerance for having a value considered zeropublic OpenMapRealVector(double[] values)
values
- The set of values to create frompublic OpenMapRealVector(double[] values, double epsilon)
values
- The set of values to create fromepsilon
- The tolerance for having a value considered zeropublic OpenMapRealVector(java.lang.Double[] values)
values
- The set of values to create frompublic OpenMapRealVector(java.lang.Double[] values, double epsilon)
values
- The set of values to create fromepsilon
- The tolerance for having a value considered zeropublic OpenMapRealVector(OpenMapRealVector v)
v
- The instance to copy frompublic OpenMapRealVector(RealVector v)
v
- The instance to copy frompublic RealVector add(RealVector v) throws java.lang.IllegalArgumentException
v
.add
in interface RealVector
add
in class AbstractRealVector
v
- Vector to be added.this
+ v
.DimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector add(OpenMapRealVector v) throws java.lang.IllegalArgumentException
v
- Vector to add withthis
with v
java.lang.IllegalArgumentException
- If the dimensions don't matchpublic OpenMapRealVector append(OpenMapRealVector v)
v
- vector to appendv
to selfpublic OpenMapRealVector append(RealVector v)
append
in interface RealVector
v
- vector to append to this one.public OpenMapRealVector append(double d)
append
in interface RealVector
d
- double to append.public OpenMapRealVector append(double[] a)
append
in interface RealVector
a
- double array to append.public OpenMapRealVector copy()
copy
in interface RealVector
copy
in class AbstractRealVector
public double dotProduct(OpenMapRealVector v) throws java.lang.IllegalArgumentException
v
- The vector to compute the dot product withthis
and v
java.lang.IllegalArgumentException
- If the dimensions don't matchpublic double dotProduct(RealVector v) throws java.lang.IllegalArgumentException
dotProduct
in interface RealVector
dotProduct
in class AbstractRealVector
v
- vector with which dot product should be computedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector ebeDivide(RealVector v) throws java.lang.IllegalArgumentException
ebeDivide
in interface RealVector
v
- vector by which instance elements must be dividedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector ebeDivide(double[] v) throws java.lang.IllegalArgumentException
ebeDivide
in interface RealVector
ebeDivide
in class AbstractRealVector
v
- vector by which instance elements must be dividedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector ebeMultiply(RealVector v) throws java.lang.IllegalArgumentException
ebeMultiply
in interface RealVector
v
- vector by which instance elements must be multipliedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector ebeMultiply(double[] v) throws java.lang.IllegalArgumentException
ebeMultiply
in interface RealVector
ebeMultiply
in class AbstractRealVector
v
- vector by which instance elements must be multipliedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector getSubVector(int index, int n) throws MatrixIndexException
getSubVector
in interface RealVector
index
- index of first element.n
- number of elements to be retrieved.MatrixIndexException
public double[] getData()
getData
in interface RealVector
getData
in class AbstractRealVector
public int getDimension()
getDimension
in interface RealVector
public double getDistance(OpenMapRealVector v) throws java.lang.IllegalArgumentException
v
- The vector to compute distance tothis
and v
java.lang.IllegalArgumentException
- If the dimensions don't matchpublic double getDistance(RealVector v) throws java.lang.IllegalArgumentException
This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
getDistance
in interface RealVector
getDistance
in class AbstractRealVector
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
RealVector.getL1Distance(RealVector)
,
RealVector.getLInfDistance(RealVector)
,
RealVector.getNorm()
public double getDistance(double[] v) throws java.lang.IllegalArgumentException
This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
getDistance
in interface RealVector
getDistance
in class AbstractRealVector
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
RealVector.getL1Distance(double[])
,
RealVector.getLInfDistance(double[])
,
RealVector.getNorm()
public double getEntry(int index) throws MatrixIndexException
getEntry
in interface RealVector
index
- Index location of entry to be fetched.index
.MatrixIndexException
RealVector.setEntry(int, double)
public double getL1Distance(OpenMapRealVector v)
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
v
- vector to which distance is requestedpublic double getL1Distance(RealVector v) throws java.lang.IllegalArgumentException
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
getL1Distance
in interface RealVector
getL1Distance
in class AbstractRealVector
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
RealVector.getDistance(RealVector)
,
RealVector.getLInfDistance(RealVector)
,
RealVector.getL1Norm()
public double getL1Distance(double[] v) throws java.lang.IllegalArgumentException
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
getL1Distance
in interface RealVector
getL1Distance
in class AbstractRealVector
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
RealVector.getDistance(double[])
,
RealVector.getLInfDistance(double[])
,
RealVector.getL1Norm()
public double getLInfDistance(RealVector v) throws java.lang.IllegalArgumentException
This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
getLInfDistance
in interface RealVector
getLInfDistance
in class AbstractRealVector
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
RealVector.getDistance(RealVector)
,
RealVector.getL1Distance(RealVector)
,
RealVector.getLInfNorm()
public double getLInfDistance(double[] v) throws java.lang.IllegalArgumentException
This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
getLInfDistance
in interface RealVector
getLInfDistance
in class AbstractRealVector
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
RealVector.getDistance(double[])
,
RealVector.getL1Distance(double[])
,
RealVector.getLInfNorm()
public boolean isInfinite()
NaN
.isInfinite
in interface RealVector
true
if any coordinate of this vector is infinite and
none are NaN
, false
otherwise.public boolean isNaN()
NaN
.isNaN
in interface RealVector
true
if any coordinate of this vector is NaN
,
false
otherwise.public OpenMapRealVector mapAdd(double d)
mapAdd
in interface RealVector
mapAdd
in class AbstractRealVector
d
- Value to be added to each entry.this
+ d
.public OpenMapRealVector mapAddToSelf(double d)
mapAddToSelf
in interface RealVector
mapAddToSelf
in class AbstractRealVector
d
- Value to be added to each entry.this
.public RealMatrix outerProduct(double[] v) throws java.lang.IllegalArgumentException
outerProduct
in interface RealVector
outerProduct
in class AbstractRealVector
v
- vector with which outer product should be computedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public RealVector projection(RealVector v) throws java.lang.IllegalArgumentException
projection
in interface RealVector
v
- vector onto which instance must be projectedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector projection(double[] v) throws java.lang.IllegalArgumentException
projection
in interface RealVector
projection
in class AbstractRealVector
v
- vector onto which instance must be projectedDimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public void setEntry(int index, double value) throws MatrixIndexException
setEntry
in interface RealVector
index
- element index.value
- new value for the element.MatrixIndexException
RealVector.getEntry(int)
public void setSubVector(int index, RealVector v) throws MatrixIndexException
setSubVector
in interface RealVector
setSubVector
in class AbstractRealVector
index
- index of first element to be set.v
- vector containing the values to set.MatrixIndexException
RealVector.setSubVector(int, double[])
public void setSubVector(int index, double[] v) throws MatrixIndexException
setSubVector
in interface RealVector
setSubVector
in class AbstractRealVector
index
- index of first element to be set.v
- vector containing the values to set.MatrixIndexException
RealVector.setSubVector(int, RealVector)
public void set(double value)
set
in interface RealVector
set
in class AbstractRealVector
value
- single value to set for all elementspublic OpenMapRealVector subtract(OpenMapRealVector v) throws java.lang.IllegalArgumentException
v
- The vector to subtract from this
this
and v
java.lang.IllegalArgumentException
- If the dimensions don't matchpublic OpenMapRealVector subtract(RealVector v) throws java.lang.IllegalArgumentException
v
from this vector.subtract
in interface RealVector
subtract
in class AbstractRealVector
v
- Vector to be subtracted.this
- v
.DimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector subtract(double[] v) throws java.lang.IllegalArgumentException
v
from this vector.subtract
in interface RealVector
subtract
in class AbstractRealVector
v
- Vector to be subtracted.this
- v
.DimensionMismatchException
- if v
is not the same size as this vector.java.lang.IllegalArgumentException
public OpenMapRealVector unitVector()
The instance is not changed by this method.
unitVector
in interface RealVector
unitVector
in class AbstractRealVector
public void unitize()
The instance itself is changed by this method.
unitize
in interface RealVector
unitize
in class AbstractRealVector
public double[] toArray()
The array is independent from vector data, it's elements are copied.
toArray
in interface RealVector
toArray
in class AbstractRealVector
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, while
a.hashCode() != b.hashCode()
.
hashCode
in class java.lang.Object
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, while
a.equals(b) == false
.
equals
in class java.lang.Object
@Deprecated public double getSparcity()
getSparsity()
public double getSparsity()
public java.util.Iterator<RealVector.Entry> sparseIterator()
RealVector.iterator()
.sparseIterator
in interface RealVector
sparseIterator
in class AbstractRealVector
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"