org.apache.commons.math.linear
Class OpenMapRealVector

java.lang.Object
  extended by org.apache.commons.math.linear.OpenMapRealVector
All Implemented Interfaces:
Serializable, RealVector, SparseRealVector

public class OpenMapRealVector
extends Object
implements SparseRealVector, Serializable

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

Since:
2.0
Version:
$Revision: 800111 $ $Date: 2009-08-02 13:23:05 -0400 (Sun, 02 Aug 2009) $
See Also:
Serialized Form

Field Summary
static double DEFAULT_ZERO_TOLERANCE
          Default Tolerance for having a value considered zero.
 
Constructor Summary
  OpenMapRealVector()
          Build a 0-length vector.
  OpenMapRealVector(double[] values)
          Create from a double array.
  OpenMapRealVector(Double[] values)
          Create from a Double array.
  OpenMapRealVector(double[] values, double epsilon)
          Create from a double array, specifying zero tolerance.
  OpenMapRealVector(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.
protected OpenMapRealVector(OpenMapRealVector v, int resize)
          Build a resized vector, for use with append.
  OpenMapRealVector(RealVector v)
          Generic copy constructor.
 
Method Summary
 OpenMapRealVector add(double[] v)
          Compute the sum of this and v.
 OpenMapRealVector add(OpenMapRealVector v)
          Optimized method to add two OpenMapRealVectors.
 OpenMapRealVector add(RealVector v)
          Compute the sum of this 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.
protected  void checkVectorDimensions(int n)
          Check if instance dimension is equal to some expected value.
 OpenMapRealVector copy()
          Returns a (deep) copy of this.
 double dotProduct(double[] v)
          Compute the dot product.
 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(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 getEpsilon()
          Get the tolerance for having a value considered zero.
 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 getL1Norm()
          Returns the L1 norm of the vector.
 double getLInfDistance(double[] v)
          Distance between two vectors.
 double getLInfDistance(RealVector v)
          Distance between two vectors.
 double getLInfNorm()
          Returns the L norm of the vector.
 double getNorm()
          Returns the L2 norm of the vector.
 double getSparcity()
           
 OpenMapRealVector getSubVector(int index, int n)
          Get a subvector from consecutive elements.
 int hashCode()
          
 boolean isInfinite()
          Returns true if any coordinate of this vector is infinite and none are NaN; false otherwise
 boolean isNaN()
          Returns true if any coordinate of this vector is NaN; false otherwise
protected  boolean isZero(double value)
          Determine if this value is zero.
 OpenMapRealVector mapAbs()
          Map the Math.abs(double) function to each entry.
 OpenMapRealVector mapAbsToSelf()
          Map the Math.abs(double) function to each entry.
 OpenMapRealVector mapAcos()
          Map the Math.acos(double) function to each entry.
 OpenMapRealVector mapAcosToSelf()
          Map the Math.acos(double) function to each entry.
 OpenMapRealVector mapAdd(double d)
          Map an addition operation to each entry.
 OpenMapRealVector mapAddToSelf(double d)
          Map an addition operation to each entry.
 OpenMapRealVector mapAsin()
          Map the Math.asin(double) function to each entry.
 OpenMapRealVector mapAsinToSelf()
          Map the Math.asin(double) function to each entry.
 OpenMapRealVector mapAtan()
          Map the Math.atan(double) function to each entry.
 OpenMapRealVector mapAtanToSelf()
          Map the Math.atan(double) function to each entry.
 OpenMapRealVector mapCbrt()
          Map the Math.cbrt(double) function to each entry.
 OpenMapRealVector mapCbrtToSelf()
          Map the Math.cbrt(double) function to each entry.
 OpenMapRealVector mapCeil()
          Map the Math.ceil(double) function to each entry.
 OpenMapRealVector mapCeilToSelf()
          Map the Math.ceil(double) function to each entry.
 OpenMapRealVector mapCos()
          Map the Math.cos(double) function to each entry.
 OpenMapRealVector mapCosh()
          Map the Math.cosh(double) function to each entry.
 OpenMapRealVector mapCoshToSelf()
          Map the Math.cosh(double) function to each entry.
 OpenMapRealVector mapCosToSelf()
          Map the Math.cos(double) function to each entry.
 OpenMapRealVector mapDivide(double d)
          Map a division operation to each entry.
 OpenMapRealVector mapDivideToSelf(double d)
          Map a division operation to each entry.
 OpenMapRealVector mapExp()
          Map the Math.exp(double) function to each entry.
 OpenMapRealVector mapExpm1()
          Map the Math.expm1(double) function to each entry.
 OpenMapRealVector mapExpm1ToSelf()
          Map the Math.expm1(double) function to each entry.
 OpenMapRealVector mapExpToSelf()
          Map the Math.exp(double) function to each entry.
 OpenMapRealVector mapFloor()
          Map the Math.floor(double) function to each entry.
 OpenMapRealVector mapFloorToSelf()
          Map the Math.floor(double) function to each entry.
 OpenMapRealVector mapInv()
          Map the 1/x function to each entry.
 OpenMapRealVector mapInvToSelf()
          Map the 1/x function to each entry.
 OpenMapRealVector mapLog()
          Map the Math.log(double) function to each entry.
 OpenMapRealVector mapLog10()
          Map the Math.log10(double) function to each entry.
 OpenMapRealVector mapLog10ToSelf()
          Map the Math.log10(double) function to each entry.
 OpenMapRealVector mapLog1p()
          Map the Math.log1p(double) function to each entry.
 OpenMapRealVector mapLog1pToSelf()
          Map the Math.log1p(double) function to each entry.
 OpenMapRealVector mapLogToSelf()
          Map the Math.log(double) function to each entry.
 OpenMapRealVector mapMultiply(double d)
          Map a multiplication operation to each entry.
 OpenMapRealVector mapMultiplyToSelf(double d)
          Map a multiplication operation to each entry.
 OpenMapRealVector mapPow(double d)
          Map a power operation to each entry.
 OpenMapRealVector mapPowToSelf(double d)
          Map a power operation to each entry.
 OpenMapRealVector mapRint()
          Map the Math.rint(double) function to each entry.
 OpenMapRealVector mapRintToSelf()
          Map the Math.rint(double) function to each entry.
 OpenMapRealVector mapSignum()
          Map the Math.signum(double) function to each entry.
 OpenMapRealVector mapSignumToSelf()
          Map the Math.signum(double) function to each entry.
 OpenMapRealVector mapSin()
          Map the Math.sin(double) function to each entry.
 OpenMapRealVector mapSinh()
          Map the Math.sinh(double) function to each entry.
 OpenMapRealVector mapSinhToSelf()
          Map the Math.sinh(double) function to each entry.
 OpenMapRealVector mapSinToSelf()
          Map the Math.sin(double) function to each entry.
 OpenMapRealVector mapSqrt()
          Map the Math.sqrt(double) function to each entry.
 OpenMapRealVector mapSqrtToSelf()
          Map the Math.sqrt(double) function to each entry.
 OpenMapRealVector mapSubtract(double d)
          Map a subtraction operation to each entry.
 OpenMapRealVector mapSubtractToSelf(double d)
          Map a subtraction operation to each entry.
 OpenMapRealVector mapTan()
          Map the Math.tan(double) function to each entry.
 OpenMapRealVector mapTanh()
          Map the Math.tanh(double) function to each entry.
 OpenMapRealVector mapTanhToSelf()
          Map the Math.tanh(double) function to each entry.
 OpenMapRealVector mapTanToSelf()
          Map the Math.tan(double) function to each entry.
 OpenMapRealVector mapUlp()
          Map the Math.ulp(double) function to each entry.
 OpenMapRealVector mapUlpToSelf()
          Map the Math.ulp(double) function to each entry.
 RealMatrix outerProduct(double[] v)
          Compute the outer product.
 OpenMapRealMatrix outerproduct(OpenMapRealVector v)
          Optimized method to compute the outer product.
 RealMatrix outerProduct(RealVector 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 setEpsilon(double epsilon)
          Set the tolerance for having a value considered zero.
 void setSubVector(int index, double[] v)
          Set a set of consecutive elements.
 void setSubVector(int index, RealVector v)
          Set a set of consecutive elements.
 OpenMapRealVector subtract(double[] v)
          Compute this minus v.
 OpenMapRealVector subtract(OpenMapRealVector v)
          Optimized method to subtract OpenMapRealVectors.
 OpenMapRealVector subtract(RealVector v)
          Compute this minus v.
 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.
 
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
Default Tolerance for having a value considered zero.

See Also:
Constant Field Values
Constructor Detail

OpenMapRealVector

public OpenMapRealVector()
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(double[]), append(RealVector)) to gather data into this vector.


OpenMapRealVector

public OpenMapRealVector(int dimension)
Construct a (dimension)-length vector of zeros.

Parameters:
dimension - size of the vector

OpenMapRealVector

public OpenMapRealVector(int dimension,
                         double epsilon)
Construct a (dimension)-length vector of zeros, specifying zero tolerance.

Parameters:
dimension - Size of the vector
epsilon - The tolerance for having a value considered zero

OpenMapRealVector

protected OpenMapRealVector(OpenMapRealVector v,
                            int resize)
Build a resized vector, for use with append.

Parameters:
v - The original vector
resize - The amount to resize it

OpenMapRealVector

public OpenMapRealVector(int dimension,
                         int expectedSize)
Build a vector with known the sparseness (for advanced use only).

Parameters:
dimension - The size of the vector
expectedSize - The expected number of non-zero entries

OpenMapRealVector

public OpenMapRealVector(int dimension,
                         int expectedSize,
                         double epsilon)
Build a vector with known the sparseness and zero tolerance setting (for advanced use only).

Parameters:
dimension - The size of the vector
expectedSize - The expected number of non-zero entries
epsilon - The tolerance for having a value considered zero

OpenMapRealVector

public OpenMapRealVector(double[] values)
Create from a double array. Only non-zero entries will be stored

Parameters:
values - The set of values to create from

OpenMapRealVector

public OpenMapRealVector(double[] values,
                         double epsilon)
Create from a double array, specifying zero tolerance. Only non-zero entries will be stored

Parameters:
values - The set of values to create from
epsilon - The tolerance for having a value considered zero

OpenMapRealVector

public OpenMapRealVector(Double[] values)
Create from a Double array. Only non-zero entries will be stored

Parameters:
values - The set of values to create from

OpenMapRealVector

public OpenMapRealVector(Double[] values,
                         double epsilon)
Create from a Double array. Only non-zero entries will be stored

Parameters:
values - The set of values to create from
epsilon - The tolerance for having a value considered zero

OpenMapRealVector

public OpenMapRealVector(OpenMapRealVector v)
Copy constructor.

Parameters:
v - The instance to copy from

OpenMapRealVector

public OpenMapRealVector(RealVector v)
Generic copy constructor.

Parameters:
v - The instance to copy from
Method Detail

isZero

protected boolean isZero(double value)
Determine if this value is zero.

Parameters:
value - The value to test
Returns:
true if this value is zero, false otherwise

getEpsilon

public double getEpsilon()
Get the tolerance for having a value considered zero.

Returns:
The test range for testing if a value is zero

setEpsilon

public void setEpsilon(double epsilon)
Set the tolerance for having a value considered zero.

Parameters:
epsilon - The test range for testing if a value is zero

add

public OpenMapRealVector add(RealVector v)
                      throws IllegalArgumentException
Compute the sum of this and v.

Specified by:
add in interface RealVector
Parameters:
v - vector to be added
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

add

public OpenMapRealVector add(OpenMapRealVector v)
                      throws IllegalArgumentException
Optimized method to add two OpenMapRealVectors.

Parameters:
v - Vector to add with
Returns:
The sum of this with v
Throws:
IllegalArgumentException - If the dimensions don't match

add

public OpenMapRealVector add(double[] v)
                      throws IllegalArgumentException
Compute the sum of this and v.

Specified by:
add in interface RealVector
Parameters:
v - vector to be added
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

append

public OpenMapRealVector append(OpenMapRealVector v)
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)
Construct a vector by appending a vector to this vector.

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

append

public OpenMapRealVector append(double d)
Construct a vector by appending a double to this vector.

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

append

public OpenMapRealVector append(double[] a)
Construct a vector by appending a double array to this vector.

Specified by:
append in interface RealVector
Parameters:
a - double array to append.
Returns:
a new vector

copy

public OpenMapRealVector copy()
Returns a (deep) copy of this.

Specified by:
copy in interface RealVector
Returns:
vector copy

dotProduct

public double dotProduct(RealVector v)
                  throws IllegalArgumentException
Compute the dot product.

Specified by:
dotProduct in interface RealVector
Parameters:
v - vector with which dot product should be computed
Returns:
the scalar dot product between instance and v
Throws:
IllegalArgumentException - if v is not the same size as this

dotProduct

public double dotProduct(double[] v)
                  throws IllegalArgumentException
Compute the dot product.

Specified by:
dotProduct in interface RealVector
Parameters:
v - vector with which dot product should be computed
Returns:
the scalar dot product between instance and v
Throws:
IllegalArgumentException - if v is not the same size as this

ebeDivide

public OpenMapRealVector ebeDivide(RealVector v)
                            throws IllegalArgumentException
Element-by-element division.

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

ebeDivide

public OpenMapRealVector ebeDivide(double[] v)
                            throws IllegalArgumentException
Element-by-element division.

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

ebeMultiply

public OpenMapRealVector ebeMultiply(RealVector v)
                              throws IllegalArgumentException
Element-by-element multiplication.

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

ebeMultiply

public OpenMapRealVector ebeMultiply(double[] v)
                              throws IllegalArgumentException
Element-by-element multiplication.

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

getSubVector

public OpenMapRealVector getSubVector(int index,
                                      int n)
                               throws MatrixIndexException
Get a subvector from consecutive elements.

Specified by:
getSubVector in interface RealVector
Parameters:
index - index of first element.
n - number of elements to be retrieved.
Returns:
a vector containing n elements.
Throws:
MatrixIndexException - if the index is inconsistent with vector size

getData

public double[] getData()
Returns vector entries as a double array.

Specified by:
getData in interface RealVector
Returns:
double array of entries

getDimension

public int getDimension()
Returns the size of the vector.

Specified by:
getDimension in interface RealVector
Returns:
size

getDistance

public double getDistance(OpenMapRealVector v)
                   throws IllegalArgumentException
Optimized method to compute distance.

Parameters:
v - The vector to compute distance to
Returns:
The distance from this and v
Throws:
IllegalArgumentException - If the dimensions don't match

getDistance

public double getDistance(RealVector v)
                   throws IllegalArgumentException
Distance between two vectors.

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

Specified by:
getDistance in interface RealVector
Parameters:
v - vector to which distance is requested
Returns:
distance between two vectors.
Throws:
IllegalArgumentException - if v is not the same size as this
See Also:
RealVector.getL1Distance(RealVector), RealVector.getLInfDistance(RealVector), RealVector.getNorm()

getDistance

public double getDistance(double[] v)
                   throws IllegalArgumentException
Distance between two vectors.

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

Specified by:
getDistance in interface RealVector
Parameters:
v - vector to which distance is requested
Returns:
distance between two vectors.
Throws:
IllegalArgumentException - if v is not the same size as this
See Also:
RealVector.getL1Distance(double[]), RealVector.getLInfDistance(double[]), RealVector.getNorm()

getEntry

public double getEntry(int index)
                throws MatrixIndexException
Returns the entry in the specified index.

The index start at 0 and must be lesser than the size, otherwise a MatrixIndexException is thrown.

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

getL1Distance

public double getL1Distance(OpenMapRealVector v)
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 two vectors.

getL1Distance

public double getL1Distance(RealVector v)
                     throws IllegalArgumentException
Distance between two vectors.

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

Specified by:
getL1Distance in interface RealVector
Parameters:
v - vector to which distance is requested
Returns:
distance between two vectors.
Throws:
IllegalArgumentException - if v is not the same size as this
See Also:
RealVector.getDistance(RealVector), RealVector.getLInfDistance(RealVector), RealVector.getL1Norm()

getL1Distance

public double getL1Distance(double[] v)
                     throws IllegalArgumentException
Distance between two vectors.

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

Specified by:
getL1Distance in interface RealVector
Parameters:
v - vector to which distance is requested
Returns:
distance between two vectors.
Throws:
IllegalArgumentException - if v is not the same size as this
See Also:
RealVector.getDistance(double[]), RealVector.getLInfDistance(double[]), RealVector.getL1Norm()

getL1Norm

public double getL1Norm()
Returns the L1 norm of the vector.

The L1 norm is the sum of the absolute values of elements.

Specified by:
getL1Norm in interface RealVector
Returns:
norm
See Also:
RealVector.getNorm(), RealVector.getLInfNorm(), RealVector.getL1Distance(RealVector)

getLInfDistance

public double getLInfDistance(RealVector v)
                       throws IllegalArgumentException
Distance between two vectors.

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

Specified by:
getLInfDistance in interface RealVector
Parameters:
v - vector to which distance is requested
Returns:
distance between two vectors.
Throws:
IllegalArgumentException - if v is not the same size as this
See Also:
RealVector.getDistance(RealVector), RealVector.getL1Distance(RealVector), RealVector.getLInfNorm()

getLInfDistance

public double getLInfDistance(double[] v)
                       throws IllegalArgumentException
Distance between two vectors.

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

Specified by:
getLInfDistance in interface RealVector
Parameters:
v - vector to which distance is requested
Returns:
distance between two vectors.
Throws:
IllegalArgumentException - if v is not the same size as this
See Also:
RealVector.getDistance(double[]), RealVector.getL1Distance(double[]), RealVector.getLInfNorm()

getLInfNorm

public double getLInfNorm()
Returns the L norm of the vector.

The L norm is the max of the absolute values of elements.

Specified by:
getLInfNorm in interface RealVector
Returns:
norm
See Also:
RealVector.getNorm(), RealVector.getL1Norm(), RealVector.getLInfDistance(RealVector)

getNorm

public double getNorm()
Returns the L2 norm of the vector.

The L2 norm is the root of the sum of the squared elements.

Specified by:
getNorm in interface RealVector
Returns:
norm
See Also:
RealVector.getL1Norm(), RealVector.getLInfNorm(), RealVector.getDistance(RealVector)

isInfinite

public boolean isInfinite()
Returns true if any coordinate of this vector is infinite and none are NaN; false otherwise

Specified by:
isInfinite in interface RealVector
Returns:
true if any coordinate of this vector is infinite and none are NaN; false otherwise

isNaN

public boolean isNaN()
Returns true if any coordinate of this vector is NaN; false otherwise

Specified by:
isNaN in interface RealVector
Returns:
true if any coordinate of this vector is NaN; false otherwise

mapAbs

public OpenMapRealVector mapAbs()
Map the Math.abs(double) function to each entry.

Specified by:
mapAbs in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapAbsToSelf

public OpenMapRealVector mapAbsToSelf()
Map the Math.abs(double) function to each entry.

The instance is changed by this method.

Specified by:
mapAbsToSelf in interface RealVector
Returns:
for convenience, return this

mapAcos

public OpenMapRealVector mapAcos()
Map the Math.acos(double) function to each entry.

Specified by:
mapAcos in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapAcosToSelf

public OpenMapRealVector mapAcosToSelf()
Map the Math.acos(double) function to each entry.

The instance is changed by this method.

Specified by:
mapAcosToSelf in interface RealVector
Returns:
for convenience, return this

mapAdd

public OpenMapRealVector mapAdd(double d)
Map an addition operation to each entry.

Specified by:
mapAdd in interface RealVector
Parameters:
d - value to be added to each entry
Returns:
this + d

mapAddToSelf

public OpenMapRealVector mapAddToSelf(double d)
Map an addition operation to each entry.

The instance is changed by this method.

Specified by:
mapAddToSelf in interface RealVector
Parameters:
d - value to be added to each entry
Returns:
for convenience, return this

mapAsin

public OpenMapRealVector mapAsin()
Map the Math.asin(double) function to each entry.

Specified by:
mapAsin in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapAsinToSelf

public OpenMapRealVector mapAsinToSelf()
Map the Math.asin(double) function to each entry.

The instance is changed by this method.

Specified by:
mapAsinToSelf in interface RealVector
Returns:
for convenience, return this

mapAtan

public OpenMapRealVector mapAtan()
Map the Math.atan(double) function to each entry.

Specified by:
mapAtan in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapAtanToSelf

public OpenMapRealVector mapAtanToSelf()
Map the Math.atan(double) function to each entry.

The instance is changed by this method.

Specified by:
mapAtanToSelf in interface RealVector
Returns:
for convenience, return this

mapCbrt

public OpenMapRealVector mapCbrt()
Map the Math.cbrt(double) function to each entry.

Specified by:
mapCbrt in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapCbrtToSelf

public OpenMapRealVector mapCbrtToSelf()
Map the Math.cbrt(double) function to each entry.

The instance is changed by this method.

Specified by:
mapCbrtToSelf in interface RealVector
Returns:
for convenience, return this

mapCeil

public OpenMapRealVector mapCeil()
Map the Math.ceil(double) function to each entry.

Specified by:
mapCeil in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapCeilToSelf

public OpenMapRealVector mapCeilToSelf()
Map the Math.ceil(double) function to each entry.

The instance is changed by this method.

Specified by:
mapCeilToSelf in interface RealVector
Returns:
for convenience, return this

mapCos

public OpenMapRealVector mapCos()
Map the Math.cos(double) function to each entry.

Specified by:
mapCos in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapCosToSelf

public OpenMapRealVector mapCosToSelf()
Map the Math.cos(double) function to each entry.

The instance is changed by this method.

Specified by:
mapCosToSelf in interface RealVector
Returns:
for convenience, return this

mapCosh

public OpenMapRealVector mapCosh()
Map the Math.cosh(double) function to each entry.

Specified by:
mapCosh in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapCoshToSelf

public OpenMapRealVector mapCoshToSelf()
Map the Math.cosh(double) function to each entry.

The instance is changed by this method.

Specified by:
mapCoshToSelf in interface RealVector
Returns:
for convenience, return this

mapDivide

public OpenMapRealVector mapDivide(double d)
Map a division operation to each entry.

Specified by:
mapDivide in interface RealVector
Parameters:
d - value to divide all entries by
Returns:
this / d

mapDivideToSelf

public OpenMapRealVector mapDivideToSelf(double d)
Map a division operation to each entry.

The instance is changed by this method.

Specified by:
mapDivideToSelf in interface RealVector
Parameters:
d - value to divide all entries by
Returns:
for convenience, return this

mapExp

public OpenMapRealVector mapExp()
Map the Math.exp(double) function to each entry.

Specified by:
mapExp in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapExpToSelf

public OpenMapRealVector mapExpToSelf()
Map the Math.exp(double) function to each entry.

The instance is changed by this method.

Specified by:
mapExpToSelf in interface RealVector
Returns:
for convenience, return this

mapExpm1

public OpenMapRealVector mapExpm1()
Map the Math.expm1(double) function to each entry.

Specified by:
mapExpm1 in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapExpm1ToSelf

public OpenMapRealVector mapExpm1ToSelf()
Map the Math.expm1(double) function to each entry.

The instance is changed by this method.

Specified by:
mapExpm1ToSelf in interface RealVector
Returns:
for convenience, return this

mapFloor

public OpenMapRealVector mapFloor()
Map the Math.floor(double) function to each entry.

Specified by:
mapFloor in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapFloorToSelf

public OpenMapRealVector mapFloorToSelf()
Map the Math.floor(double) function to each entry.

The instance is changed by this method.

Specified by:
mapFloorToSelf in interface RealVector
Returns:
for convenience, return this

mapInv

public OpenMapRealVector mapInv()
Map the 1/x function to each entry.

Specified by:
mapInv in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapInvToSelf

public OpenMapRealVector mapInvToSelf()
Map the 1/x function to each entry.

The instance is changed by this method.

Specified by:
mapInvToSelf in interface RealVector
Returns:
for convenience, return this

mapLog

public OpenMapRealVector mapLog()
Map the Math.log(double) function to each entry.

Specified by:
mapLog in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapLog10

public OpenMapRealVector mapLog10()
Map the Math.log10(double) function to each entry.

Specified by:
mapLog10 in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapLog10ToSelf

public OpenMapRealVector mapLog10ToSelf()
Map the Math.log10(double) function to each entry.

The instance is changed by this method.

Specified by:
mapLog10ToSelf in interface RealVector
Returns:
for convenience, return this

mapLog1p

public OpenMapRealVector mapLog1p()
Map the Math.log1p(double) function to each entry.

Specified by:
mapLog1p in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapLog1pToSelf

public OpenMapRealVector mapLog1pToSelf()
Map the Math.log1p(double) function to each entry.

The instance is changed by this method.

Specified by:
mapLog1pToSelf in interface RealVector
Returns:
for convenience, return this

mapLogToSelf

public OpenMapRealVector mapLogToSelf()
Map the Math.log(double) function to each entry.

The instance is changed by this method.

Specified by:
mapLogToSelf in interface RealVector
Returns:
for convenience, return this

mapMultiply

public OpenMapRealVector mapMultiply(double d)
Map a multiplication operation to each entry.

Specified by:
mapMultiply in interface RealVector
Parameters:
d - value to multiply all entries by
Returns:
this * d

mapMultiplyToSelf

public OpenMapRealVector mapMultiplyToSelf(double d)
Map a multiplication operation to each entry.

The instance is changed by this method.

Specified by:
mapMultiplyToSelf in interface RealVector
Parameters:
d - value to multiply all entries by
Returns:
for convenience, return this

mapPow

public OpenMapRealVector mapPow(double d)
Map a power operation to each entry.

Specified by:
mapPow in interface RealVector
Parameters:
d - value to raise all entries to
Returns:
this ^ d

mapPowToSelf

public OpenMapRealVector mapPowToSelf(double d)
Map a power operation to each entry.

The instance is changed by this method.

Specified by:
mapPowToSelf in interface RealVector
Parameters:
d - value to raise all entries to
Returns:
for convenience, return this

mapRint

public OpenMapRealVector mapRint()
Map the Math.rint(double) function to each entry.

Specified by:
mapRint in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapRintToSelf

public OpenMapRealVector mapRintToSelf()
Map the Math.rint(double) function to each entry.

The instance is changed by this method.

Specified by:
mapRintToSelf in interface RealVector
Returns:
for convenience, return this

mapSignum

public OpenMapRealVector mapSignum()
Map the Math.signum(double) function to each entry.

Specified by:
mapSignum in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapSignumToSelf

public OpenMapRealVector mapSignumToSelf()
Map the Math.signum(double) function to each entry.

The instance is changed by this method.

Specified by:
mapSignumToSelf in interface RealVector
Returns:
for convenience, return this

mapSin

public OpenMapRealVector mapSin()
Map the Math.sin(double) function to each entry.

Specified by:
mapSin in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapSinToSelf

public OpenMapRealVector mapSinToSelf()
Map the Math.sin(double) function to each entry.

The instance is changed by this method.

Specified by:
mapSinToSelf in interface RealVector
Returns:
for convenience, return this

mapSinh

public OpenMapRealVector mapSinh()
Map the Math.sinh(double) function to each entry.

Specified by:
mapSinh in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapSinhToSelf

public OpenMapRealVector mapSinhToSelf()
Map the Math.sinh(double) function to each entry.

The instance is changed by this method.

Specified by:
mapSinhToSelf in interface RealVector
Returns:
for convenience, return this

mapSqrt

public OpenMapRealVector mapSqrt()
Map the Math.sqrt(double) function to each entry.

Specified by:
mapSqrt in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapSqrtToSelf

public OpenMapRealVector mapSqrtToSelf()
Map the Math.sqrt(double) function to each entry.

The instance is changed by this method.

Specified by:
mapSqrtToSelf in interface RealVector
Returns:
for convenience, return this

mapSubtract

public OpenMapRealVector mapSubtract(double d)
Map a subtraction operation to each entry.

Specified by:
mapSubtract in interface RealVector
Parameters:
d - value to be subtracted to each entry
Returns:
this - d

mapSubtractToSelf

public OpenMapRealVector mapSubtractToSelf(double d)
Map a subtraction operation to each entry.

The instance is changed by this method.

Specified by:
mapSubtractToSelf in interface RealVector
Parameters:
d - value to be subtracted to each entry
Returns:
for convenience, return this

mapTan

public OpenMapRealVector mapTan()
Map the Math.tan(double) function to each entry.

Specified by:
mapTan in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapTanToSelf

public OpenMapRealVector mapTanToSelf()
Map the Math.tan(double) function to each entry.

The instance is changed by this method.

Specified by:
mapTanToSelf in interface RealVector
Returns:
for convenience, return this

mapTanh

public OpenMapRealVector mapTanh()
Map the Math.tanh(double) function to each entry.

Specified by:
mapTanh in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapTanhToSelf

public OpenMapRealVector mapTanhToSelf()
Map the Math.tanh(double) function to each entry.

The instance is changed by this method.

Specified by:
mapTanhToSelf in interface RealVector
Returns:
for convenience, return this

mapUlp

public OpenMapRealVector mapUlp()
Map the Math.ulp(double) function to each entry.

Specified by:
mapUlp in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapUlpToSelf

public OpenMapRealVector mapUlpToSelf()
Map the Math.ulp(double) function to each entry.

The instance is changed by this method.

Specified by:
mapUlpToSelf in interface RealVector
Returns:
for convenience, return this

outerproduct

public OpenMapRealMatrix outerproduct(OpenMapRealVector v)
                               throws IllegalArgumentException
Optimized method to compute the outer product.

Parameters:
v - The vector to comput the outer product on
Returns:
The outer product of this and v
Throws:
IllegalArgumentException - If the dimensions don't match

outerProduct

public RealMatrix outerProduct(RealVector v)
                        throws IllegalArgumentException
Compute the outer product.

Specified by:
outerProduct in interface RealVector
Parameters:
v - vector with which outer product should be computed
Returns:
the square matrix outer product between instance and v
Throws:
IllegalArgumentException - if v is not the same size as this

outerProduct

public RealMatrix outerProduct(double[] v)
                        throws IllegalArgumentException
Compute the outer product.

Specified by:
outerProduct in interface RealVector
Parameters:
v - vector with which outer product should be computed
Returns:
the square matrix outer product between instance and v
Throws:
IllegalArgumentException - if v is not the same size as this

projection

public RealVector projection(RealVector v)
                      throws IllegalArgumentException
Find the orthogonal projection of this vector onto another vector.

Specified by:
projection in interface RealVector
Parameters:
v - vector onto which instance must be projected
Returns:
projection of the instance onto v
Throws:
IllegalArgumentException - if v is not the same size as this

projection

public OpenMapRealVector projection(double[] v)
                             throws IllegalArgumentException
Find the orthogonal projection of this vector onto another vector.

Specified by:
projection in interface RealVector
Parameters:
v - vector onto which instance must be projected
Returns:
projection of the instance onto v
Throws:
IllegalArgumentException - if v is not the same size as this

setEntry

public void setEntry(int index,
                     double value)
              throws MatrixIndexException
Set a single element.

Specified by:
setEntry in interface RealVector
Parameters:
index - element index.
value - new value for the element.
Throws:
MatrixIndexException - if the index is inconsistent with vector size
See Also:
RealVector.getEntry(int)

setSubVector

public void setSubVector(int index,
                         RealVector v)
                  throws MatrixIndexException
Set a set of consecutive elements.

Specified by:
setSubVector in interface RealVector
Parameters:
index - index of first element to be set.
v - vector containing the values to set.
Throws:
MatrixIndexException - if the index is inconsistent with vector size
See Also:
RealVector.setSubVector(int, double[])

setSubVector

public void setSubVector(int index,
                         double[] v)
                  throws MatrixIndexException
Set a set of consecutive elements.

Specified by:
setSubVector in interface RealVector
Parameters:
index - index of first element to be set.
v - vector containing the values to set.
Throws:
MatrixIndexException - if the index is inconsistent with vector size
See Also:
RealVector.setSubVector(int, RealVector)

set

public void set(double value)
Set all elements to a single value.

Specified by:
set in interface RealVector
Parameters:
value - single value to set for all elements

subtract

public OpenMapRealVector subtract(OpenMapRealVector v)
                           throws IllegalArgumentException
Optimized method to subtract OpenMapRealVectors.

Parameters:
v - The vector to subtract from this
Returns:
The difference of this and v
Throws:
IllegalArgumentException - If the dimensions don't match

subtract

public OpenMapRealVector subtract(RealVector v)
                           throws IllegalArgumentException
Compute this minus v.

Specified by:
subtract in interface RealVector
Parameters:
v - vector to be subtracted
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

subtract

public OpenMapRealVector subtract(double[] v)
                           throws IllegalArgumentException
Compute this minus v.

Specified by:
subtract in interface RealVector
Parameters:
v - vector to be subtracted
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

unitVector

public OpenMapRealVector unitVector()
Creates a unit vector pointing in the direction of this vector.

The instance is not changed by this method.

Specified by:
unitVector in interface RealVector
Returns:
a unit vector pointing in direction of this vector

unitize

public void unitize()
Converts this vector into a unit vector.

The instance itself is changed by this method.

Specified by:
unitize in interface RealVector

checkVectorDimensions

protected void checkVectorDimensions(int n)
                              throws IllegalArgumentException
Check if instance dimension is equal to some expected value.

Parameters:
n - expected dimension.
Throws:
IllegalArgumentException - if the dimension is inconsistent with vector size

toArray

public double[] toArray()
Convert the vector to a double array.

The array is independent from vector data, it's elements are copied.

Specified by:
toArray in interface RealVector
Returns:
array containing a copy of vector elements

hashCode

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

Overrides:
hashCode in class Object

equals

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

Overrides:
equals in class Object

getSparcity

public double getSparcity()
Returns:
the percentage of none zero elements as a decimal percent.


Copyright © 2003-2009 Apache Software Foundation. All Rights Reserved.