public interface RealVector
vector element indexing is 0-based -- e.g., getEntry(0)
returns the first element of the vector.
The various mapXxx
and mapXxxToSelf
methods operate
on vectors element-wise, i.e. they perform the same operation (adding a scalar,
applying a function ...) on each element in turn. The mapXxx
versions create a new vector to hold the result and do not change the instance.
The mapXxxToSelf
versions use the instance itself to store the
results, so the instance is changed by these methods. In both cases, the result
vector is returned by the methods, this allows to use the fluent API
style, like this:
RealVector result = v.mapAddToSelf(3.0).mapTanToSelf().mapSquareToSelf();
Remark on the deprecated mapXxx
and mapXxxToSelf
methods: In
Commons-Math v3.0, the same functionality will be achieved by directly using the
map(UnivariateRealFunction)
and mapToSelf(UnivariateRealFunction)
together with new function objects (not available in v2.2).
Modifier and Type | Interface and Description |
---|---|
static class |
RealVector.Entry
Class representing a modifiable entry in the vector.
|
Modifier and Type | Method and Description |
---|---|
RealVector |
add(double[] v)
Compute the sum of this vector and
v . |
RealVector |
add(RealVector v)
Compute the sum of this vector and
v . |
RealVector |
append(double d)
Construct a vector by appending a double to this vector.
|
RealVector |
append(double[] a)
Construct a vector by appending a double array to this vector.
|
RealVector |
append(RealVector v)
Construct a vector by appending a vector to this vector.
|
RealVector |
copy()
Returns a (deep) copy of this vector.
|
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 |
ebeDivide(RealVector v)
Element-by-element division.
|
RealVector |
ebeMultiply(double[] v)
Element-by-element multiplication.
|
RealVector |
ebeMultiply(RealVector v)
Element-by-element multiplication.
|
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(RealVector v)
Distance between two vectors.
|
double |
getEntry(int index)
Returns the entry in the specified index.
|
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.
|
double |
getNorm()
Returns the L2 norm of the vector.
|
RealVector |
getSubVector(int index,
int n)
Get a subvector from consecutive elements.
|
boolean |
isInfinite()
Check whether any coordinate of this vector is infinite and none are
NaN . |
boolean |
isNaN()
Check whether any coordinate of this vector is
NaN . |
java.util.Iterator<RealVector.Entry> |
iterator()
Generic dense iterator.
|
RealVector |
map(UnivariateRealFunction function)
Acts as if implemented as:
|
RealVector |
mapAbs()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapAbsToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapAcos()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapAcosToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapAdd(double d)
Add a value to each entry.
|
RealVector |
mapAddToSelf(double d)
Add a value to each entry.
|
RealVector |
mapAsin()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapAsinToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapAtan()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapAtanToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapCbrt()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapCbrtToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapCeil()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapCeilToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapCos()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapCosh()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapCoshToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapCosToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapDivide(double d)
Divide each entry.
|
RealVector |
mapDivideToSelf(double d)
Divide each entry.
|
RealVector |
mapExp()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapExpm1()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapExpm1ToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapExpToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapFloor()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapFloorToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapInv()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapInvToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapLog()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapLog10()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapLog10ToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapLog1p()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapLog1pToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapLogToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapMultiply(double d)
Multiply each entry.
|
RealVector |
mapMultiplyToSelf(double d)
Multiply each entry.
|
RealVector |
mapPow(double d)
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapPowToSelf(double d)
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapRint()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapRintToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSignum()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSignumToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSin()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSinh()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSinhToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSinToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSqrt()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSqrtToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapSubtract(double d)
Subtract a value from each entry.
|
RealVector |
mapSubtractToSelf(double d)
Subtract a value from each entry.
|
RealVector |
mapTan()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapTanh()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapTanhToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapTanToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapToSelf(UnivariateRealFunction function)
Acts as if it is implemented as:
|
RealVector |
mapUlp()
Deprecated.
in 2.2 (to be removed in 3.0).
|
RealVector |
mapUlpToSelf()
Deprecated.
in 2.2 (to be removed in 3.0).
|
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.
|
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 |
setSubVector(int index,
double[] v)
Set a set of consecutive elements.
|
void |
setSubVector(int index,
RealVector v)
Set a set of consecutive elements.
|
java.util.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)
Subtract
v from this vector. |
RealVector |
subtract(RealVector v)
Subtract
v from this vector. |
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.
|
RealVector mapToSelf(UnivariateRealFunction function) throws FunctionEvaluationException
Entry e = null; for(Iteratorit = iterator(); it.hasNext(); e = it.next()) { e.setValue(function.value(e.getValue())); }
function
- Function to apply to each entry.FunctionEvaluationException
- if the function throws it.RealVector map(UnivariateRealFunction function) throws FunctionEvaluationException
return copy().map(function);
function
- Function to apply to each entry.FunctionEvaluationException
- if the function throws it.java.util.Iterator<RealVector.Entry> iterator()
java.util.Iterator<RealVector.Entry> sparseIterator()
iterator()
.RealVector copy()
RealVector add(RealVector v)
v
.v
- Vector to be added.this
+ v
.DimensionMismatchException
- if v
is not the same size as this vector.RealVector add(double[] v)
v
.v
- Vector to be added.this
+ v
.DimensionMismatchException
- if v
is not the same size as this vector.RealVector subtract(RealVector v)
v
from this vector.v
- Vector to be subtracted.this
- v
.DimensionMismatchException
- if v
is not the same size as this vector.RealVector subtract(double[] v)
v
from this vector.v
- Vector to be subtracted.this
- v
.DimensionMismatchException
- if v
is not the same size as this vector.RealVector mapAdd(double d)
d
- Value to be added to each entry.this
+ d
.RealVector mapAddToSelf(double d)
d
- Value to be added to each entry.this
.RealVector mapSubtract(double d)
d
- Value to be subtracted.this
- d
.RealVector mapSubtractToSelf(double d)
d
- Value to be subtracted.this
.RealVector mapMultiply(double d)
d
- Multiplication factor.this
* d
.RealVector mapMultiplyToSelf(double d)
d
- Multiplication factor.this
.RealVector mapDivide(double d)
d
- Value to divide by.this
/ d
.RealVector mapDivideToSelf(double d)
d
- Value to divide by.this
.@Deprecated RealVector mapPow(double d)
d
- Operator value.@Deprecated RealVector mapPowToSelf(double d)
d
- Operator value.@Deprecated RealVector mapExp()
Math.exp(double)
function to each entry.@Deprecated RealVector mapExpToSelf()
Math.exp(double)
operation to each entry.
The instance is changed in-place.@Deprecated RealVector mapExpm1()
Math.expm1(double)
function to each entry.@Deprecated RealVector mapExpm1ToSelf()
Math.expm1(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapLog()
Math.log(double)
function to each entry.@Deprecated RealVector mapLogToSelf()
Math.log(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapLog10()
Math.log10(double)
function to each entry.@Deprecated RealVector mapLog10ToSelf()
Math.log10(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapLog1p()
Math.log1p(double)
function to each entry.@Deprecated RealVector mapLog1pToSelf()
Math.log1p(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapCosh()
Math.cosh(double)
function to each entry.@Deprecated RealVector mapCoshToSelf()
Math.cosh(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapSinh()
Math.sinh(double)
function to each entry.@Deprecated RealVector mapSinhToSelf()
Math.sinh(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapTanh()
Math.tanh(double)
function to each entry.@Deprecated RealVector mapTanhToSelf()
Math.tanh(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapCos()
Math.cos(double)
function to each entry.@Deprecated RealVector mapCosToSelf()
Math.cos(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapSin()
Math.sin(double)
function to each entry.@Deprecated RealVector mapSinToSelf()
Math.sin(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapTan()
Math.tan(double)
function to each entry.@Deprecated RealVector mapTanToSelf()
Math.tan(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapAcos()
Math.acos(double)
function to each entry.@Deprecated RealVector mapAcosToSelf()
Math.acos(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapAsin()
Math.asin(double)
function to each entry.@Deprecated RealVector mapAsinToSelf()
Math.asin(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapAtan()
Math.atan(double)
function to each entry.@Deprecated RealVector mapAtanToSelf()
Math.atan(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapInv()
@Deprecated RealVector mapInvToSelf()
The instance is changed by this method.
@Deprecated RealVector mapAbs()
Math.abs(double)
function to each entry.@Deprecated RealVector mapAbsToSelf()
Math.abs(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapSqrt()
Math.sqrt(double)
function to each entry.@Deprecated RealVector mapSqrtToSelf()
Math.sqrt(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapCbrt()
Math.cbrt(double)
function to each entry.@Deprecated RealVector mapCbrtToSelf()
Math.cbrt(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapCeil()
Math.ceil(double)
function to each entry.@Deprecated RealVector mapCeilToSelf()
Math.ceil(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapFloor()
Math.floor(double)
function to each entry.@Deprecated RealVector mapFloorToSelf()
Math.floor(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapRint()
Math.rint(double)
function to each entry.@Deprecated RealVector mapRintToSelf()
Math.rint(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapSignum()
Math.signum(double)
function to each entry.@Deprecated RealVector mapSignumToSelf()
Math.signum(double)
function to each entry.
The instance is changed by this method.
@Deprecated RealVector mapUlp()
Math.ulp(double)
function to each entry.@Deprecated RealVector mapUlpToSelf()
Math.ulp(double)
function to each entry.
The instance is changed by this method.
RealVector ebeMultiply(RealVector v)
v
- vector by which instance elements must be multipliedDimensionMismatchException
- if v
is not the same size as this vector.RealVector ebeMultiply(double[] v)
v
- vector by which instance elements must be multipliedDimensionMismatchException
- if v
is not the same size as this vector.RealVector ebeDivide(RealVector v)
v
- vector by which instance elements must be dividedDimensionMismatchException
- if v
is not the same size as this vector.RealVector ebeDivide(double[] v)
v
- vector by which instance elements must be dividedDimensionMismatchException
- if v
is not the same size as this vector.double[] getData()
double dotProduct(RealVector v)
v
- vector with which dot product should be computedDimensionMismatchException
- if v
is not the same size as this vector.double dotProduct(double[] v)
v
- vector with which dot product should be computedDimensionMismatchException
- if v
is not the same size as this vector.double getNorm()
The L2 norm is the root of the sum of the squared elements.
getL1Norm()
,
getLInfNorm()
,
getDistance(RealVector)
double getL1Norm()
The L1 norm is the sum of the absolute values of elements.
getNorm()
,
getLInfNorm()
,
getL1Distance(RealVector)
double getLInfNorm()
The L∞ norm is the max of the absolute values of elements.
getNorm()
,
getL1Norm()
,
getLInfDistance(RealVector)
double getDistance(RealVector v)
This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.getL1Distance(RealVector)
,
getLInfDistance(RealVector)
,
getNorm()
double getDistance(double[] v)
This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.getL1Distance(double[])
,
getLInfDistance(double[])
,
getNorm()
double getL1Distance(RealVector v)
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.getDistance(RealVector)
,
getLInfDistance(RealVector)
,
getL1Norm()
double getL1Distance(double[] v)
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.getDistance(double[])
,
getLInfDistance(double[])
,
getL1Norm()
double getLInfDistance(RealVector v)
This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.getDistance(RealVector)
,
getL1Distance(RealVector)
,
getLInfNorm()
double getLInfDistance(double[] v)
This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
v
- vector to which distance is requestedDimensionMismatchException
- if v
is not the same size as this vector.getDistance(double[])
,
getL1Distance(double[])
,
getLInfNorm()
RealVector unitVector()
The instance is not changed by this method.
java.lang.ArithmeticException
- if the norm is nullvoid unitize()
The instance itself is changed by this method.
java.lang.ArithmeticException
- if the norm is zero.RealVector projection(RealVector v)
v
- vector onto which instance must be projectedDimensionMismatchException
- if v
is not the same size as this vector.RealVector projection(double[] v)
v
- vector onto which instance must be projectedDimensionMismatchException
- if v
is not the same size as this vector.RealMatrix outerProduct(RealVector v)
v
- vector with which outer product should be computedDimensionMismatchException
- if v
is not the same size as this vector.RealMatrix outerProduct(double[] v)
v
- vector with which outer product should be computedDimensionMismatchException
- if v
is not the same size as this vector.double getEntry(int index)
index
- Index location of entry to be fetched.index
.OutOfRangeException
- if the index is not valid.setEntry(int, double)
void setEntry(int index, double value)
index
- element index.value
- new value for the element.OutOfRangeException
- if the index is not valid.getEntry(int)
int getDimension()
RealVector append(RealVector v)
v
- vector to append to this one.RealVector append(double d)
d
- double to append.RealVector append(double[] a)
a
- double array to append.RealVector getSubVector(int index, int n)
index
- index of first element.n
- number of elements to be retrieved.OutOfRangeException
- if the index is not valid.void setSubVector(int index, RealVector v)
index
- index of first element to be set.v
- vector containing the values to set.OutOfRangeException
- if the index is not valid.setSubVector(int, double[])
void setSubVector(int index, double[] v)
index
- index of first element to be set.v
- vector containing the values to set.OutOfRangeException
- if the index is not valid.setSubVector(int, RealVector)
void set(double value)
value
- single value to set for all elementsdouble[] toArray()
The array is independent from vector data, it's elements are copied.
boolean isNaN()
NaN
.true
if any coordinate of this vector is NaN
,
false
otherwise.boolean isInfinite()
NaN
.true
if any coordinate of this vector is infinite and
none are NaN
, false
otherwise.Copyright © 2010 - 2020 Adobe. All Rights Reserved