Interface RealVector
-
- All Known Subinterfaces:
SparseRealVector
- All Known Implementing Classes:
AbstractRealVector,ArrayRealVector,OpenMapRealVector
public interface RealVectorInterface defining a real-valued vector with basic algebraic operations.vector element indexing is 0-based -- e.g.,
getEntry(0)returns the first element of the vector.The various
mapXxxandmapXxxToSelfmethods operate on vectors element-wise, i.e. they perform the same operation (adding a scalar, applying a function ...) on each element in turn. ThemapXxxversions create a new vector to hold the result and do not change the instance. ThemapXxxToSelfversions 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
mapXxxandmapXxxToSelfmethods: In Commons-Math v3.0, the same functionality will be achieved by directly using themap(UnivariateRealFunction)andmapToSelf(UnivariateRealFunction)together with new function objects (not available in v2.2).- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classRealVector.EntryClass representing a modifiable entry in the vector.
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description RealVectoradd(double[] v)Compute the sum of this vector andv.RealVectoradd(RealVector v)Compute the sum of this vector andv.RealVectorappend(double d)Construct a vector by appending a double to this vector.RealVectorappend(double[] a)Construct a vector by appending a double array to this vector.RealVectorappend(RealVector v)Construct a vector by appending a vector to this vector.RealVectorcopy()Returns a (deep) copy of this vector.doubledotProduct(double[] v)Compute the dot product.doubledotProduct(RealVector v)Compute the dot product.RealVectorebeDivide(double[] v)Element-by-element division.RealVectorebeDivide(RealVector v)Element-by-element division.RealVectorebeMultiply(double[] v)Element-by-element multiplication.RealVectorebeMultiply(RealVector v)Element-by-element multiplication.double[]getData()Returns vector entries as a double array.intgetDimension()Returns the size of the vector.doublegetDistance(double[] v)Distance between two vectors.doublegetDistance(RealVector v)Distance between two vectors.doublegetEntry(int index)Returns the entry in the specified index.doublegetL1Distance(double[] v)Distance between two vectors.doublegetL1Distance(RealVector v)Distance between two vectors.doublegetL1Norm()Returns the L1 norm of the vector.doublegetLInfDistance(double[] v)Distance between two vectors.doublegetLInfDistance(RealVector v)Distance between two vectors.doublegetLInfNorm()Returns the L∞ norm of the vector.doublegetNorm()Returns the L2 norm of the vector.RealVectorgetSubVector(int index, int n)Get a subvector from consecutive elements.booleanisInfinite()Check whether any coordinate of this vector is infinite and none areNaN.booleanisNaN()Check whether any coordinate of this vector isNaN.java.util.Iterator<RealVector.Entry>iterator()Generic dense iterator.RealVectormap(UnivariateRealFunction function)Acts as if implemented as:RealVectormapAbs()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapAbsToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapAcos()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapAcosToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapAdd(double d)Add a value to each entry.RealVectormapAddToSelf(double d)Add a value to each entry.RealVectormapAsin()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapAsinToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapAtan()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapAtanToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapCbrt()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapCbrtToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapCeil()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapCeilToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapCos()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapCosh()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapCoshToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapCosToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapDivide(double d)Divide each entry.RealVectormapDivideToSelf(double d)Divide each entry.RealVectormapExp()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapExpm1()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapExpm1ToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapExpToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapFloor()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapFloorToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapInv()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapInvToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapLog()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapLog10()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapLog10ToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapLog1p()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapLog1pToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapLogToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapMultiply(double d)Multiply each entry.RealVectormapMultiplyToSelf(double d)Multiply each entry.RealVectormapPow(double d)Deprecated.in 2.2 (to be removed in 3.0).RealVectormapPowToSelf(double d)Deprecated.in 2.2 (to be removed in 3.0).RealVectormapRint()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapRintToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSignum()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSignumToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSin()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSinh()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSinhToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSinToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSqrt()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSqrtToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapSubtract(double d)Subtract a value from each entry.RealVectormapSubtractToSelf(double d)Subtract a value from each entry.RealVectormapTan()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapTanh()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapTanhToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapTanToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapToSelf(UnivariateRealFunction function)Acts as if it is implemented as:RealVectormapUlp()Deprecated.in 2.2 (to be removed in 3.0).RealVectormapUlpToSelf()Deprecated.in 2.2 (to be removed in 3.0).RealMatrixouterProduct(double[] v)Compute the outer product.RealMatrixouterProduct(RealVector v)Compute the outer product.RealVectorprojection(double[] v)Find the orthogonal projection of this vector onto another vector.RealVectorprojection(RealVector v)Find the orthogonal projection of this vector onto another vector.voidset(double value)Set all elements to a single value.voidsetEntry(int index, double value)Set a single element.voidsetSubVector(int index, double[] v)Set a set of consecutive elements.voidsetSubVector(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.RealVectorsubtract(double[] v)Subtractvfrom this vector.RealVectorsubtract(RealVector v)Subtractvfrom this vector.double[]toArray()Convert the vector to a double array.voidunitize()Converts this vector into a unit vector.RealVectorunitVector()Creates a unit vector pointing in the direction of this vector.
-
-
-
Method Detail
-
mapToSelf
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())); } - Parameters:
function- Function to apply to each entry.- Returns:
- this vector.
- Throws:
FunctionEvaluationException- if the function throws it.
-
map
RealVector map(UnivariateRealFunction function) throws FunctionEvaluationException
Acts as if implemented as:return copy().map(function);
- Parameters:
function- Function to apply to each entry.- Returns:
- a new vector.
- Throws:
FunctionEvaluationException- if the function throws it.
-
iterator
java.util.Iterator<RealVector.Entry> iterator()
Generic dense iterator. It iterates in increasing order of the vector index.- Returns:
- a dense iterator
-
sparseIterator
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. No guarantees are made about order of iteration. In dense implementations, this method will often delegate toiterator().- Returns:
- a sparse iterator
-
copy
RealVector copy()
Returns a (deep) copy of this vector.- Returns:
- a vector copy.
-
add
RealVector add(RealVector v)
Compute the sum of this vector andv.- Parameters:
v- Vector to be added.- Returns:
this+v.- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
add
RealVector add(double[] v)
Compute the sum of this vector andv.- Parameters:
v- Vector to be added.- Returns:
this+v.- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
subtract
RealVector subtract(RealVector v)
Subtractvfrom this vector.- Parameters:
v- Vector to be subtracted.- Returns:
this-v.- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
subtract
RealVector subtract(double[] v)
Subtractvfrom this vector.- Parameters:
v- Vector to be subtracted.- Returns:
this-v.- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
mapAdd
RealVector mapAdd(double d)
Add a value to each entry.- Parameters:
d- Value to be added to each entry.- Returns:
this+d.
-
mapAddToSelf
RealVector mapAddToSelf(double d)
Add a value to each entry. The instance is changed in-place.- Parameters:
d- Value to be added to each entry.- Returns:
this.
-
mapSubtract
RealVector mapSubtract(double d)
Subtract a value from each entry.- Parameters:
d- Value to be subtracted.- Returns:
this-d.
-
mapSubtractToSelf
RealVector mapSubtractToSelf(double d)
Subtract a value from each entry. The instance is changed in-place.- Parameters:
d- Value to be subtracted.- Returns:
this.
-
mapMultiply
RealVector mapMultiply(double d)
Multiply each entry.- Parameters:
d- Multiplication factor.- Returns:
this*d.
-
mapMultiplyToSelf
RealVector mapMultiplyToSelf(double d)
Multiply each entry. The instance is changed in-place.- Parameters:
d- Multiplication factor.- Returns:
this.
-
mapDivide
RealVector mapDivide(double d)
Divide each entry.- Parameters:
d- Value to divide by.- Returns:
this/d.
-
mapDivideToSelf
RealVector mapDivideToSelf(double d)
Divide each entry. The instance is changed in-place.- Parameters:
d- Value to divide by.- Returns:
this.
-
mapPow
@Deprecated RealVector mapPow(double d)
Deprecated.in 2.2 (to be removed in 3.0).Map a power operation to each entry.- Parameters:
d- Operator value.- Returns:
- a mapped copy of the vector.
-
mapPowToSelf
@Deprecated RealVector mapPowToSelf(double d)
Deprecated.in 2.2 (to be removed in 3.0).Map a power operation to each entry. The instance is changed in-place.- Parameters:
d- Operator value.- Returns:
- the mapped vector.
-
mapExp
@Deprecated RealVector mapExp()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.exp(double)function to each entry.- Returns:
- a mapped copy of the vector.
-
mapExpToSelf
@Deprecated RealVector mapExpToSelf()
Deprecated.in 2.2 (to be removed in 3.0).MapMath.exp(double)operation to each entry. The instance is changed in-place.- Returns:
- the mapped vector.
-
mapExpm1
@Deprecated RealVector mapExpm1()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.expm1(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapExpm1ToSelf
@Deprecated RealVector mapExpm1ToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.expm1(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapLog
@Deprecated RealVector mapLog()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.log(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapLogToSelf
@Deprecated RealVector mapLogToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.log(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapLog10
@Deprecated RealVector mapLog10()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.log10(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapLog10ToSelf
@Deprecated RealVector mapLog10ToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.log10(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapLog1p
@Deprecated RealVector mapLog1p()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.log1p(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapLog1pToSelf
@Deprecated RealVector mapLog1pToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.log1p(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapCosh
@Deprecated RealVector mapCosh()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.cosh(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapCoshToSelf
@Deprecated RealVector mapCoshToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.cosh(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapSinh
@Deprecated RealVector mapSinh()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.sinh(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapSinhToSelf
@Deprecated RealVector mapSinhToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.sinh(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapTanh
@Deprecated RealVector mapTanh()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.tanh(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapTanhToSelf
@Deprecated RealVector mapTanhToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.tanh(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapCos
@Deprecated RealVector mapCos()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.cos(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapCosToSelf
@Deprecated RealVector mapCosToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.cos(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapSin
@Deprecated RealVector mapSin()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.sin(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapSinToSelf
@Deprecated RealVector mapSinToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.sin(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapTan
@Deprecated RealVector mapTan()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.tan(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapTanToSelf
@Deprecated RealVector mapTanToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.tan(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapAcos
@Deprecated RealVector mapAcos()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.acos(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapAcosToSelf
@Deprecated RealVector mapAcosToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.acos(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapAsin
@Deprecated RealVector mapAsin()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.asin(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapAsinToSelf
@Deprecated RealVector mapAsinToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.asin(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapAtan
@Deprecated RealVector mapAtan()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.atan(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapAtanToSelf
@Deprecated RealVector mapAtanToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.atan(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapInv
@Deprecated RealVector mapInv()
Deprecated.in 2.2 (to be removed in 3.0).Map the 1/x function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapInvToSelf
@Deprecated RealVector mapInvToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map the 1/x function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapAbs
@Deprecated RealVector mapAbs()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.abs(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapAbsToSelf
@Deprecated RealVector mapAbsToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.abs(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapSqrt
@Deprecated RealVector mapSqrt()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.sqrt(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapSqrtToSelf
@Deprecated RealVector mapSqrtToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.sqrt(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapCbrt
@Deprecated RealVector mapCbrt()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.cbrt(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapCbrtToSelf
@Deprecated RealVector mapCbrtToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.cbrt(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapCeil
@Deprecated RealVector mapCeil()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.ceil(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapCeilToSelf
@Deprecated RealVector mapCeilToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.ceil(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapFloor
@Deprecated RealVector mapFloor()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.floor(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapFloorToSelf
@Deprecated RealVector mapFloorToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.floor(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapRint
@Deprecated RealVector mapRint()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.rint(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapRintToSelf
@Deprecated RealVector mapRintToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.rint(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapSignum
@Deprecated RealVector mapSignum()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.signum(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapSignumToSelf
@Deprecated RealVector mapSignumToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.signum(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
mapUlp
@Deprecated RealVector mapUlp()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.ulp(double)function to each entry.- Returns:
- a vector containing the result of applying the function to each entry
-
mapUlpToSelf
@Deprecated RealVector mapUlpToSelf()
Deprecated.in 2.2 (to be removed in 3.0).Map theMath.ulp(double)function to each entry.The instance is changed by this method.
- Returns:
- for convenience, return this
-
ebeMultiply
RealVector ebeMultiply(RealVector v)
Element-by-element multiplication.- Parameters:
v- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
ebeMultiply
RealVector ebeMultiply(double[] v)
Element-by-element multiplication.- Parameters:
v- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
ebeDivide
RealVector ebeDivide(RealVector v)
Element-by-element division.- Parameters:
v- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
ebeDivide
RealVector ebeDivide(double[] v)
Element-by-element division.- Parameters:
v- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
getData
double[] getData()
Returns vector entries as a double array.- Returns:
- double array of entries
-
dotProduct
double dotProduct(RealVector v)
Compute the dot product.- Parameters:
v- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
dotProduct
double dotProduct(double[] v)
Compute the dot product.- Parameters:
v- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
getNorm
double getNorm()
Returns the L2 norm of the vector.The L2 norm is the root of the sum of the squared elements.
- Returns:
- norm
- See Also:
getL1Norm(),getLInfNorm(),getDistance(RealVector)
-
getL1Norm
double getL1Norm()
Returns the L1 norm of the vector.The L1 norm is the sum of the absolute values of elements.
- Returns:
- norm
- See Also:
getNorm(),getLInfNorm(),getL1Distance(RealVector)
-
getLInfNorm
double getLInfNorm()
Returns the L∞ norm of the vector.The L∞ norm is the max of the absolute values of elements.
- Returns:
- norm
- See Also:
getNorm(),getL1Norm(),getLInfDistance(RealVector)
-
getDistance
double getDistance(RealVector v)
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.
- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.- See Also:
getL1Distance(RealVector),getLInfDistance(RealVector),getNorm()
-
getDistance
double getDistance(double[] v)
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.
- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.- See Also:
getL1Distance(double[]),getLInfDistance(double[]),getNorm()
-
getL1Distance
double getL1Distance(RealVector v)
Distance between two vectors.This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.- See Also:
getDistance(RealVector),getLInfDistance(RealVector),getL1Norm()
-
getL1Distance
double getL1Distance(double[] v)
Distance between two vectors.This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.- See Also:
getDistance(double[]),getLInfDistance(double[]),getL1Norm()
-
getLInfDistance
double getLInfDistance(RealVector v)
Distance between two vectors.This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.- See Also:
getDistance(RealVector),getL1Distance(RealVector),getLInfNorm()
-
getLInfDistance
double getLInfDistance(double[] v)
Distance between two vectors.This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
- Parameters:
v- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.- See Also:
getDistance(double[]),getL1Distance(double[]),getLInfNorm()
-
unitVector
RealVector unitVector()
Creates a unit vector pointing in the direction of this vector.The instance is not changed by this method.
- Returns:
- a unit vector pointing in direction of this vector
- Throws:
java.lang.ArithmeticException- if the norm is null
-
unitize
void unitize()
Converts this vector into a unit vector.The instance itself is changed by this method.
- Throws:
java.lang.ArithmeticException- if the norm is zero.
-
projection
RealVector projection(RealVector v)
Find the orthogonal projection of this vector onto another vector.- Parameters:
v- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
projection
RealVector projection(double[] v)
Find the orthogonal projection of this vector onto another vector.- Parameters:
v- vector onto which instance must be projected- Returns:
- projection of the instance onto v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
outerProduct
RealMatrix outerProduct(RealVector v)
Compute the outer product.- Parameters:
v- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
outerProduct
RealMatrix outerProduct(double[] v)
Compute the outer product.- Parameters:
v- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
DimensionMismatchException- ifvis not the same size as this vector.
-
getEntry
double getEntry(int index)
Returns the entry in the specified index.- Parameters:
index- Index location of entry to be fetched.- Returns:
- the vector entry at
index. - Throws:
OutOfRangeException- if the index is not valid.- See Also:
setEntry(int, double)
-
setEntry
void setEntry(int index, double value)Set a single element.- Parameters:
index- element index.value- new value for the element.- Throws:
OutOfRangeException- if the index is not valid.- See Also:
getEntry(int)
-
getDimension
int getDimension()
Returns the size of the vector.- Returns:
- size
-
append
RealVector append(RealVector v)
Construct a vector by appending a vector to this vector.- Parameters:
v- vector to append to this one.- Returns:
- a new vector
-
append
RealVector append(double d)
Construct a vector by appending a double to this vector.- Parameters:
d- double to append.- Returns:
- a new vector
-
append
RealVector append(double[] a)
Construct a vector by appending a double array to this vector.- Parameters:
a- double array to append.- Returns:
- a new vector
-
getSubVector
RealVector getSubVector(int index, int n)
Get a subvector from consecutive elements.- Parameters:
index- index of first element.n- number of elements to be retrieved.- Returns:
- a vector containing n elements.
- Throws:
OutOfRangeException- if the index is not valid.
-
setSubVector
void setSubVector(int index, RealVector v)Set a set of consecutive elements.- Parameters:
index- index of first element to be set.v- vector containing the values to set.- Throws:
OutOfRangeException- if the index is not valid.- See Also:
setSubVector(int, double[])
-
setSubVector
void setSubVector(int index, double[] v)Set a set of consecutive elements.- Parameters:
index- index of first element to be set.v- vector containing the values to set.- Throws:
OutOfRangeException- if the index is not valid.- See Also:
setSubVector(int, RealVector)
-
set
void set(double value)
Set all elements to a single value.- Parameters:
value- single value to set for all elements
-
toArray
double[] toArray()
Convert the vector to a double array.The array is independent from vector data, it's elements are copied.
- Returns:
- array containing a copy of vector elements
-
isNaN
boolean isNaN()
Check whether any coordinate of this vector isNaN.- Returns:
trueif any coordinate of this vector isNaN,falseotherwise.
-
isInfinite
boolean isInfinite()
Check whether any coordinate of this vector is infinite and none areNaN.- Returns:
trueif any coordinate of this vector is infinite and none areNaN,falseotherwise.
-
-