org.apache.commons.math3.linear

## Class OpenMapRealVector

- java.lang.Object
- - org.apache.commons.math3.linear.RealVector
  - - org.apache.commons.math3.linear.SparseRealVector
    - - org.apache.commons.math3.linear.OpenMapRealVector

All Implemented Interfaces:
  java.io.Serializable

Deprecated.
As of version 3.1, this class is deprecated, for reasons exposed in this JIRA ticket. This class will be removed in version 4.0.

    @Deprecated
    public class OpenMapRealVector
    extends SparseRealVector
    implements java.io.Serializable

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

Since:
  2.0
Version:
  $Id: OpenMapRealVector.java 1416643 2012-12-03 19:37:14Z tn $
See Also:
  Serialized Form

### Nested Class Summary

Nested Classes
`protected class` `OpenMapRealVector.OpenMapEntry` Deprecated. Implementation of `Entry` optimized for OpenMap.
`protected class` `OpenMapRealVector.OpenMapSparseIterator` Deprecated. Iterator class to do iteration over just the non-zero elements.

### Nested classes/interfaces inherited from class org.apache.commons.math3.linear.RealVector

`RealVector.Entry, RealVector.SparseEntryIterator`

### Field Summary

Fields
`static double` `DEFAULT_ZERO_TOLERANCE` Deprecated. Default Tolerance for having a value considered zero.
`private OpenIntToDoubleHashMap` `entries` Deprecated. Entries of the vector.
`private double` `epsilon` Deprecated. Tolerance for having a value considered zero.
`private static long` `serialVersionUID` Deprecated. Serializable version identifier.
`private int` `virtualSize` Deprecated. Dimension of the vector.

### Constructor Summary

Constructors
`` `OpenMapRealVector()` Deprecated. Build a 0-length vector.
`` `OpenMapRealVector(double[] values)` Deprecated. Create from an array.
`` `OpenMapRealVector(java.lang.Double[] values)` Deprecated. Create from an array.
`` `OpenMapRealVector(double[] values, double epsilon)` Deprecated. Create from an array, specifying zero tolerance.
`` `OpenMapRealVector(java.lang.Double[] values, double epsilon)` Deprecated. Create from an array.
`` `OpenMapRealVector(int dimension)` Deprecated. Construct a vector of zeroes.
`` `OpenMapRealVector(int dimension, double epsilon)` Deprecated. Construct a vector of zeroes, specifying zero tolerance.
`` `OpenMapRealVector(int dimension, int expectedSize)` Deprecated. Build a vector with known the sparseness (for advanced use only).
`` `OpenMapRealVector(int dimension, int expectedSize, double epsilon)` Deprecated. Build a vector with known the sparseness and zero tolerance setting (for advanced use only).
`` `OpenMapRealVector(OpenMapRealVector v)` Deprecated. Copy constructor.
`protected` `OpenMapRealVector(OpenMapRealVector v, int resize)` Deprecated. Build a resized vector, for use with append.
`` `OpenMapRealVector(RealVector v)` Deprecated. Generic copy constructor.

### Method Summary

