org.apache.commons.math.linear
Class AbstractRealVector

java.lang.Object
  extended by org.apache.commons.math.linear.AbstractRealVector
All Implemented Interfaces:
RealVector
Direct Known Subclasses:
ArrayRealVector, OpenMapRealVector

public abstract class AbstractRealVector
extends Object
implements RealVector

This class provides default basic implementations for many methods in the RealVector interface with.

Since:
2.1
Version:
$Revision: 904231 $ $Date: 2010-01-28 14:42:31 -0500 (Thu, 28 Jan 2010) $

Nested Class Summary
protected  class AbstractRealVector.EntryImpl
          An entry in the vector.
protected  class AbstractRealVector.SparseEntryIterator
          This class should rare be used, but is here to provide a default implementation of sparseIterator(), which is implemented by walking over the entries, skipping those whose values are the default one.
 
Nested classes/interfaces inherited from interface org.apache.commons.math.linear.RealVector
RealVector.Entry
 
Constructor Summary
AbstractRealVector()
           
 
Method Summary
 RealVector add(double[] v)
          Compute the sum of this and v.
 RealVector add(RealVector v)
          Compute the sum of this and v.
protected  void checkIndex(int index)
          Check if an index is valid.
protected  void checkVectorDimensions(int n)
          Check if instance dimension is equal to some expected value.
protected  void checkVectorDimensions(RealVector v)
          Check if instance and specified vectors have the same dimension.
abstract  AbstractRealVector copy()
          Returns a (deep) copy of this.
 double dotProduct(double[] v)
          Compute the dot product.
 double dotProduct(RealVector v)
          Compute the dot product.
 RealVector ebeDivide(double[] v)
          Element-by-element division.
 RealVector ebeMultiply(double[] v)
          Element-by-element multiplication.
 double[] getData()
          Returns vector entries as a double array.
 double getDistance(double[] v)
          Distance between two vectors.
 double getDistance(RealVector v)
          Distance between two vectors.
 double getL1Distance(double[] 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.
 int getMaxIndex()
          Get the index of the maximum entry.
 double getMaxValue()
          Get the value of the maximum entry.
 int getMinIndex()
          Get the index of the minimum entry.
 double getMinValue()
          Get the value of the minimum entry.
 double getNorm()
          Returns the L2 norm of the vector.
 Iterator<RealVector.Entry> iterator()
          Generic dense iterator - starts with index == zero, and hasNext() == true until index == getDimension();
 RealVector map(UnivariateRealFunction function)
          Acts as if implemented as: return copy().map(function);
 RealVector mapAbs()
          Map the Math.abs(double) function to each entry.
 RealVector mapAbsToSelf()
          Map the Math.abs(double) function to each entry.
 RealVector mapAcos()
          Map the Math.acos(double) function to each entry.
 RealVector mapAcosToSelf()
          Map the Math.acos(double) function to each entry.
 RealVector mapAdd(double d)
          Map an addition operation to each entry.
 RealVector mapAddToSelf(double d)
          Map an addition operation to each entry.
 RealVector mapAsin()
          Map the Math.asin(double) function to each entry.
 RealVector mapAsinToSelf()
          Map the Math.asin(double) function to each entry.
 RealVector mapAtan()
          Map the Math.atan(double) function to each entry.
 RealVector mapAtanToSelf()
          Map the Math.atan(double) function to each entry.
 RealVector mapCbrt()
          Map the Math.cbrt(double) function to each entry.
 RealVector mapCbrtToSelf()
          Map the Math.cbrt(double) function to each entry.
 RealVector mapCeil()
          Map the Math.ceil(double) function to each entry.
 RealVector mapCeilToSelf()
          Map the Math.ceil(double) function to each entry.
 RealVector mapCos()
          Map the Math.cos(double) function to each entry.
 RealVector mapCosh()
          Map the Math.cosh(double) function to each entry.
 RealVector mapCoshToSelf()
          Map the Math.cosh(double) function to each entry.
 RealVector mapCosToSelf()
          Map the Math.cos(double) function to each entry.
 RealVector mapDivide(double d)
          Map a division operation to each entry.
 RealVector mapDivideToSelf(double d)
          Map a division operation to each entry.
 RealVector mapExp()
          Map the Math.exp(double) function to each entry.
 RealVector mapExpm1()
          Map the Math.expm1(double) function to each entry.
 RealVector mapExpm1ToSelf()
          Map the Math.expm1(double) function to each entry.
 RealVector mapExpToSelf()
          Map the Math.exp(double) function to each entry.
 RealVector mapFloor()
          Map the Math.floor(double) function to each entry.
 RealVector mapFloorToSelf()
          Map the Math.floor(double) function to each entry.
 RealVector mapInv()
          Map the 1/x function to each entry.
 RealVector mapInvToSelf()
          Map the 1/x function to each entry.
 RealVector mapLog()
          Map the Math.log(double) function to each entry.
 RealVector mapLog10()
          Map the Math.log10(double) function to each entry.
 RealVector mapLog10ToSelf()
          Map the Math.log10(double) function to each entry.
 RealVector mapLog1p()
          Map the Math.log1p(double) function to each entry.
 RealVector mapLog1pToSelf()
          Map the Math.log1p(double) function to each entry.
 RealVector mapLogToSelf()
          Map the Math.log(double) function to each entry.
 RealVector mapMultiply(double d)
          Map a multiplication operation to each entry.
 RealVector mapMultiplyToSelf(double d)
          Map a multiplication operation to each entry.
 RealVector mapPow(double d)
          Map a power operation to each entry.
 RealVector mapPowToSelf(double d)
          Map a power operation to each entry.
 RealVector mapRint()
          Map the Math.rint(double) function to each entry.
 RealVector mapRintToSelf()
          Map the Math.rint(double) function to each entry.
 RealVector mapSignum()
          Map the Math.signum(double) function to each entry.
 RealVector mapSignumToSelf()
          Map the Math.signum(double) function to each entry.
 RealVector mapSin()
          Map the Math.sin(double) function to each entry.
 RealVector mapSinh()
          Map the Math.sinh(double) function to each entry.
 RealVector mapSinhToSelf()
          Map the Math.sinh(double) function to each entry.
 RealVector mapSinToSelf()
          Map the Math.sin(double) function to each entry.
 RealVector mapSqrt()
          Map the Math.sqrt(double) function to each entry.
 RealVector mapSqrtToSelf()
          Map the Math.sqrt(double) function to each entry.
 RealVector mapSubtract(double d)
          Map a subtraction operation to each entry.
 RealVector mapSubtractToSelf(double d)
          Map a subtraction operation to each entry.
 RealVector mapTan()
          Map the Math.tan(double) function to each entry.
 RealVector mapTanh()
          Map the Math.tanh(double) function to each entry.
 RealVector mapTanhToSelf()
          Map the Math.tanh(double) function to each entry.
 RealVector mapTanToSelf()
          Map the Math.tan(double) function to each entry.
 RealVector mapToSelf(UnivariateRealFunction function)
          Acts as if it is implemented as: Entry e = null; for(Iterator it = iterator(); it.hasNext(); e = it.next()) { e.setValue(function.value(e.getValue())); }
 RealVector mapUlp()
          Map the Math.ulp(double) function to each entry.
 RealVector mapUlpToSelf()
          Map the Math.ulp(double) function to each entry.
 RealMatrix outerProduct(double[] v)
          Compute the outer product.
 RealMatrix outerProduct(RealVector v)
          Compute the outer product.
 RealVector projection(double[] v)
          Find the orthogonal projection of this vector onto another vector.
 void set(double value)
          Set all elements to a single value.
 void setSubVector(int index, double[] v)
          Set a set of consecutive elements.
 void setSubVector(int index, RealVector v)
          Set a set of consecutive elements.
 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.
 RealVector subtract(double[] v)
          Compute this minus v.
 RealVector 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.
 RealVector unitVector()
          Creates a unit vector pointing in the direction of this vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.math.linear.RealVector
append, append, append, ebeDivide, ebeMultiply, getDimension, getEntry, getSubVector, isInfinite, isNaN, projection, setEntry
 

Constructor Detail

AbstractRealVector

public AbstractRealVector()
Method Detail

checkVectorDimensions

protected void checkVectorDimensions(RealVector v)
Check if instance and specified vectors have the same dimension.

Parameters:
v - vector to compare instance with
Throws:
IllegalArgumentException - if the vectors do not have the same dimension

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

checkIndex

protected void checkIndex(int index)
                   throws MatrixIndexException
Check if an index is valid.

Parameters:
index - index to check
Throws:
MatrixIndexException - if index is not valid

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)

