Top Description Inners Fields Constructors Methods
org.apache.commons.math3.linear

public Class OpenMapRealVector

extends SparseRealVector
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, org.apache.commons.math3.exception.DimensionMismatchException, .MathArithmeticException, .NotPositiveException, .OutOfRangeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.FastMath, .OpenIntToDoubleHashMap, .OpenIntToDoubleHashMap.Iterator

This class implements the RealVector interface with a OpenIntToDoubleHashMap backing store.

Caveat

This implementation assumes that, for any x, the equality x * 0d == 0d holds. But it is is not true for NaN. Moreover, zero entries will lose their sign. Some operations (that involve NaN and/or infinities) may thus give incorrect results, like multiplications, divisions or functions mapping.

Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass 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.

Field Summary

Modifier and TypeField and Description
public static final double
DEFAULT_ZERO_TOLERANCE

Default Tolerance for having a value considered zero.

private final OpenIntToDoubleHashMap
entries

Entries of the vector.

private final double
epsilon

Tolerance for having a value considered zero.

private static final long
serialVersionUID

Serializable version identifier.

private final int
virtualSize

Dimension of the vector.

Constructor Summary

AccessConstructor and Description
public
OpenMapRealVector()

Build a 0-length vector.

public
OpenMapRealVector(int
Size of the vector.
dimension
)

Construct a vector of zeroes.

public
OpenMapRealVector(int
Size of the vector.
dimension
,
double
Tolerance below which a value considered zero.
epsilon
)

Construct a vector of zeroes, specifying zero tolerance.

protected
OpenMapRealVector(OpenMapRealVector
Original vector.
v
,
int
Amount to add.
resize
)

Build a resized vector, for use with append.

public
OpenMapRealVector(int
Size of the vector.
dimension
,
int
The expected number of non-zero entries.
expectedSize
)

Build a vector with known the sparseness (for advanced use only).

public
OpenMapRealVector(int
Size of the vector.
dimension
,
int
Expected number of non-zero entries.
expectedSize
,
double
Tolerance below which a value is considered zero.
epsilon
)

Build a vector with known the sparseness and zero tolerance setting (for advanced use only).

public
OpenMapRealVector(double[]
Set of values to create from.
values
)

Create from an array.

public
OpenMapRealVector(double[]
Set of values to create from.
values
,
double
Tolerance below which a value is considered zero.
epsilon
)

Create from an array, specifying zero tolerance.

public
OpenMapRealVector(Double[]
The set of values to create from
values
)

Create from an array.

public
OpenMapRealVector(Double[]
Set of values to create from.
values
,
double
Tolerance below which a value is considered zero.
epsilon
)

Create from an array.

public
OpenMapRealVector(OpenMapRealVector
Instance to copy from.
v
)

Copy constructor.

public
OpenMapRealVector(RealVector
Instance to copy from.
v
)

Generic copy constructor.

Method Summary

Modifier and TypeMethod and Description
public RealVector
add(RealVector
Vector to be added.
v
)

Overrides org.apache.commons.math3.linear.RealVector.add.

Compute the sum of this vector and v.

public OpenMapRealVector

Returns:

the sum of this and v.
add
(OpenMapRealVector
Vector to add.
v
)

Optimized method to add two OpenMapRealVectors.

public OpenMapRealVector

Returns:

The result of appending v to self
append
(OpenMapRealVector
vector to append
v
)

Optimized method to append a OpenMapRealVector.

public OpenMapRealVector
append(RealVector
vector to append to this one.
v
)

Implements abstract org.apache.commons.math3.linear.RealVector.append.

Construct a new vector by appending a vector to this vector.

public OpenMapRealVector
append(double
double to append.
d
)

Implements abstract org.apache.commons.math3.linear.RealVector.append.

Construct a new vector by appending a double to this vector.

public OpenMapRealVector
copy()

Implements abstract org.apache.commons.math3.linear.RealVector.copy.

Returns a (deep) copy of this vector.

public double

Returns:

the dot product of this vector with v.
dotProduct
(OpenMapRealVector
Vector.
v
)
Deprecated as of 3.1 (to be removed in 4.0). The computation is performed by the parent class. The method must be kept to maintain backwards compatibility.

Computes the dot product.

public OpenMapRealVector
ebeDivide(RealVector
Vector by which instance elements must be divided.
v
)

Implements abstract org.apache.commons.math3.linear.RealVector.ebeDivide.

Element-by-element division.

public OpenMapRealVector
ebeMultiply(RealVector
Vector by which instance elements must be multiplied
v
)