Methods
`OpenMapRealVector` `add(OpenMapRealVector v)` Deprecated. Optimized method to add two OpenMapRealVectors.
`RealVector` `add(RealVector v)` Deprecated. Compute the sum of this vector and `v`.
`OpenMapRealVector` `append(double d)` Deprecated. Construct a new vector by appending a double to this vector.
`OpenMapRealVector` `append(OpenMapRealVector v)` Deprecated. Optimized method to append a OpenMapRealVector.
`OpenMapRealVector` `append(RealVector v)` Deprecated. Construct a new vector by appending a vector to this vector.
`OpenMapRealVector` `copy()` Deprecated. Returns a (deep) copy of this vector.
`double` `dotProduct(OpenMapRealVector 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.
`OpenMapRealVector` `ebeDivide(RealVector v)` Deprecated. Element-by-element division.
`OpenMapRealVector` `ebeMultiply(RealVector v)` Deprecated. Element-by-element multiplication.
`boolean` `equals(java.lang.Object obj)` Deprecated. Test for the equality of two real vectors.
`int` `getDimension()` Deprecated. Returns the size of the vector.
`double` `getDistance(OpenMapRealVector v)` Deprecated. Optimized method to compute distance.
`double` `getDistance(RealVector v)` Deprecated. Distance between two vectors.
`private OpenIntToDoubleHashMap` `getEntries()` Deprecated. Get the entries of this instance.
`double` `getEntry(int index)` Deprecated. Return the entry at the specified index.
`double` `getL1Distance(OpenMapRealVector v)` Deprecated. Distance between two vectors.
`double` `getL1Distance(RealVector v)` Deprecated. Distance between two vectors.
`private double` `getLInfDistance(OpenMapRealVector v)` Deprecated. Optimized method to compute LInfDistance.
`double` `getLInfDistance(RealVector v)` Deprecated. Distance between two vectors.
`double` `getSparsity()` Deprecated.
`OpenMapRealVector` `getSubVector(int index, int n)` Deprecated. Get a subvector from consecutive elements.
`int` `hashCode()` Deprecated. .
`protected boolean` `isDefaultValue(double value)` Deprecated. Determine if this value is within epsilon of zero.
`boolean` `isInfinite()` Deprecated. Check whether any coordinate of this vector is infinite and none are `NaN`.
`boolean` `isNaN()` Deprecated. Check whether any coordinate of this vector is `NaN`.
`OpenMapRealVector` `mapAdd(double d)` Deprecated. Add a value to each entry.
`OpenMapRealVector` `mapAddToSelf(double d)` Deprecated. Add a value to each entry.
`void` `set(double value)` Deprecated. Set all elements to a single value.
`void` `setEntry(int index, double value)` Deprecated. Set a single element.
`void` `setSubVector(int index, RealVector v)` Deprecated. Set a sequence of consecutive elements.
`java.util.Iterator<RealVector.Entry>` `sparseIterator()` Deprecated. Create a sparse iterator over the vector, which may omit some entries.
`OpenMapRealVector` `subtract(OpenMapRealVector v)` Deprecated. Optimized method to subtract OpenMapRealVectors.
`RealVector` `subtract(RealVector v)` Deprecated. Subtract `v` from this vector.
`double[]` `toArray()` Deprecated. Convert the vector to an array of `double`s.
`void` `unitize()` Deprecated. Converts this vector into a unit vector.
`OpenMapRealVector` `unitVector()` Deprecated. Creates a unit vector pointing in the direction of this vector.

### Methods inherited from class org.apache.commons.math3.linear.RealVector

`addToEntry, checkIndex, checkIndices, checkVectorDimensions, checkVectorDimensions, combine, combineToSelf, cosine, dotProduct, getL1Norm, getLInfNorm, getMaxIndex, getMaxValue, getMinIndex, getMinValue, getNorm, iterator, map, mapDivide, mapDivideToSelf, mapMultiply, mapMultiplyToSelf, mapSubtract, mapSubtractToSelf, mapToSelf, outerProduct, projection, unmodifiableRealVector, walkInDefaultOrder, walkInDefaultOrder, walkInDefaultOrder, walkInDefaultOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DEFAULT_ZERO_TOLERANCE

    public static final double DEFAULT_ZERO_TOLERANCE

Deprecated.
Default Tolerance for having a value considered zero.

See Also:
  Constant Field Values

#### serialVersionUID

    private static final long serialVersionUID

Deprecated.
Serializable version identifier.

See Also:
  Constant Field Values

#### entries

    private final OpenIntToDoubleHashMap entries

Deprecated.
Entries of the vector.

#### virtualSize

    private final int virtualSize

Deprecated.
Dimension of the vector.

#### epsilon

    private final double epsilon

Deprecated.
Tolerance for having a value considered zero.

### Constructor Detail

#### OpenMapRealVector

    public OpenMapRealVector()

Deprecated.
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 the `append` method (`append(double)`, `append(RealVector)`) to gather data into this vector.

#### OpenMapRealVector

    public OpenMapRealVector(int dimension)

Deprecated.
Construct a vector of zeroes.

Parameters:
  `dimension` - Size of the vector.

#### OpenMapRealVector

    public OpenMapRealVector(int dimension,
                     double epsilon)

Deprecated.
Construct a vector of zeroes, specifying zero tolerance.

Parameters:
  `dimension` - Size of the vector.
  `epsilon` - Tolerance below which a value considered zero.

#### OpenMapRealVector

    protected OpenMapRealVector(OpenMapRealVector v,
                     int resize)

Deprecated.
Build a resized vector, for use with append.

Parameters:
  `v` - Original vector.
  `resize` - Amount to add.