add

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

add

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

subtract

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

subtract

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

mapAdd

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

copy

public abstract AbstractRealVector copy()
Returns a (deep) copy of this.

Specified by:
copy in interface RealVector
Returns:
vector copy

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

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

ebeDivide

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

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

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)

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)

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)

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

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

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

getMinIndex

public int getMinIndex()
Get the index of the minimum entry.

Returns:
index of the minimum entry or -1 if vector length is 0 or all entries are NaN

getMinValue

public double getMinValue()
Get the value of the minimum entry.

Returns:
value of the minimum entry or NaN if all entries are NaN

getMaxIndex

public int getMaxIndex()
Get the index of the maximum entry.

Returns:
index of the maximum entry or -1 if vector length is 0 or all entries are NaN

getMaxValue

public double getMaxValue()
Get the value of the maximum entry.

Returns:
value of the maximum entry or NaN if all entries are NaN

mapAbs

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

mapAsin

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

mapLogToSelf

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

mapLog10

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

mapMultiply

public RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 RealVector 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 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(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

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

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

getData

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

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

unitVector

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

sparseIterator

public 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. No guarantees are made about order of iteration. In dense implementations, this method will often delegate to RealVector.iterator()

Specified by:
sparseIterator in interface RealVector
Returns:
a sparse iterator

iterator

public Iterator<RealVector.Entry> iterator()
Generic dense iterator - starts with index == zero, and hasNext() == true until index == getDimension();

Specified by:
iterator in interface RealVector
Returns:
a dense iterator

map

public RealVector map(UnivariateRealFunction function)
               throws FunctionEvaluationException
Acts as if implemented as: return copy().map(function);

Specified by:
map in interface RealVector
Parameters:
function - to apply to each successive entry
Returns:
a new vector
Throws:
FunctionEvaluationException - if function throws it on application to any entry

mapToSelf

public RealVector mapToSelf(UnivariateRealFunction function)
                     throws FunctionEvaluationException
Acts as if it is implemented as: Entry e = null; for(Iterator it = iterator(); it.hasNext(); e = it.next()) { e.setValue(function.value(e.getValue())); }

Specified by:
mapToSelf in interface RealVector
Parameters:
function - to apply to each successive entry
Returns:
this vector
Throws:
FunctionEvaluationException - if function throws it on application to any entry


Copyright © 2003-2010 The Apache Software Foundation. All Rights Reserved.