Implements abstract org.apache.commons.math3.linear.RealVector.ebeMultiply.

Element-by-element multiplication.

public boolean
equals(Object
Object to test for equality.
obj
)

Overrides org.apache.commons.math3.linear.RealVector.equals.

Test for the equality of two real vectors.

public int
getDimension()

Implements abstract org.apache.commons.math3.linear.RealVector.getDimension.

Returns the size of the vector.

public double

Returns:

the distance from this and v.
getDistance
(OpenMapRealVector
Vector to compute distance to.
v
)

Optimized method to compute distance.

public double
getDistance(RealVector
Vector to which distance is requested.
v
)

Overrides org.apache.commons.math3.linear.RealVector.getDistance.

Distance between two vectors.

private OpenIntToDoubleHashMap

Returns:

the entries of this instance.
getEntries
()

Get the entries of this instance.

public double
getEntry(int
Index location of entry to be fetched.
index
)

Implements abstract org.apache.commons.math3.linear.RealVector.getEntry.

Return the entry at the specified index.

public double

Returns:

distance between this vector and v.
getL1Distance
(OpenMapRealVector
Vector to which distance is requested.
v
)

Distance between two vectors.

public double
getL1Distance(RealVector
Vector to which distance is requested.
v
)

Overrides org.apache.commons.math3.linear.RealVector.getL1Distance.

Distance between two vectors.

private double

Returns:

the LInfDistance.
getLInfDistance
(OpenMapRealVector
Vector to compute distance from.
v
)

Optimized method to compute LInfDistance.

public double
getLInfDistance(RealVector
Vector to which distance is requested.
v
)

Overrides org.apache.commons.math3.linear.RealVector.getLInfDistance.

Distance between two vectors.

public double

Returns:

the percentage of none zero elements as a decimal percent.
getSparsity
()

public OpenMapRealVector
getSubVector(int
index of first element.
index
,
int
number of elements to be retrieved.
n
)

Implements abstract org.apache.commons.math3.linear.RealVector.getSubVector.

Get a subvector from consecutive elements.

public int
hashCode()

Overrides org.apache.commons.math3.linear.RealVector.hashCode.

Returns a hash code value for this object.

protected boolean

Returns:

true if this value is within epsilon to zero, false otherwise.
isDefaultValue
(double
Value to test
value
)

Determine if this value is within epsilon of zero.

public boolean
isInfinite()

Implements abstract org.apache.commons.math3.linear.RealVector.isInfinite.

Check whether any coordinate of this vector is infinite and none are NaN.

public boolean
isNaN()

Implements abstract org.apache.commons.math3.linear.RealVector.isNaN.

Check whether any coordinate of this vector is NaN.

public OpenMapRealVector
mapAdd(double
Value to be added to each entry.
d
)

Overrides org.apache.commons.math3.linear.RealVector.mapAdd.

Add a value to each entry.

public OpenMapRealVector
mapAddToSelf(double
Value to be added to each entry.
d
)

Overrides org.apache.commons.math3.linear.RealVector.mapAddToSelf.

Add a value to each entry.

public void
set(double
Single value to set for all elements.
value
)

Overrides org.apache.commons.math3.linear.RealVector.set.

Set all elements to a single value.

public void
setEntry(int
element index.
index
,
double
new value for the element.
value
)

Implements abstract org.apache.commons.math3.linear.RealVector.setEntry.

Set a single element.

public void
setSubVector(int
index of first element to be set.
index
,
RealVector
vector containing the values to set.
v
)

Implements abstract org.apache.commons.math3.linear.RealVector.setSubVector.

Set a sequence of consecutive elements.

public Iterator<RealVector.Entry>
sparseIterator()

Overrides org.apache.commons.math3.linear.RealVector.sparseIterator.

Create a sparse iterator over the vector, which may omit some entries.

public OpenMapRealVector

Returns:

the difference of this and v.
subtract
(OpenMapRealVector
Vector to subtract from this.
v
)

Optimized method to subtract OpenMapRealVectors.

public RealVector
subtract(RealVector
Vector to be subtracted.
v
)

Overrides org.apache.commons.math3.linear.RealVector.subtract.

Subtract v from this vector.

public double[]
toArray()

Overrides org.apache.commons.math3.linear.RealVector.toArray.

Convert the vector to an array of doubles.

public void
unitize()

Overrides org.apache.commons.math3.linear.RealVector.unitize.

Converts this vector into a unit vector.

public OpenMapRealVector
unitVector()

Overrides org.apache.commons.math3.linear.RealVector.unitVector.

Creates a unit vector pointing in the direction of this vector.