#### OpenMapRealVector

    public OpenMapRealVector(int dimension,
                     int expectedSize)

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

Parameters:
  `dimension` - Size of the vector.
  `expectedSize` - The expected number of non-zero entries.

#### OpenMapRealVector

    public OpenMapRealVector(int dimension,
                     int expectedSize,
                     double epsilon)

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

Parameters:
  `dimension` - Size of the vector.
  `expectedSize` - Expected number of non-zero entries.
  `epsilon` - Tolerance below which a value is considered zero.

#### OpenMapRealVector

    public OpenMapRealVector(double[] values)

Deprecated.
Create from an array. Only non-zero entries will be stored.

Parameters:
  `values` - Set of values to create from.

#### OpenMapRealVector

    public OpenMapRealVector(double[] values,
                     double epsilon)

Deprecated.
Create from an array, specifying zero tolerance. Only non-zero entries will be stored.

Parameters:
  `values` - Set of values to create from.
  `epsilon` - Tolerance below which a value is considered zero.

#### OpenMapRealVector

    public OpenMapRealVector(java.lang.Double[] values)

Deprecated.
Create from an 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)

Deprecated.
Create from an array. Only non-zero entries will be stored.

Parameters:
  `values` - Set of values to create from.
  `epsilon` - Tolerance below which a value is considered zero.

#### OpenMapRealVector

    public OpenMapRealVector(OpenMapRealVector v)

Deprecated.
Copy constructor.

Parameters:
  `v` - Instance to copy from.

#### OpenMapRealVector

    public OpenMapRealVector(RealVector v)

Deprecated.
Generic copy constructor.

Parameters:
  `v` - Instance to copy from.

### Method Detail

#### getEntries

    private OpenIntToDoubleHashMap getEntries()

Deprecated.
Get the entries of this instance.

Returns:
  the entries of this instance.

#### isDefaultValue

    protected boolean isDefaultValue(double value)

Deprecated.
Determine if this value is within epsilon of zero.

Parameters:
  `value` - Value to test
Returns:
  `true` if this value is within epsilon to zero, `false` otherwise.
Since:
  2.1

#### add

    public RealVector add(RealVector v)
                   throws DimensionMismatchException

Deprecated.
Compute the sum of this vector and `v`. Returns a new vector. Does not change instance data.

Overrides:
  `add` in class `RealVector`
Parameters:
  `v` - Vector to be added.
Returns:
  `this` + `v`.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as `this` vector.

#### add

    public OpenMapRealVector add(OpenMapRealVector v)
                          throws DimensionMismatchException

Deprecated.
Optimized method to add two OpenMapRealVectors. It copies the larger vector, then iterates over the smaller.

Parameters:
  `v` - Vector to add.
Returns:
  the sum of `this` and `v`.
Throws:
  `DimensionMismatchException` - if the dimensions do not match.

#### append

    public OpenMapRealVector append(OpenMapRealVector v)

Deprecated.
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)

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

Specified by:
  `append` in class `RealVector`
Parameters:
  `v` - vector to append to this one.
Returns:
  a new vector.

#### append

    public OpenMapRealVector append(double d)

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

Specified by:
  `append` in class `RealVector`
Parameters:
  `d` - double to append.
Returns:
  a new vector.

#### copy

    public OpenMapRealVector copy()

Deprecated.
Returns a (deep) copy of this vector.

Specified by:
  `copy` in class `RealVector`
Returns:
  a vector copy.
Since:
  2.1

#### dotProduct

    @Deprecated
    public double dotProduct(OpenMapRealVector v)
                      throws DimensionMismatchException

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. Note that the computation is now performed in the parent class: no performance improvement is to be expected from this overloaded method. The previous implementation was buggy and cannot be easily fixed (see MATH-795).

Parameters:
  `v` - Vector.
Returns:
  the dot product of this vector with `v`.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as `this` vector.

#### ebeDivide

    public OpenMapRealVector ebeDivide(RealVector v)
                                throws DimensionMismatchException

Deprecated.
Element-by-element division.

Specified by:
  `ebeDivide` in class `RealVector`
Parameters:
  `v` - Vector by which instance elements must be divided.
Returns:
  a vector containing this[i] / v[i] for all i.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as `this` vector.

#### ebeMultiply

    public OpenMapRealVector ebeMultiply(RealVector v)
                                  throws DimensionMismatchException

