public class OpenMapRealVector extends SparseRealVector implements Serializable
RealVector
interface with a
OpenIntToDoubleHashMap
backing store.Modifier and Type | Class and Description |
---|---|
protected class |
OpenMapRealVector.OpenMapEntry
Implementation of
Entry optimized for OpenMap. |
protected class |
OpenMapRealVector.OpenMapSparseIterator
Iterator class to do iteration over just the non-zero elements.
|
RealVector.Entry, RealVector.SparseEntryIterator
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_ZERO_TOLERANCE
Default Tolerance for having a value considered zero.
|
Modifier | Constructor and Description |
---|---|
|
OpenMapRealVector()
Build a 0-length vector.
|
|
OpenMapRealVector(double[] values)
Create from an array.
|
|
OpenMapRealVector(Double[] values)
Create from an array.
|
|
OpenMapRealVector(double[] values,
double epsilon)
Create from an array, specifying zero tolerance.
|
|
OpenMapRealVector(Double[] values,
double epsilon)
Create from an array.
|
|
OpenMapRealVector(int dimension)
Construct a vector of zeroes.
|
|
OpenMapRealVector(int dimension,
double epsilon)
Construct a vector of zeroes, 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.
|
protected |
OpenMapRealVector(OpenMapRealVector v,
int resize)
Build a resized vector, for use with append.
|
|
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 new vector by appending a double to this vector.
|
OpenMapRealVector |
append(OpenMapRealVector v)
Optimized method to append a OpenMapRealVector.
|
OpenMapRealVector |
append(RealVector v)
Construct a new 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 of this vector with
v . |
OpenMapRealVector |
ebeDivide(RealVector v)
Element-by-element division.
|
OpenMapRealVector |
ebeMultiply(RealVector v)
Element-by-element multiplication.
|
boolean |
equals(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 . |
int |
getDimension()
Returns the size of the vector.
|
double |
getDistance(OpenMapRealVector v)
Optimized method to compute distance.
|
double |
getDistance(RealVector v)
Distance between two vectors.
|
double |
getEntry(int index)
Return the entry at the specified index.
|
double |
getL1Distance(OpenMapRealVector v)
Distance between two vectors.
|
double |
getL1Distance(RealVector v)
Distance between two vectors.
|
double |
getLInfDistance(RealVector v)
Distance between two vectors.
|
double |
getSparsity() |
OpenMapRealVector |
getSubVector(int index,
int n)
Get a subvector from consecutive elements.
|
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() . |
protected boolean |
isDefaultValue(double value)
Determine if this value is within epsilon of zero.
|
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.
|
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,
RealVector v)
Set a sequence of consecutive elements.
|
Iterator<RealVector.Entry> |
sparseIterator()
Create a sparse iterator over the vector, which may omit some entries.
|
OpenMapRealVector |
subtract(OpenMapRealVector v)
Optimized method to subtract OpenMapRealVectors.
|
RealVector |
subtract(RealVector v)
Subtract
v from this vector. |
double[] |
toArray()
Convert the vector to an array of
double s. |
void |
unitize()
Converts this vector into a unit vector.
|
OpenMapRealVector |
unitVector()
Creates a unit vector pointing in the direction of this vector.
|
addToEntry, checkIndex, checkVectorDimensions, checkVectorDimensions, combine, combineToSelf, cosine, getL1Norm, getLInfNorm, getMaxIndex, getMaxValue, getMinIndex, getMinValue, getNorm, iterator, map, mapDivide, mapDivideToSelf, mapMultiply, mapMultiplyToSelf, mapSubtract, mapSubtractToSelf, mapToSelf, outerProduct, unmodifiableRealVector
public static final double DEFAULT_ZERO_TOLERANCE
public OpenMapRealVector()
OpenMapRealVector(OpenMapRealVector, int)
constructor
or one of the append
method (append(double)
,
append(RealVector)
) to gather data into this vector.public OpenMapRealVector(int dimension)
dimension
- Size of the vector.public OpenMapRealVector(int dimension, double epsilon)
dimension
- Size of the vector.epsilon
- Tolerance below which a value considered zero.protected OpenMapRealVector(OpenMapRealVector v, int resize)
v
- Original vector.resize
- Amount to add.public OpenMapRealVector(int dimension, int expectedSize)
dimension
- Size of the vector.expectedSize
- The expected number of non-zero entries.public OpenMapRealVector(int dimension, int expectedSize, double epsilon)
dimension
- Size of the vector.expectedSize
- Expected number of non-zero entries.epsilon
- Tolerance below which a value is considered zero.public OpenMapRealVector(double[] values)
values
- Set of values to create from.public OpenMapRealVector(double[] values, double epsilon)
values
- Set of values to create from.epsilon
- Tolerance below which a value is considered zero.public OpenMapRealVector(Double[] values)
values
- The set of values to create frompublic OpenMapRealVector(Double[] values, double epsilon)
values
- Set of values to create from.epsilon
- Tolerance below which a value is considered zero.public OpenMapRealVector(OpenMapRealVector v)
v
- Instance to copy from.public OpenMapRealVector(RealVector v)
v
- Instance to copy from.protected boolean isDefaultValue(double value)
value
- Value to testtrue
if this value is within epsilon to zero,
false
otherwise.public RealVector add(RealVector v)
v
.
Returns a new vector. Does not change instance data.add
in class RealVector
v
- Vector to be added.this
+ v
.public OpenMapRealVector add(OpenMapRealVector v)
v
- Vector to add.this
and v
.DimensionMismatchException
- if the dimensions do not match.public OpenMapRealVector append(OpenMapRealVector v)
v
- vector to appendv
to selfpublic OpenMapRealVector append(RealVector v)
append
in class RealVector
v
- vector to append to this one.public OpenMapRealVector append(double d)
append
in class RealVector
d
- double to append.public OpenMapRealVector copy()
copy
in class RealVector
public double dotProduct(OpenMapRealVector v)
v
- Cector to compute the dot product with.this
and v
.DimensionMismatchException
- if the dimensions do not match.public double dotProduct(RealVector v)
v
.dotProduct
in class RealVector
v
- Vector with which dot product should be computedv
.public OpenMapRealVector ebeDivide(RealVector v)
ebeDivide
in class RealVector
v
- Vector by which instance elements must be divided.public OpenMapRealVector ebeMultiply(RealVector v)
ebeMultiply
in class RealVector
v
- Vector by which instance elements must be multipliedpublic OpenMapRealVector getSubVector(int index, int n)
getSubVector
in class RealVector
index
- index of first element.n
- number of elements to be retrieved.public int getDimension()
getDimension
in class RealVector
public double getDistance(OpenMapRealVector v)
v
- Vector to compute distance to.this
and v
.DimensionMismatchException
- if the dimensions do not match.public double getDistance(RealVector v)
This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of element differences, or Euclidian distance.
getDistance
in class RealVector
v
- Vector to which distance is requested.RealVector.getL1Distance(RealVector)
,
RealVector.getLInfDistance(RealVector)
,
RealVector.getNorm()
public double getEntry(int index)
getEntry
in class RealVector
index
- Index location of entry to be fetched.index
.RealVector.setEntry(int, double)
public double getL1Distance(OpenMapRealVector v)
v
- Vector to which distance is requested.v
.public double getL1Distance(RealVector v)
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of the elements differences.
getL1Distance
in class RealVector
v
- Vector to which distance is requested.public double getLInfDistance(RealVector v)
This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of element differences.
getLInfDistance
in class RealVector
v
- Vector to which distance is requested.RealVector.getDistance(RealVector)
,
RealVector.getL1Distance(RealVector)
,
RealVector.getLInfNorm()
public boolean isInfinite()
NaN
.isInfinite
in class RealVector
true
if any coordinate of this vector is infinite and
none are NaN
, false
otherwise.public boolean isNaN()
NaN
.isNaN
in class RealVector
true
if any coordinate of this vector is NaN
,
false
otherwise.public OpenMapRealVector mapAdd(double d)
mapAdd
in class RealVector
d
- Value to be added to each entry.this
+ d
.public OpenMapRealVector mapAddToSelf(double d)
mapAddToSelf
in class RealVector
d
- Value to be added to each entry.this
.public RealVector projection(RealVector v)
projection
in class RealVector
v
- vector onto which instance must be projected.v
.public void setEntry(int index, double value)
setEntry
in class RealVector
index
- element index.value
- new value for the element.RealVector.getEntry(int)
public void setSubVector(int index, RealVector v)
setSubVector
in class RealVector
index
- index of first element to be set.v
- vector containing the values to set.public void set(double value)
set
in class RealVector
value
- Single value to set for all elements.public OpenMapRealVector subtract(OpenMapRealVector v)
v
- Vector to subtract from this
.this
and v
.DimensionMismatchException
- if the dimensions do not match.public RealVector subtract(RealVector v)
v
from this vector.
Returns a new vector. Does not change instance data.subtract
in class RealVector
v
- Vector to be subtracted.this
- v
.public OpenMapRealVector unitVector()
unitVector
in class RealVector
public void unitize()
unitize
in class RealVector
public double[] toArray()
double
s.
The array is independent from this vector data: the elements
are copied.toArray
in class RealVector
public int hashCode()
a.subtract(b)
to be the zero vector, while
a.hashCode() != b.hashCode()
.public boolean equals(Object obj)
a.subtract(b
} to be the zero vector, while
a.equals(b) == false
.public double getSparsity()
public Iterator<RealVector.Entry> sparseIterator()
RealVector.iterator()
.sparseIterator
in class RealVector
Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.