Class AbstractRealVector
- All Implemented Interfaces:
RealVector
- Direct Known Subclasses:
ArrayRealVector
,OpenMapRealVector
RealVector
interface.- Since:
- 2.1
- Version:
- $Revision: 1070725 $ $Date: 2011-02-15 02:31:12 +0100 (mar. 15 févr. 2011) $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
An entry in the vector.protected class
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
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
.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
Check if instance and specified vectors have the same dimension.abstract AbstractRealVector
copy()
Returns a (deep) copy of this vector.double
dotProduct
(double[] v) Compute the dot product.double
Compute 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.double
getDistance
(double[] v) Distance between two vectors.double
Distance between two vectors.double
getL1Distance
(double[] v) Distance between two vectors.double
Distance between two vectors.double
Returns the L1 norm of the vector.double
getLInfDistance
(double[] v) Distance between two vectors.double
Distance between two vectors.double
Returns the L∞ norm of the vector.int
Get the index of the maximum entry.double
Get the value of the maximum entry.int
Get the index of the minimum entry.double
Get the value of the minimum entry.double
getNorm()
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.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.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) Subtractv
from this vector.Subtractv
from this vector.double[]
toArray()
Convert the vector to a double array.void
unitize()
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
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 Details
-
AbstractRealVector
public AbstractRealVector()
-
-
Method Details
-
checkVectorDimensions
Check if instance and specified vectors have the same dimension.- Parameters:
v
- vector to compare instance with- Throws:
DimensionMismatchException
- if the vectors do not have the same dimension
-
checkVectorDimensions
Check if instance dimension is equal to some expected value.- Parameters:
n
- expected dimension.- Throws:
DimensionMismatchException
- if the dimension is inconsistent with vector size
-
checkIndex
Check if an index is valid.- Parameters:
index
- index to check- Throws:
MatrixIndexException
- if index is not valid
-
setSubVector
Set a set of consecutive elements.- Specified by:
setSubVector
in 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:
setSubVector
in 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:
add
in interfaceRealVector
- Parameters:
v
- Vector to be added.- Returns:
this
+v
.- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
add
Compute the sum of this vector andv
.- Specified by:
add
in interfaceRealVector
- Parameters:
v
- Vector to be added.- Returns:
this
+v
.- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
subtract
Subtractv
from this vector.- Specified by:
subtract
in interfaceRealVector
- Parameters:
v
- Vector to be subtracted.- Returns:
this
-v
.- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
subtract
Subtractv
from this vector.- Specified by:
subtract
in interfaceRealVector
- Parameters:
v
- Vector to be subtracted.- Returns:
this
-v
.- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
mapAdd
Add a value to each entry.- Specified by:
mapAdd
in 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:
mapAddToSelf
in interfaceRealVector
- Parameters:
d
- Value to be added to each entry.- Returns:
this
.
-
copy
Returns a (deep) copy of this vector.- Specified by:
copy
in interfaceRealVector
- Returns:
- a vector copy.
-
dotProduct
Compute the dot product.- Specified by:
dotProduct
in interfaceRealVector
- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
dotProduct
Compute the dot product.- Specified by:
dotProduct
in interfaceRealVector
- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
ebeDivide
Element-by-element division.- Specified by:
ebeDivide
in interfaceRealVector
- Parameters:
v
- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
ebeMultiply
Element-by-element multiplication.- Specified by:
ebeMultiply
in interfaceRealVector
- Parameters:
v
- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.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:
getDistance
in interfaceRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.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:
getNorm
in 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:
getL1Norm
in 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:
getLInfNorm
in 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:
getDistance
in interfaceRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.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:
getL1Distance
in interfaceRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.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:
getL1Distance
in interfaceRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.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:
getLInfDistance
in interfaceRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.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:
getLInfDistance
in interfaceRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.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:
mapAbs
in 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:
mapAbsToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapAcos
Map theMath.acos(double)
function to each entry.- Specified by:
mapAcos
in 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:
mapAcosToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapAsin
Map theMath.asin(double)
function to each entry.- Specified by:
mapAsin
in 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:
mapAsinToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapAtan
Map theMath.atan(double)
function to each entry.- Specified by:
mapAtan
in 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:
mapAtanToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapCbrt
Map theMath.cbrt(double)
function to each entry.- Specified by:
mapCbrt
in 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:
mapCbrtToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapCeil
Map theMath.ceil(double)
function to each entry.- Specified by:
mapCeil
in 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:
mapCeilToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapCos
Map theMath.cos(double)
function to each entry.- Specified by:
mapCos
in 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:
mapCosToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapCosh
Map theMath.cosh(double)
function to each entry.- Specified by:
mapCosh
in 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:
mapCoshToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapDivide
Divide each entry.- Specified by:
mapDivide
in interfaceRealVector
- Parameters:
d
- Value to divide by.- Returns:
this
/d
.
-
mapDivideToSelf
Divide each entry. The instance is changed in-place.- Specified by:
mapDivideToSelf
in interfaceRealVector
- Parameters:
d
- Value to divide by.- Returns:
this
.
-
mapExp
Map theMath.exp(double)
function to each entry.- Specified by:
mapExp
in interfaceRealVector
- Returns:
- a mapped copy of the vector.
-
mapExpToSelf
MapMath.exp(double)
operation to each entry. The instance is changed in-place.- Specified by:
mapExpToSelf
in interfaceRealVector
- Returns:
- the mapped vector.
-
mapExpm1
Map theMath.expm1(double)
function to each entry.- Specified by:
mapExpm1
in 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:
mapExpm1ToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapFloor
Map theMath.floor(double)
function to each entry.- Specified by:
mapFloor
in 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:
mapFloorToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapInv
Map the 1/x function to each entry.- Specified by:
mapInv
in 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:
mapInvToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapLog
Map theMath.log(double)
function to each entry.- Specified by:
mapLog
in 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:
mapLogToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapLog10
Map theMath.log10(double)
function to each entry.- Specified by:
mapLog10
in 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:
mapLog10ToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapLog1p
Map theMath.log1p(double)
function to each entry.- Specified by:
mapLog1p
in 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:
mapLog1pToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapMultiply
Multiply each entry.- Specified by:
mapMultiply
in interfaceRealVector
- Parameters:
d
- Multiplication factor.- Returns:
this
*d
.
-
mapMultiplyToSelf
Multiply each entry. The instance is changed in-place.- Specified by:
mapMultiplyToSelf
in interfaceRealVector
- Parameters:
d
- Multiplication factor.- Returns:
this
.
-
mapPow
Map a power operation to each entry.- Specified by:
mapPow
in 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:
mapPowToSelf
in interfaceRealVector
- Parameters:
d
- Operator value.- Returns:
- the mapped vector.
-
mapRint
Map theMath.rint(double)
function to each entry.- Specified by:
mapRint
in 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:
mapRintToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapSignum
Map theMath.signum(double)
function to each entry.- Specified by:
mapSignum
in 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:
mapSignumToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapSin
Map theMath.sin(double)
function to each entry.- Specified by:
mapSin
in 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:
mapSinToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapSinh
Map theMath.sinh(double)
function to each entry.- Specified by:
mapSinh
in 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:
mapSinhToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapSqrt
Map theMath.sqrt(double)
function to each entry.- Specified by:
mapSqrt
in 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:
mapSqrtToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapSubtract
Subtract a value from each entry.- Specified by:
mapSubtract
in 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:
mapSubtractToSelf
in interfaceRealVector
- Parameters:
d
- Value to be subtracted.- Returns:
this
.
-
mapTan
Map theMath.tan(double)
function to each entry.- Specified by:
mapTan
in 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:
mapTanToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapTanh
Map theMath.tanh(double)
function to each entry.- Specified by:
mapTanh
in 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:
mapTanhToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
mapUlp
Map theMath.ulp(double)
function to each entry.- Specified by:
mapUlp
in 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:
mapUlpToSelf
in interfaceRealVector
- Returns:
- for convenience, return this
-
outerProduct
Compute the outer product.- Specified by:
outerProduct
in interfaceRealVector
- Parameters:
v
- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
outerProduct
Compute the outer product.- Specified by:
outerProduct
in interfaceRealVector
- Parameters:
v
- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
projection
Find the orthogonal projection of this vector onto another vector.- Specified by:
projection
in interfaceRealVector
- Parameters:
v
- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
org.apache.commons.math.exception.DimensionMismatchException
- ifv
is not the same size as this vector.IllegalArgumentException
-
set
public void set(double value) Set all elements to a single value.- Specified by:
set
in 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:
toArray
in interfaceRealVector
- Returns:
- array containing a copy of vector elements
-
getData
public double[] getData()Returns vector entries as a double array.- Specified by:
getData
in 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:
unitVector
in 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:
unitize
in 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:
sparseIterator
in interfaceRealVector
- Returns:
- a sparse iterator
-
iterator
Generic dense iterator. It iterates in increasing order of the vector index.- Specified by:
iterator
in interfaceRealVector
- Returns:
- a dense iterator
-
map
Acts as if implemented as:return copy().map(function);
- Specified by:
map
in 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:
mapToSelf
in interfaceRealVector
- Parameters:
function
- Function to apply to each entry.- Returns:
- this vector.
- Throws:
FunctionEvaluationException
- if the function throws it.
-