Deprecated.
Element-by-element multiplication.

Specified by:
  `ebeMultiply` in class `RealVector`
Parameters:
  `v` - Vector by which instance elements must be multiplied
Returns:
  a vector containing this[i] * v[i] for all i.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as `this` vector.

#### getSubVector

    public OpenMapRealVector getSubVector(int index,
                                 int n)
                                   throws NotPositiveException,
                                          OutOfRangeException

Deprecated.
Get a subvector from consecutive elements.

Specified by:
  `getSubVector` in class `RealVector`
Parameters:
  `index` - index of first element.
  `n` - number of elements to be retrieved.
Returns:
  a vector containing n elements.
Throws:
  `NotPositiveException` - if the number of elements is not positive.
  `OutOfRangeException` - if the index is not valid.

#### getDimension

    public int getDimension()

Deprecated.
Returns the size of the vector.

Specified by:
  `getDimension` in class `RealVector`
Returns:
  the size of this vector.

#### getDistance

    public double getDistance(OpenMapRealVector v)
                       throws DimensionMismatchException

Deprecated.
Optimized method to compute distance.

Parameters:
  `v` - Vector to compute distance to.
Returns:
  the distance from `this` and `v`.
Throws:
  `DimensionMismatchException` - if the dimensions do not match.

#### getDistance

    public double getDistance(RealVector v)
                       throws DimensionMismatchException

Deprecated.
Distance between two vectors.

This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of element differences, or Euclidean distance.

Overrides:
  `getDistance` in class `RealVector`
Parameters:
  `v` - Vector to which distance is requested.
Returns:
  the distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as `this` vector.
See Also:
  `RealVector.getL1Distance(RealVector)`, `RealVector.getLInfDistance(RealVector)`, `RealVector.getNorm()`

#### getEntry

    public double getEntry(int index)
                    throws OutOfRangeException

Deprecated.
Return the entry at the specified index.

Specified by:
  `getEntry` in class `RealVector`
Parameters:
  `index` - Index location of entry to be fetched.
Returns:
  the vector entry at `index`.
Throws:
  `OutOfRangeException` - if the index is not valid.
See Also:
  `RealVector.setEntry(int, double)`

#### getL1Distance

    public double getL1Distance(OpenMapRealVector v)
                         throws DimensionMismatchException

Deprecated.
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 this vector and `v`.
Throws:
  `DimensionMismatchException` - if the dimensions do not match.

#### getL1Distance

    public double getL1Distance(RealVector v)
                         throws DimensionMismatchException

Deprecated.
Distance between two vectors.

This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of the elements differences.

Overrides:
  `getL1Distance` in class `RealVector`
Parameters:
  `v` - Vector to which distance is requested.
Returns:
  the distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as `this` vector.

#### getLInfDistance

    private double getLInfDistance(OpenMapRealVector v)
                            throws DimensionMismatchException

Deprecated.
Optimized method to compute LInfDistance.

Parameters:
  `v` - Vector to compute distance from.
Returns:
  the LInfDistance.
Throws:
  `DimensionMismatchException` - if the dimensions do not match.

#### getLInfDistance

    public double getLInfDistance(RealVector v)
                           throws DimensionMismatchException

Deprecated.
Distance between two vectors.

This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of element differences.

Overrides:
  `getLInfDistance` in class `RealVector`
Parameters:
  `v` - Vector to which distance is requested.
Returns:
  the distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as `this` vector.
See Also:
  `RealVector.getDistance(RealVector)`, `RealVector.getL1Distance(RealVector)`, `RealVector.getLInfNorm()`

#### isInfinite

    public boolean isInfinite()

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

Specified by:
  `isInfinite` in class `RealVector`
Returns:
  `true` if any coordinate of this vector is infinite and none are `NaN`, `false` otherwise.

#### isNaN

    public boolean isNaN()

Deprecated.
Check whether any coordinate of this vector is `NaN`.

Specified by:
  `isNaN` in class `RealVector`
Returns:
  `true` if any coordinate of this vector is `NaN`, `false` otherwise.

#### mapAdd

    public OpenMapRealVector mapAdd(double d)

Deprecated.
Add a value to each entry. Returns a new vector. Does not change instance data.

Overrides:
  `mapAdd` in class `RealVector`
Parameters:
  `d` - Value to be added to each entry.
Returns:
  `this` + `d`.

#### mapAddToSelf

    public OpenMapRealVector mapAddToSelf(double d)

