Class AbstractRealVector
- All Implemented Interfaces:
RealVector
- Direct Known Subclasses:
ArrayRealVector,OpenMapRealVector
RealVector interface.- Since:
- 2.1
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.commons.math.linear.RealVector
RealVector.Entry -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double[] v) Compute the sum of this vector andv.add(RealVector v) Compute the sum of this vector andv.abstract AbstractRealVectorcopy()Returns a (deep) copy of this vector.doubledotProduct(double[] v) Compute the dot product.doubleCompute the dot product.ebeDivide(double[] v) Element-by-element division.ebeMultiply(double[] v) Element-by-element multiplication.double[]getData()Returns vector entries as a double array.doublegetDistance(double[] v) Distance between two vectors.doubleDistance between two vectors.doublegetL1Distance(double[] v) Distance between two vectors.doubleDistance between two vectors.doubleReturns the L1 norm of the vector.doublegetLInfDistance(double[] v) Distance between two vectors.doubleDistance between two vectors.doubleReturns the L∞ norm of the vector.intGet the index of the maximum entry.doubleGet the value of the maximum entry.intGet the index of the minimum entry.doubleGet the value of the minimum entry.doublegetNorm()Returns the L2 norm of the vector.iterator()Generic dense iterator.map(UnivariateRealFunction function) Acts as if implemented as:mapAbs()Map theMath.abs(double)function to each entry.Map theMath.abs(double)function to each entry.mapAcos()Map theMath.acos(double)function to each entry.Map theMath.acos(double)function to each entry.mapAdd(double d) Add a value to each entry.mapAddToSelf(double d) Add a value to each entry.mapAsin()Map theMath.asin(double)function to each entry.Map theMath.asin(double)function to each entry.mapAtan()Map theMath.atan(double)function to each entry.Map theMath.atan(double)function to each entry.mapCbrt()Map theMath.cbrt(double)function to each entry.Map theMath.cbrt(double)function to each entry.mapCeil()Map theMath.ceil(double)function to each entry.Map theMath.ceil(double)function to each entry.mapCos()Map theMath.cos(double)function to each entry.mapCosh()Map theMath.cosh(double)function to each entry.Map theMath.cosh(double)function to each entry.Map theMath.cos(double)function to each entry.mapDivide(double d) Divide each entry.mapDivideToSelf(double d) Divide each entry.mapExp()Map theMath.exp(double)function to each entry.mapExpm1()Map theMath.expm1(double)function to each entry.Map theMath.expm1(double)function to each entry.MapMath.exp(double)operation to each entry.mapFloor()Map theMath.floor(double)function to each entry.Map theMath.floor(double)function to each entry.mapInv()Map the 1/x function to each entry.Map the 1/x function to each entry.mapLog()Map theMath.log(double)function to each entry.mapLog10()Map theMath.log10(double)function to each entry.Map theMath.log10(double)function to each entry.mapLog1p()Map theMath.log1p(double)function to each entry.Map theMath.log1p(double)function to each entry.Map theMath.log(double)function to each entry.mapMultiply(double d) Multiply each entry.mapMultiplyToSelf(double d) Multiply each entry.mapPow(double d) Map a power operation to each entry.mapPowToSelf(double d) Map a power operation to each entry.mapRint()Map theMath.rint(double)function to each entry.Map theMath.rint(double)function to each entry.Map theMath.signum(double)function to each entry.Map theMath.signum(double)function to each entry.mapSin()Map theMath.sin(double)function to each entry.mapSinh()Map theMath.sinh(double)function to each entry.Map theMath.sinh(double)function to each entry.Map theMath.sin(double)function to each entry.mapSqrt()Map theMath.sqrt(double)function to each entry.Map theMath.sqrt(double)function to each entry.mapSubtract(double d) Subtract a value from each entry.mapSubtractToSelf(double d) Subtract a value from each entry.mapTan()Map theMath.tan(double)function to each entry.mapTanh()Map theMath.tanh(double)function to each entry.Map theMath.tanh(double)function to each entry.Map theMath.tan(double)function to each entry.mapToSelf(UnivariateRealFunction function) Acts as if it is implemented as:mapUlp()Map theMath.ulp(double)function to each entry.Map theMath.ulp(double)function to each entry.outerProduct(double[] v) Compute the outer product.Compute the outer product.projection(double[] v) Find the orthogonal projection of this vector onto another vector.voidset(double value) Set all elements to a single value.voidsetSubVector(int index, double[] v) Set a set of consecutive elements.voidsetSubVector(int index, RealVector v) Set a set of consecutive elements.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.subtract(double[] v) Subtractvfrom this vector.Subtractvfrom this vector.double[]toArray()Convert the vector to a double array.voidunitize()Converts this vector into a unit vector.Creates a unit vector pointing in the direction of this vector.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.math.linear.RealVector
append, append, append, ebeDivide, ebeMultiply, getDimension, getEntry, getSubVector, isInfinite, isNaN, projection, setEntry
-
Constructor Details
-
AbstractRealVector
public AbstractRealVector()
-
-
Method Details
-
setSubVector
Set a set of consecutive elements.- Specified by:
setSubVectorin interfaceRealVector- Parameters:
index- index of first element to be set.v- vector containing the values to set.- Throws:
MatrixIndexException- See Also:
-
setSubVector
Set a set of consecutive elements.- Specified by:
setSubVectorin interfaceRealVector- Parameters:
index- index of first element to be set.v- vector containing the values to set.- Throws:
MatrixIndexException- See Also:
-
add
Compute the sum of this vector andv.- Specified by:
addin interfaceRealVector- Parameters:
v- Vector to be added.- Returns:
this+v.- Throws:
IllegalArgumentException
-
add
Compute the sum of this vector andv.- Specified by:
addin interfaceRealVector- Parameters:
v- Vector to be added.- Returns:
this+v.- Throws:
IllegalArgumentException
-
subtract
Subtractvfrom this vector.- Specified by:
subtractin interfaceRealVector- Parameters:
v- Vector to be subtracted.- Returns:
this-v.- Throws:
IllegalArgumentException
-
subtract
Subtractvfrom this vector.- Specified by:
subtractin interfaceRealVector- Parameters:
v- Vector to be subtracted.- Returns:
this-v.- Throws:
IllegalArgumentException
-
mapAdd
Add a value to each entry.- Specified by:
mapAddin interfaceRealVector- Parameters:
d- Value to be added to each entry.- Returns:
this+d.
-
mapAddToSelf
Add a value to each entry. The instance is changed in-place.- Specified by:
mapAddToSelfin interfaceRealVector- Parameters:
d- Value to be added to each entry.- Returns:
this.
-
copy
Returns a (deep) copy of this vector.- Specified by:
copyin interfaceRealVector- Returns:
- a vector copy.
-
dotProduct
Compute the dot product.- Specified by:
dotProductin interfaceRealVector- Parameters:
v- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
IllegalArgumentException
-
dotProduct
Compute the dot product.- Specified by:
dotProductin interfaceRealVector- Parameters:
v- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
IllegalArgumentException
-
ebeDivide
Element-by-element division.- Specified by:
ebeDividein interfaceRealVector- Parameters:
v- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
IllegalArgumentException
-
ebeMultiply
Element-by-element multiplication.- Specified by:
ebeMultiplyin interfaceRealVector- Parameters:
v- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
IllegalArgumentException
-
getDistance
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:
getDistancein interfaceRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
IllegalArgumentException- See Also:
-
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:
getNormin interfaceRealVector- Returns:
- norm
- See Also:
-
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:
getL1Normin interfaceRealVector- Returns:
- norm
- See Also:
-
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:
getLInfNormin interfaceRealVector- Returns:
- norm
- See Also:
-
getDistance
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:
getDistancein interfaceRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
IllegalArgumentException- See Also:
-
getL1Distance
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:
getL1Distancein interfaceRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
IllegalArgumentException- See Also:
-
getL1Distance
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:
getL1Distancein interfaceRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
IllegalArgumentException- See Also:
-
getLInfDistance
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:
getLInfDistancein interfaceRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
IllegalArgumentException- See Also:
-
getLInfDistance
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:
getLInfDistancein interfaceRealVector- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
IllegalArgumentException- See Also:
-
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
Map theMath.abs(double)function to each entry.- Specified by:
mapAbsin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapAbsToSelf
Map theMath.abs(double)function to each entry.The instance is changed by this method.
- Specified by:
mapAbsToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapAcos
Map theMath.acos(double)function to each entry.- Specified by:
mapAcosin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapAcosToSelf
Map theMath.acos(double)function to each entry.The instance is changed by this method.
- Specified by:
mapAcosToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapAsin
Map theMath.asin(double)function to each entry.- Specified by:
mapAsinin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapAsinToSelf
Map theMath.asin(double)function to each entry.The instance is changed by this method.
- Specified by:
mapAsinToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapAtan
Map theMath.atan(double)function to each entry.- Specified by:
mapAtanin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapAtanToSelf
Map theMath.atan(double)function to each entry.The instance is changed by this method.
- Specified by:
mapAtanToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapCbrt
Map theMath.cbrt(double)function to each entry.- Specified by:
mapCbrtin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapCbrtToSelf
Map theMath.cbrt(double)function to each entry.The instance is changed by this method.
- Specified by:
mapCbrtToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapCeil
Map theMath.ceil(double)function to each entry.- Specified by:
mapCeilin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapCeilToSelf
Map theMath.ceil(double)function to each entry.The instance is changed by this method.
- Specified by:
mapCeilToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapCos
Map theMath.cos(double)function to each entry.- Specified by:
mapCosin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapCosToSelf
Map theMath.cos(double)function to each entry.The instance is changed by this method.
- Specified by:
mapCosToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapCosh
Map theMath.cosh(double)function to each entry.- Specified by:
mapCoshin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapCoshToSelf
Map theMath.cosh(double)function to each entry.The instance is changed by this method.
- Specified by:
mapCoshToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapDivide
Divide each entry.- Specified by:
mapDividein interfaceRealVector- Parameters:
d- Value to divide by.- Returns:
this/d.
-
mapDivideToSelf
Divide each entry. The instance is changed in-place.- Specified by:
mapDivideToSelfin interfaceRealVector- Parameters:
d- Value to divide by.- Returns:
this.
-
mapExp
Map theMath.exp(double)function to each entry.- Specified by:
mapExpin interfaceRealVector- Returns:
- a mapped copy of the vector.
-
mapExpToSelf
MapMath.exp(double)operation to each entry. The instance is changed in-place.- Specified by:
mapExpToSelfin interfaceRealVector- Returns:
- the mapped vector.
-
mapExpm1
Map theMath.expm1(double)function to each entry.- Specified by:
mapExpm1in interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapExpm1ToSelf
Map theMath.expm1(double)function to each entry.The instance is changed by this method.
- Specified by:
mapExpm1ToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapFloor
Map theMath.floor(double)function to each entry.- Specified by:
mapFloorin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapFloorToSelf
Map theMath.floor(double)function to each entry.The instance is changed by this method.
- Specified by:
mapFloorToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapInv
Map the 1/x function to each entry.- Specified by:
mapInvin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapInvToSelf
Map the 1/x function to each entry.The instance is changed by this method.
- Specified by:
mapInvToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapLog
Map theMath.log(double)function to each entry.- Specified by:
mapLogin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapLogToSelf
Map theMath.log(double)function to each entry.The instance is changed by this method.
- Specified by:
mapLogToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapLog10
Map theMath.log10(double)function to each entry.- Specified by:
mapLog10in interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapLog10ToSelf
Map theMath.log10(double)function to each entry.The instance is changed by this method.
- Specified by:
mapLog10ToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapLog1p
Map theMath.log1p(double)function to each entry.- Specified by:
mapLog1pin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapLog1pToSelf
Map theMath.log1p(double)function to each entry.The instance is changed by this method.
- Specified by:
mapLog1pToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapMultiply
Multiply each entry.- Specified by:
mapMultiplyin interfaceRealVector- Parameters:
d- Multiplication factor.- Returns:
this*d.
-
mapMultiplyToSelf
Multiply each entry. The instance is changed in-place.- Specified by:
mapMultiplyToSelfin interfaceRealVector- Parameters:
d- Multiplication factor.- Returns:
this.
-
mapPow
Map a power operation to each entry.- Specified by:
mapPowin interfaceRealVector- Parameters:
d- Operator value.- Returns:
- a mapped copy of the vector.
-
mapPowToSelf
Map a power operation to each entry. The instance is changed in-place.- Specified by:
mapPowToSelfin interfaceRealVector- Parameters:
d- Operator value.- Returns:
- the mapped vector.
-
mapRint
Map theMath.rint(double)function to each entry.- Specified by:
mapRintin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapRintToSelf
Map theMath.rint(double)function to each entry.The instance is changed by this method.
- Specified by:
mapRintToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapSignum
Map theMath.signum(double)function to each entry.- Specified by:
mapSignumin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapSignumToSelf
Map theMath.signum(double)function to each entry.The instance is changed by this method.
- Specified by:
mapSignumToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapSin
Map theMath.sin(double)function to each entry.- Specified by:
mapSinin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapSinToSelf
Map theMath.sin(double)function to each entry.The instance is changed by this method.
- Specified by:
mapSinToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapSinh
Map theMath.sinh(double)function to each entry.- Specified by:
mapSinhin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapSinhToSelf
Map theMath.sinh(double)function to each entry.The instance is changed by this method.
- Specified by:
mapSinhToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapSqrt
Map theMath.sqrt(double)function to each entry.- Specified by:
mapSqrtin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapSqrtToSelf
Map theMath.sqrt(double)function to each entry.The instance is changed by this method.
- Specified by:
mapSqrtToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapSubtract
Subtract a value from each entry.- Specified by:
mapSubtractin interfaceRealVector- Parameters:
d- Value to be subtracted.- Returns:
this-d.
-
mapSubtractToSelf
Subtract a value from each entry. The instance is changed in-place.- Specified by:
mapSubtractToSelfin interfaceRealVector- Parameters:
d- Value to be subtracted.- Returns:
this.
-
mapTan
Map theMath.tan(double)function to each entry.- Specified by:
mapTanin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapTanToSelf
Map theMath.tan(double)function to each entry.The instance is changed by this method.
- Specified by:
mapTanToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapTanh
Map theMath.tanh(double)function to each entry.- Specified by:
mapTanhin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapTanhToSelf
Map theMath.tanh(double)function to each entry.The instance is changed by this method.
- Specified by:
mapTanhToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
mapUlp
Map theMath.ulp(double)function to each entry.- Specified by:
mapUlpin interfaceRealVector- Returns:
- a vector containing the result of applying the function to each entry
-
mapUlpToSelf
Map theMath.ulp(double)function to each entry.The instance is changed by this method.
- Specified by:
mapUlpToSelfin interfaceRealVector- Returns:
- for convenience, return this
-
outerProduct
Compute the outer product.- Specified by:
outerProductin interfaceRealVector- Parameters:
v- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
IllegalArgumentException
-
outerProduct
Compute the outer product.- Specified by:
outerProductin interfaceRealVector- Parameters:
v- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
IllegalArgumentException
-
projection
Find the orthogonal projection of this vector onto another vector.- Specified by:
projectionin interfaceRealVector- Parameters:
v- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
IllegalArgumentException
-
set
public void set(double value) Set all elements to a single value.- Specified by:
setin interfaceRealVector- 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:
toArrayin interfaceRealVector- Returns:
- array containing a copy of vector elements
-
getData
public double[] getData()Returns vector entries as a double array.- Specified by:
getDatain interfaceRealVector- Returns:
- double array of entries
-
unitVector
Creates a unit vector pointing in the direction of this vector.The instance is not changed by this method.
- Specified by:
unitVectorin interfaceRealVector- 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:
unitizein interfaceRealVector
-
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 toRealVector.iterator().- Specified by:
sparseIteratorin interfaceRealVector- Returns:
- a sparse iterator
-
iterator
Generic dense iterator. It iterates in increasing order of the vector index.- Specified by:
iteratorin interfaceRealVector- Returns:
- a dense iterator
-
map
Acts as if implemented as:return copy().map(function);
- Specified by:
mapin interfaceRealVector- Parameters:
function- Function to apply to each entry.- Returns:
- a new vector.
- Throws:
FunctionEvaluationException- if the function throws it.
-
mapToSelf
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:
mapToSelfin interfaceRealVector- Parameters:
function- Function to apply to each entry.- Returns:
- this vector.
- Throws:
FunctionEvaluationException- if the function throws it.
-