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, outerProductgetClass, notify, notifyAll, toString, wait, wait, waitadd, 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, outerProductpublic 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 RealVectoradd in class AbstractRealVectorv - Vector to be added.this + v.DimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector add(OpenMapRealVector v) throws java.lang.IllegalArgumentException
v - Vector to add withthis with vjava.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 RealVectorv - vector to append to this one.public OpenMapRealVector append(double d)
append in interface RealVectord - double to append.public OpenMapRealVector append(double[] a)
append in interface RealVectora - double array to append.public OpenMapRealVector copy()
copy in interface RealVectorcopy in class AbstractRealVectorpublic double dotProduct(OpenMapRealVector v) throws java.lang.IllegalArgumentException
v - The vector to compute the dot product withthis and vjava.lang.IllegalArgumentException - If the dimensions don't matchpublic double dotProduct(RealVector v) throws java.lang.IllegalArgumentException
dotProduct in interface RealVectordotProduct in class AbstractRealVectorv - vector with which dot product should be computedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector ebeDivide(RealVector v) throws java.lang.IllegalArgumentException
ebeDivide in interface RealVectorv - vector by which instance elements must be dividedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector ebeDivide(double[] v) throws java.lang.IllegalArgumentException
ebeDivide in interface RealVectorebeDivide in class AbstractRealVectorv - vector by which instance elements must be dividedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector ebeMultiply(RealVector v) throws java.lang.IllegalArgumentException
ebeMultiply in interface RealVectorv - vector by which instance elements must be multipliedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector ebeMultiply(double[] v) throws java.lang.IllegalArgumentException
ebeMultiply in interface RealVectorebeMultiply in class AbstractRealVectorv - vector by which instance elements must be multipliedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector getSubVector(int index, int n) throws MatrixIndexException
getSubVector in interface RealVectorindex - index of first element.n - number of elements to be retrieved.MatrixIndexExceptionpublic double[] getData()
getData in interface RealVectorgetData in class AbstractRealVectorpublic int getDimension()
getDimension in interface RealVectorpublic double getDistance(OpenMapRealVector v) throws java.lang.IllegalArgumentException
v - The vector to compute distance tothis and vjava.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 RealVectorgetDistance in class AbstractRealVectorv - vector to which distance is requestedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionRealVector.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 RealVectorgetDistance in class AbstractRealVectorv - vector to which distance is requestedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionRealVector.getL1Distance(double[]),
RealVector.getLInfDistance(double[]),
RealVector.getNorm()public double getEntry(int index)
throws MatrixIndexException
getEntry in interface RealVectorindex - Index location of entry to be fetched.index.MatrixIndexExceptionRealVector.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 RealVectorgetL1Distance in class AbstractRealVectorv - vector to which distance is requestedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionRealVector.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 RealVectorgetL1Distance in class AbstractRealVectorv - vector to which distance is requestedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionRealVector.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 RealVectorgetLInfDistance in class AbstractRealVectorv - vector to which distance is requestedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionRealVector.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 RealVectorgetLInfDistance in class AbstractRealVectorv - vector to which distance is requestedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionRealVector.getDistance(double[]),
RealVector.getL1Distance(double[]),
RealVector.getLInfNorm()public boolean isInfinite()
NaN.isInfinite in interface RealVectortrue if any coordinate of this vector is infinite and
none are NaN, false otherwise.public boolean isNaN()
NaN.isNaN in interface RealVectortrue if any coordinate of this vector is NaN,
false otherwise.public OpenMapRealVector mapAdd(double d)
mapAdd in interface RealVectormapAdd in class AbstractRealVectord - Value to be added to each entry.this + d.public OpenMapRealVector mapAddToSelf(double d)
mapAddToSelf in interface RealVectormapAddToSelf in class AbstractRealVectord - Value to be added to each entry.this.public RealMatrix outerProduct(double[] v) throws java.lang.IllegalArgumentException
outerProduct in interface RealVectorouterProduct in class AbstractRealVectorv - vector with which outer product should be computedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic RealVector projection(RealVector v) throws java.lang.IllegalArgumentException
projection in interface RealVectorv - vector onto which instance must be projectedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector projection(double[] v) throws java.lang.IllegalArgumentException
projection in interface RealVectorprojection in class AbstractRealVectorv - vector onto which instance must be projectedDimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic void setEntry(int index,
double value)
throws MatrixIndexException
setEntry in interface RealVectorindex - element index.value - new value for the element.MatrixIndexExceptionRealVector.getEntry(int)public void setSubVector(int index,
RealVector v)
throws MatrixIndexException
setSubVector in interface RealVectorsetSubVector in class AbstractRealVectorindex - index of first element to be set.v - vector containing the values to set.MatrixIndexExceptionRealVector.setSubVector(int, double[])public void setSubVector(int index,
double[] v)
throws MatrixIndexException
setSubVector in interface RealVectorsetSubVector in class AbstractRealVectorindex - index of first element to be set.v - vector containing the values to set.MatrixIndexExceptionRealVector.setSubVector(int, RealVector)public void set(double value)
set in interface RealVectorset in class AbstractRealVectorvalue - single value to set for all elementspublic OpenMapRealVector subtract(OpenMapRealVector v) throws java.lang.IllegalArgumentException
v - The vector to subtract from thisthis and vjava.lang.IllegalArgumentException - If the dimensions don't matchpublic OpenMapRealVector subtract(RealVector v) throws java.lang.IllegalArgumentException
v from this vector.subtract in interface RealVectorsubtract in class AbstractRealVectorv - Vector to be subtracted.this - v.DimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector subtract(double[] v) throws java.lang.IllegalArgumentException
v from this vector.subtract in interface RealVectorsubtract in class AbstractRealVectorv - Vector to be subtracted.this - v.DimensionMismatchException - if v is not the same size as this vector.java.lang.IllegalArgumentExceptionpublic OpenMapRealVector unitVector()
The instance is not changed by this method.
unitVector in interface RealVectorunitVector in class AbstractRealVectorpublic void unitize()
The instance itself is changed by this method.
unitize in interface RealVectorunitize in class AbstractRealVectorpublic double[] toArray()
The array is independent from vector data, it's elements are copied.
toArray in interface RealVectortoArray in class AbstractRealVectorpublic 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.Objectpublic 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 RealVectorsparseIterator in class AbstractRealVectorCopyright © 2010 - 2023 Adobe. All Rights Reserved