Deprecated.
Add a value to each entry. The instance is changed in-place.

Overrides:
  `mapAddToSelf` in class `RealVector`
Parameters:
  `d` - Value to be added to each entry.
Returns:
  `this`.

#### setEntry

    public void setEntry(int index,
                double value)
                  throws OutOfRangeException

Deprecated.
Set a single element.

Specified by:
  `setEntry` in class `RealVector`
Parameters:
  `index` - element index.
  `value` - new value for the element.
Throws:
  `OutOfRangeException` - if the index is not valid.
See Also:
  `RealVector.getEntry(int)`

#### setSubVector

    public void setSubVector(int index,
                    RealVector v)
                      throws OutOfRangeException

Deprecated.
Set a sequence of consecutive elements.

Specified by:
  `setSubVector` in class `RealVector`
Parameters:
  `index` - index of first element to be set.
  `v` - vector containing the values to set.
Throws:
  `OutOfRangeException` - if the index is not valid.

#### set

    public void set(double value)

Deprecated.
Set all elements to a single value.

Overrides:
  `set` in class `RealVector`
Parameters:
  `value` - Single value to set for all elements.

#### subtract

    public OpenMapRealVector subtract(OpenMapRealVector v)
                               throws DimensionMismatchException

Deprecated.
Optimized method to subtract OpenMapRealVectors.

Parameters:
  `v` - Vector to subtract from `this`.
Returns:
  the difference of `this` and `v`.
Throws:
  `DimensionMismatchException` - if the dimensions do not match.

#### subtract

    public RealVector subtract(RealVector v)
                        throws DimensionMismatchException

Deprecated.
Subtract `v` from this vector. Returns a new vector. Does not change instance data.

Overrides:
  `subtract` in class `RealVector`
Parameters:
  `v` - Vector to be subtracted.
Returns:
  `this` - `v`.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as `this` vector.

#### unitVector

    public OpenMapRealVector unitVector()
                                 throws MathArithmeticException

Deprecated.
Creates a unit vector pointing in the direction of this vector. The instance is not changed by this method.

Overrides:
  `unitVector` in class `RealVector`
Returns:
  a unit vector pointing in direction of this vector.
Throws:
  `MathArithmeticException` - if the norm is zero.

#### unitize

    public void unitize()
                 throws MathArithmeticException

Deprecated.
Converts this vector into a unit vector. The instance itself is changed by this method.

Overrides:
  `unitize` in class `RealVector`
Throws:
  `MathArithmeticException` - if the norm is zero.

#### toArray

    public double[] toArray()

Deprecated.
Convert the vector to an array of `double`s. The array is independent from this vector data: the elements are copied.

Overrides:
  `toArray` in class `RealVector`
Returns:
  an array containing a copy of the vector elements.

#### hashCode

    public int hashCode()

Deprecated.
. This method must be overriden by concrete subclasses of `RealVector` (current implementation throws an exception). 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()`.

Overrides:
  `hashCode` in class `RealVector`

#### equals

    public boolean equals(java.lang.Object obj)

Deprecated.

Test for the equality of two real vectors. If all coordinates of two real vectors are exactly the same, and none are `NaN`, the two real vectors are considered to be equal. `NaN` coordinates are considered to affect globally the vector and be equals to each other - i.e, if either (or all) coordinates of the real vector are equal to `NaN`, the real vector is equal to a vector with all `NaN` coordinates.

This method must be overriden by concrete subclasses of `RealVector` (the current implementation throws an exception).

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`.

Overrides:
  `equals` in class `RealVector`
Parameters:
  `obj` - Object to test for equality.
Returns:
  `true` if two vector objects are equal, `false` if `other` is null, not an instance of `RealVector`, or not equal to this `RealVector` instance.

#### getSparsity

    public double getSparsity()

Deprecated.

Returns:
  the percentage of none zero elements as a decimal percent.
Since:
  2.2

#### sparseIterator

    public java.util.Iterator<RealVector.Entry> sparseIterator()

Deprecated.
Create a sparse iterator over the vector, which may omit some entries. 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 to `RealVector.iterator()`.

Note: derived classes are required to return an `Iterator` that returns non-null `RealVector.Entry` objects as long as `Iterator.hasNext()` returns `true`.

Overrides:
  `sparseIterator` in class `RealVector`
Returns:
  a sparse iterator.