Class ArrayRealVector
- java.lang.Object
-
- org.apache.commons.math.linear.AbstractRealVector
-
- org.apache.commons.math.linear.ArrayRealVector
-
- All Implemented Interfaces:
java.io.Serializable
,RealVector
public class ArrayRealVector extends AbstractRealVector implements java.io.Serializable
This class implements theRealVector
interface with a double array.- Since:
- 2.0
- Version:
- $Revision: 1003993 $ $Date: 2010-10-03 18:39:16 +0200 (dim. 03 oct. 2010) $
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.math.linear.AbstractRealVector
AbstractRealVector.EntryImpl, AbstractRealVector.SparseEntryIterator
-
Nested classes/interfaces inherited from interface org.apache.commons.math.linear.RealVector
RealVector.Entry
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]
data
Entries of the vector.
-
Constructor Summary
Constructors Constructor Description ArrayRealVector()
Build a 0-length vector.ArrayRealVector(double[] d)
Construct a vector from an array, copying the input array.ArrayRealVector(double[] d, boolean copyArray)
Create a new ArrayRealVector using the input array as the underlying data array.ArrayRealVector(double[] v1, double[] v2)
Construct a vector by appending one vector to another vector.ArrayRealVector(double[] d, int pos, int size)
Construct a vector from part of a array.ArrayRealVector(double[] v1, ArrayRealVector v2)
Construct a vector by appending one vector to another vector.ArrayRealVector(int size)
Construct a (size)-length vector of zeros.ArrayRealVector(int size, double preset)
Construct an (size)-length vector with preset values.ArrayRealVector(java.lang.Double[] d)
Construct a vector from an array.ArrayRealVector(java.lang.Double[] d, int pos, int size)
Construct a vector from part of a Double arrayArrayRealVector(ArrayRealVector v)
Construct a vector from another vector, using a deep copy.ArrayRealVector(ArrayRealVector v, boolean deep)
Construct a vector from another vector.ArrayRealVector(ArrayRealVector v1, double[] v2)
Construct a vector by appending one vector to another vector.ArrayRealVector(ArrayRealVector v1, ArrayRealVector v2)
Construct a vector by appending one vector to another vector.ArrayRealVector(ArrayRealVector v1, RealVector v2)
Construct a vector by appending one vector to another vector.ArrayRealVector(RealVector v)
Construct a vector from another vector, using a deep copy.ArrayRealVector(RealVector v1, ArrayRealVector v2)
Construct a vector by appending one vector to another vector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RealVector
add(double[] v)
Compute the sum of this vector andv
.ArrayRealVector
add(ArrayRealVector v)
Compute the sum of this and v.RealVector
add(RealVector v)
Compute the sum of this vector andv
.RealVector
append(double in)
Construct a vector by appending a double to this vector.RealVector
append(double[] in)
Construct a vector by appending a double array to this vector.ArrayRealVector
append(ArrayRealVector v)
Construct a vector by appending a vector to this vector.RealVector
append(RealVector v)
Construct a vector by appending a vector to this vector.protected void
checkVectorDimensions(int n)
Check if instance dimension is equal to some expected value.protected void
checkVectorDimensions(RealVector v)
Check if instance and specified vectors have the same dimension.AbstractRealVector
copy()
Returns a (deep) copy of this vector.double
dotProduct(double[] v)
Compute the dot product.double
dotProduct(ArrayRealVector v)
Compute the dot product.double
dotProduct(RealVector v)
Compute the dot product.RealVector
ebeDivide(double[] v)
Element-by-element division.ArrayRealVector
ebeDivide(ArrayRealVector v)
Element-by-element division.RealVector
ebeDivide(RealVector v)
Element-by-element division.RealVector
ebeMultiply(double[] v)
Element-by-element multiplication.ArrayRealVector
ebeMultiply(ArrayRealVector v)
Element-by-element multiplication.RealVector
ebeMultiply(RealVector v)
Element-by-element multiplication.boolean
equals(java.lang.Object other)
Test for the equality of two real vectors.double[]
getData()
Returns vector entries as a double array.double[]
getDataRef()
Returns a reference to the underlying data array.int
getDimension()
Returns the size of the vector.double
getDistance(double[] v)
Distance between two vectors.double
getDistance(ArrayRealVector 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(ArrayRealVector 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(ArrayRealVector 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.int
hashCode()
Get a hashCode for the real vector.boolean
isInfinite()
Returns true if any coordinate of this vector is infinite and none are NaN; false otherwiseboolean
isNaN()
Returns true if any coordinate of this vector is NaN; false otherwiseRealVector
mapAbsToSelf()
Map theMath.abs(double)
function to each entry.RealVector
mapAcosToSelf()
Map theMath.acos(double)
function to each entry.RealVector
mapAddToSelf(double d)
Add a value to each entry.RealVector
mapAsinToSelf()
Map theMath.asin(double)
function to each entry.RealVector
mapAtanToSelf()
Map theMath.atan(double)
function to each entry.RealVector
mapCbrtToSelf()
Map theMath.cbrt(double)
function to each entry.RealVector
mapCeilToSelf()
Map theMath.ceil(double)
function to each entry.RealVector
mapCoshToSelf()
Map theMath.cosh(double)
function to each entry.RealVector
mapCosToSelf()
Map theMath.cos(double)
function to each entry.RealVector
mapDivideToSelf(double d)
Divide each entry.RealVector
mapExpm1ToSelf()
Map theMath.expm1(double)
function to each entry.RealVector
mapExpToSelf()
MapMath.exp(double)
operation to each entry.RealVector
mapFloorToSelf()
Map theMath.floor(double)
function to each entry.RealVector
mapInvToSelf()
Map the 1/x function to each entry.RealVector
mapLog10ToSelf()
Map theMath.log10(double)
function to each entry.RealVector
mapLog1pToSelf()
Map theMath.log1p(double)
function to each entry.RealVector
mapLogToSelf()
Map theMath.log(double)
function to each entry.RealVector
mapMultiplyToSelf(double d)
Multiply each entry.RealVector
mapPowToSelf(double d)
Map a power operation to each entry.RealVector
mapRintToSelf()
Map theMath.rint(double)
function to each entry.RealVector
mapSignumToSelf()
Map theMath.signum(double)
function to each entry.RealVector
mapSinhToSelf()
Map theMath.sinh(double)
function to each entry.RealVector
mapSinToSelf()
Map theMath.sin(double)
function to each entry.RealVector
mapSqrtToSelf()
Map theMath.sqrt(double)
function to each entry.RealVector
mapSubtractToSelf(double d)
Subtract a value from each entry.RealVector
mapTanhToSelf()
Map theMath.tanh(double)
function to each entry.RealVector
mapTanToSelf()
Map theMath.tan(double)
function to each entry.RealVector
mapUlpToSelf()
Map theMath.ulp(double)
function to each entry.RealMatrix
outerProduct(double[] v)
Compute the outer product.RealMatrix
outerProduct(ArrayRealVector 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.ArrayRealVector
projection(ArrayRealVector 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
set(int index, ArrayRealVector v)
Set a set of consecutive elements.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.RealVector
subtract(double[] v)
Subtractv
from this vector.ArrayRealVector
subtract(ArrayRealVector v)
Compute this minus v.RealVector
subtract(RealVector v)
Subtractv
from this vector.double[]
toArray()
Convert the vector to a double array.java.lang.String
toString()
void
unitize()
Converts this vector into a unit vector.RealVector
unitVector()
Creates a unit vector pointing in the direction of this vector.-
Methods inherited from class org.apache.commons.math.linear.AbstractRealVector
checkIndex, getMaxIndex, getMaxValue, getMinIndex, getMinValue, iterator, map, mapAbs, mapAcos, mapAdd, mapAsin, mapAtan, mapCbrt, mapCeil, mapCos, mapCosh, mapDivide, mapExp, mapExpm1, mapFloor, mapInv, mapLog, mapLog10, mapLog1p, mapMultiply, mapPow, mapRint, mapSignum, mapSin, mapSinh, mapSqrt, mapSubtract, mapTan, mapTanh, mapToSelf, mapUlp, sparseIterator
-
-
-
-
Constructor Detail
-
ArrayRealVector
public ArrayRealVector()
Build a 0-length vector.Zero-length vectors may be used to initialized construction of vectors by data gathering. We start with zero-length and use either the
ArrayRealVector(ArrayRealVector, ArrayRealVector)
constructor or one of theappend
method (append(double)
,append(double[])
,append(ArrayRealVector)
) to gather data into this vector.
-
ArrayRealVector
public ArrayRealVector(int size)
Construct a (size)-length vector of zeros.- Parameters:
size
- size of the vector
-
ArrayRealVector
public ArrayRealVector(int size, double preset)
Construct an (size)-length vector with preset values.- Parameters:
size
- size of the vectorpreset
- fill the vector with this scalar value
-
ArrayRealVector
public ArrayRealVector(double[] d)
Construct a vector from an array, copying the input array.- Parameters:
d
- array of doubles.
-
ArrayRealVector
public ArrayRealVector(double[] d, boolean copyArray)
Create a new ArrayRealVector using the input array as the underlying data array.If an array is built specially in order to be embedded in a ArrayRealVector and not used directly, the
copyArray
may be set tofalse
- Parameters:
d
- data for new vectorcopyArray
- if true, the input array will be copied, otherwise it will be referenced- See Also:
ArrayRealVector(double[])
-
ArrayRealVector
public ArrayRealVector(double[] d, int pos, int size)
Construct a vector from part of a array.- Parameters:
d
- array of doubles.pos
- position of first entrysize
- number of entries to copy
-
ArrayRealVector
public ArrayRealVector(java.lang.Double[] d)
Construct a vector from an array.- Parameters:
d
- array of Doubles.
-
ArrayRealVector
public ArrayRealVector(java.lang.Double[] d, int pos, int size)
Construct a vector from part of a Double array- Parameters:
d
- array of Doubles.pos
- position of first entrysize
- number of entries to copy
-
ArrayRealVector
public ArrayRealVector(RealVector v)
Construct a vector from another vector, using a deep copy.- Parameters:
v
- vector to copy
-
ArrayRealVector
public ArrayRealVector(ArrayRealVector v)
Construct a vector from another vector, using a deep copy.- Parameters:
v
- vector to copy
-
ArrayRealVector
public ArrayRealVector(ArrayRealVector v, boolean deep)
Construct a vector from another vector.- Parameters:
v
- vector to copydeep
- if true perform a deep copy otherwise perform a shallow copy
-
ArrayRealVector
public ArrayRealVector(ArrayRealVector v1, ArrayRealVector v2)
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
ArrayRealVector
public ArrayRealVector(ArrayRealVector v1, RealVector v2)
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
ArrayRealVector
public ArrayRealVector(RealVector v1, ArrayRealVector v2)
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
ArrayRealVector
public ArrayRealVector(ArrayRealVector v1, double[] v2)
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
ArrayRealVector
public ArrayRealVector(double[] v1, ArrayRealVector v2)
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
ArrayRealVector
public ArrayRealVector(double[] v1, double[] v2)
Construct a vector by appending one vector to another vector.- Parameters:
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)
-
-
Method Detail
-
copy
public AbstractRealVector copy()
Returns a (deep) copy of this vector.- Specified by:
copy
in interfaceRealVector
- Specified by:
copy
in classAbstractRealVector
- Returns:
- a vector copy.
-
add
public RealVector add(RealVector v) throws java.lang.IllegalArgumentException
Compute the sum of this vector andv
.- Specified by:
add
in interfaceRealVector
- Overrides:
add
in classAbstractRealVector
- Parameters:
v
- Vector to be added.- Returns:
this
+v
.- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
add
public RealVector add(double[] v) throws java.lang.IllegalArgumentException
Compute the sum of this vector andv
.- Specified by:
add
in interfaceRealVector
- Overrides:
add
in classAbstractRealVector
- Parameters:
v
- Vector to be added.- Returns:
this
+v
.- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
add
public ArrayRealVector add(ArrayRealVector v) throws java.lang.IllegalArgumentException
Compute the sum of this and v.- Parameters:
v
- vector to be added- Returns:
- this + v
- Throws:
java.lang.IllegalArgumentException
- if v is not the same size as this
-
subtract
public RealVector subtract(RealVector v) throws java.lang.IllegalArgumentException
Subtractv
from this vector.- Specified by:
subtract
in interfaceRealVector
- Overrides:
subtract
in classAbstractRealVector
- Parameters:
v
- Vector to be subtracted.- Returns:
this
-v
.- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
subtract
public RealVector subtract(double[] v) throws java.lang.IllegalArgumentException
Subtractv
from this vector.- Specified by:
subtract
in interfaceRealVector
- Overrides:
subtract
in classAbstractRealVector
- Parameters:
v
- Vector to be subtracted.- Returns:
this
-v
.- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
subtract
public ArrayRealVector subtract(ArrayRealVector v) throws java.lang.IllegalArgumentException
Compute this minus v.- Parameters:
v
- vector to be subtracted- Returns:
- this + v
- Throws:
java.lang.IllegalArgumentException
- if v is not the same size as this
-
mapAddToSelf
public RealVector mapAddToSelf(double d)
Add a value to each entry. The instance is changed in-place.- Specified by:
mapAddToSelf
in interfaceRealVector
- Overrides:
mapAddToSelf
in classAbstractRealVector
- Parameters:
d
- Value to be added to each entry.- Returns:
this
.
-
mapSubtractToSelf
public RealVector mapSubtractToSelf(double d)
Subtract a value from each entry. The instance is changed in-place.- Specified by:
mapSubtractToSelf
in interfaceRealVector
- Overrides:
mapSubtractToSelf
in classAbstractRealVector
- Parameters:
d
- Value to be subtracted.- Returns:
this
.
-
mapMultiplyToSelf
public RealVector mapMultiplyToSelf(double d)
Multiply each entry. The instance is changed in-place.- Specified by:
mapMultiplyToSelf
in interfaceRealVector
- Overrides:
mapMultiplyToSelf
in classAbstractRealVector
- Parameters:
d
- Multiplication factor.- Returns:
this
.
-
mapDivideToSelf
public RealVector mapDivideToSelf(double d)
Divide each entry. The instance is changed in-place.- Specified by:
mapDivideToSelf
in interfaceRealVector
- Overrides:
mapDivideToSelf
in classAbstractRealVector
- Parameters:
d
- Value to divide by.- Returns:
this
.
-
mapPowToSelf
public RealVector mapPowToSelf(double d)
Map a power operation to each entry. The instance is changed in-place.- Specified by:
mapPowToSelf
in interfaceRealVector
- Overrides:
mapPowToSelf
in classAbstractRealVector
- Parameters:
d
- Operator value.- Returns:
- the mapped vector.
-
mapExpToSelf
public RealVector mapExpToSelf()
MapMath.exp(double)
operation to each entry. The instance is changed in-place.- Specified by:
mapExpToSelf
in interfaceRealVector
- Overrides:
mapExpToSelf
in classAbstractRealVector
- Returns:
- the mapped vector.
-
mapExpm1ToSelf
public RealVector mapExpm1ToSelf()
Map theMath.expm1(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapExpm1ToSelf
in interfaceRealVector
- Overrides:
mapExpm1ToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapLogToSelf
public RealVector mapLogToSelf()
Map theMath.log(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapLogToSelf
in interfaceRealVector
- Overrides:
mapLogToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapLog10ToSelf
public RealVector mapLog10ToSelf()
Map theMath.log10(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapLog10ToSelf
in interfaceRealVector
- Overrides:
mapLog10ToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapLog1pToSelf
public RealVector mapLog1pToSelf()
Map theMath.log1p(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapLog1pToSelf
in interfaceRealVector
- Overrides:
mapLog1pToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapCoshToSelf
public RealVector mapCoshToSelf()
Map theMath.cosh(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapCoshToSelf
in interfaceRealVector
- Overrides:
mapCoshToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapSinhToSelf
public RealVector mapSinhToSelf()
Map theMath.sinh(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapSinhToSelf
in interfaceRealVector
- Overrides:
mapSinhToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapTanhToSelf
public RealVector mapTanhToSelf()
Map theMath.tanh(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapTanhToSelf
in interfaceRealVector
- Overrides:
mapTanhToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapCosToSelf
public RealVector mapCosToSelf()
Map theMath.cos(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapCosToSelf
in interfaceRealVector
- Overrides:
mapCosToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapSinToSelf
public RealVector mapSinToSelf()
Map theMath.sin(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapSinToSelf
in interfaceRealVector
- Overrides:
mapSinToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapTanToSelf
public RealVector mapTanToSelf()
Map theMath.tan(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapTanToSelf
in interfaceRealVector
- Overrides:
mapTanToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapAcosToSelf
public RealVector mapAcosToSelf()
Map theMath.acos(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapAcosToSelf
in interfaceRealVector
- Overrides:
mapAcosToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapAsinToSelf
public RealVector mapAsinToSelf()
Map theMath.asin(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapAsinToSelf
in interfaceRealVector
- Overrides:
mapAsinToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapAtanToSelf
public RealVector mapAtanToSelf()
Map theMath.atan(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapAtanToSelf
in interfaceRealVector
- Overrides:
mapAtanToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapInvToSelf
public RealVector mapInvToSelf()
Map the 1/x function to each entry.The instance is changed by this method.
- Specified by:
mapInvToSelf
in interfaceRealVector
- Overrides:
mapInvToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapAbsToSelf
public RealVector mapAbsToSelf()
Map theMath.abs(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapAbsToSelf
in interfaceRealVector
- Overrides:
mapAbsToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapSqrtToSelf
public RealVector mapSqrtToSelf()
Map theMath.sqrt(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapSqrtToSelf
in interfaceRealVector
- Overrides:
mapSqrtToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapCbrtToSelf
public RealVector mapCbrtToSelf()
Map theMath.cbrt(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapCbrtToSelf
in interfaceRealVector
- Overrides:
mapCbrtToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapCeilToSelf
public RealVector mapCeilToSelf()
Map theMath.ceil(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapCeilToSelf
in interfaceRealVector
- Overrides:
mapCeilToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapFloorToSelf
public RealVector mapFloorToSelf()
Map theMath.floor(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapFloorToSelf
in interfaceRealVector
- Overrides:
mapFloorToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapRintToSelf
public RealVector mapRintToSelf()
Map theMath.rint(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapRintToSelf
in interfaceRealVector
- Overrides:
mapRintToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapSignumToSelf
public RealVector mapSignumToSelf()
Map theMath.signum(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapSignumToSelf
in interfaceRealVector
- Overrides:
mapSignumToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
mapUlpToSelf
public RealVector mapUlpToSelf()
Map theMath.ulp(double)
function to each entry.The instance is changed by this method.
- Specified by:
mapUlpToSelf
in interfaceRealVector
- Overrides:
mapUlpToSelf
in classAbstractRealVector
- Returns:
- for convenience, return this
-
ebeMultiply
public RealVector ebeMultiply(RealVector v) throws java.lang.IllegalArgumentException
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:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
ebeMultiply
public RealVector ebeMultiply(double[] v) throws java.lang.IllegalArgumentException
Element-by-element multiplication.- Specified by:
ebeMultiply
in interfaceRealVector
- Overrides:
ebeMultiply
in classAbstractRealVector
- Parameters:
v
- vector by which instance elements must be multiplied- Returns:
- a vector containing this[i] * v[i] for all i
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
ebeMultiply
public ArrayRealVector ebeMultiply(ArrayRealVector v) throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException
- if v is not the same size as this
-
ebeDivide
public RealVector ebeDivide(RealVector v) throws java.lang.IllegalArgumentException
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:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
ebeDivide
public RealVector ebeDivide(double[] v) throws java.lang.IllegalArgumentException
Element-by-element division.- Specified by:
ebeDivide
in interfaceRealVector
- Overrides:
ebeDivide
in classAbstractRealVector
- Parameters:
v
- vector by which instance elements must be divided- Returns:
- a vector containing this[i] / v[i] for all i
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
ebeDivide
public ArrayRealVector ebeDivide(ArrayRealVector v) throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException
- if v is not the same size as this
-
getData
public double[] getData()
Returns vector entries as a double array.- Specified by:
getData
in interfaceRealVector
- Overrides:
getData
in classAbstractRealVector
- Returns:
- double array of entries
-
getDataRef
public double[] getDataRef()
Returns a reference to the underlying data array.Does not make a fresh copy of the underlying data.
- Returns:
- array of entries
-
dotProduct
public double dotProduct(RealVector v) throws java.lang.IllegalArgumentException
Compute the dot product.- Specified by:
dotProduct
in interfaceRealVector
- Overrides:
dotProduct
in classAbstractRealVector
- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
dotProduct
public double dotProduct(double[] v) throws java.lang.IllegalArgumentException
Compute the dot product.- Specified by:
dotProduct
in interfaceRealVector
- Overrides:
dotProduct
in classAbstractRealVector
- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
dotProduct
public double dotProduct(ArrayRealVector v) throws java.lang.IllegalArgumentException
Compute the dot product.- Parameters:
v
- vector with which dot product should be computed- Returns:
- the scalar dot product between instance and v
- Throws:
java.lang.IllegalArgumentException
- if v is not the same size as this
-
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
- Overrides:
getNorm
in classAbstractRealVector
- Returns:
- norm
- See Also:
RealVector.getL1Norm()
,RealVector.getLInfNorm()
,RealVector.getDistance(RealVector)
-
getL1Norm
public double getL1Norm()
Returns the L1 norm of the vector.The L1 norm is the sum of the absolute values of elements.
- Specified by:
getL1Norm
in interfaceRealVector
- Overrides:
getL1Norm
in classAbstractRealVector
- Returns:
- norm
- See Also:
RealVector.getNorm()
,RealVector.getLInfNorm()
,RealVector.getL1Distance(RealVector)
-
getLInfNorm
public double getLInfNorm()
Returns the L∞ norm of the vector.The L∞ norm is the max of the absolute values of elements.
- Specified by:
getLInfNorm
in interfaceRealVector
- Overrides:
getLInfNorm
in classAbstractRealVector
- Returns:
- norm
- See Also:
RealVector.getNorm()
,RealVector.getL1Norm()
,RealVector.getLInfDistance(RealVector)
-
getDistance
public double getDistance(RealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
- Specified by:
getDistance
in interfaceRealVector
- Overrides:
getDistance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
- See Also:
RealVector.getL1Distance(RealVector)
,RealVector.getLInfDistance(RealVector)
,RealVector.getNorm()
-
getDistance
public double getDistance(double[] v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
- Specified by:
getDistance
in interfaceRealVector
- Overrides:
getDistance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
- See Also:
RealVector.getL1Distance(double[])
,RealVector.getLInfDistance(double[])
,RealVector.getNorm()
-
getDistance
public double getDistance(ArrayRealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
java.lang.IllegalArgumentException
- if v is not the same size as this- See Also:
getDistance(RealVector)
,getL1Distance(ArrayRealVector)
,getLInfDistance(ArrayRealVector)
,getNorm()
-
getL1Distance
public double getL1Distance(RealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
- Specified by:
getL1Distance
in interfaceRealVector
- Overrides:
getL1Distance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
- See Also:
RealVector.getDistance(RealVector)
,RealVector.getLInfDistance(RealVector)
,RealVector.getL1Norm()
-
getL1Distance
public double getL1Distance(double[] v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
- Specified by:
getL1Distance
in interfaceRealVector
- Overrides:
getL1Distance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
- See Also:
RealVector.getDistance(double[])
,RealVector.getLInfDistance(double[])
,RealVector.getL1Norm()
-
getL1Distance
public double getL1Distance(ArrayRealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
java.lang.IllegalArgumentException
- if v is not the same size as this- See Also:
getDistance(RealVector)
,getL1Distance(ArrayRealVector)
,getLInfDistance(ArrayRealVector)
,getNorm()
-
getLInfDistance
public double getLInfDistance(RealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
- Specified by:
getLInfDistance
in interfaceRealVector
- Overrides:
getLInfDistance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
- See Also:
RealVector.getDistance(RealVector)
,RealVector.getL1Distance(RealVector)
,RealVector.getLInfNorm()
-
getLInfDistance
public double getLInfDistance(double[] v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
- Specified by:
getLInfDistance
in interfaceRealVector
- Overrides:
getLInfDistance
in classAbstractRealVector
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
- See Also:
RealVector.getDistance(double[])
,RealVector.getL1Distance(double[])
,RealVector.getLInfNorm()
-
getLInfDistance
public double getLInfDistance(ArrayRealVector v) throws java.lang.IllegalArgumentException
Distance between two vectors.This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
- Parameters:
v
- vector to which distance is requested- Returns:
- distance between two vectors.
- Throws:
java.lang.IllegalArgumentException
- if v is not the same size as this- See Also:
getDistance(RealVector)
,getL1Distance(ArrayRealVector)
,getLInfDistance(ArrayRealVector)
,getNorm()
-
unitVector
public RealVector unitVector() throws java.lang.ArithmeticException
Creates a unit vector pointing in the direction of this vector.The instance is not changed by this method.
- Specified by:
unitVector
in interfaceRealVector
- Overrides:
unitVector
in classAbstractRealVector
- Returns:
- a unit vector pointing in direction of this vector
- Throws:
java.lang.ArithmeticException
- if the norm is null
-
unitize
public void unitize() throws java.lang.ArithmeticException
Converts this vector into a unit vector.The instance itself is changed by this method.
- Specified by:
unitize
in interfaceRealVector
- Overrides:
unitize
in classAbstractRealVector
- Throws:
java.lang.ArithmeticException
- if the norm is zero.
-
projection
public RealVector projection(RealVector v)
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
-
projection
public RealVector projection(double[] v)
Find the orthogonal projection of this vector onto another vector.- Specified by:
projection
in interfaceRealVector
- Overrides:
projection
in classAbstractRealVector
- Parameters:
v
- vector onto which instance must be projected- Returns:
- projection of the instance onto v
-
projection
public ArrayRealVector projection(ArrayRealVector 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:
java.lang.IllegalArgumentException
- if v is not the same size as this
-
outerProduct
public RealMatrix outerProduct(RealVector v) throws java.lang.IllegalArgumentException
Compute the outer product.- Specified by:
outerProduct
in interfaceRealVector
- Overrides:
outerProduct
in classAbstractRealVector
- Parameters:
v
- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
outerProduct
public RealMatrix outerProduct(ArrayRealVector v) throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException
- if v is not the same size as this
-
outerProduct
public RealMatrix outerProduct(double[] v) throws java.lang.IllegalArgumentException
Compute the outer product.- Specified by:
outerProduct
in interfaceRealVector
- Overrides:
outerProduct
in classAbstractRealVector
- Parameters:
v
- vector with which outer product should be computed- Returns:
- the square matrix outer product between instance and v
- Throws:
DimensionMismatchException
- ifv
is not the same size as this vector.java.lang.IllegalArgumentException
-
getEntry
public double getEntry(int index) throws MatrixIndexException
Returns the entry in the specified index.- Specified by:
getEntry
in interfaceRealVector
- Parameters:
index
- Index location of entry to be fetched.- Returns:
- the vector entry at
index
. - Throws:
MatrixIndexException
- See Also:
RealVector.setEntry(int, double)
-
getDimension
public int getDimension()
Returns the size of the vector.- Specified by:
getDimension
in interfaceRealVector
- Returns:
- size
-
append
public RealVector append(RealVector v)
Construct a vector by appending a vector to this vector.- Specified by:
append
in interfaceRealVector
- Parameters:
v
- vector to append to this one.- Returns:
- a new vector
-
append
public ArrayRealVector append(ArrayRealVector v)
Construct a vector by appending a vector to this vector.- Parameters:
v
- vector to append to this one.- Returns:
- a new vector
-
append
public RealVector append(double in)
Construct a vector by appending a double to this vector.- Specified by:
append
in interfaceRealVector
- Parameters:
in
- double to append.- Returns:
- a new vector
-
append
public RealVector append(double[] in)
Construct a vector by appending a double array to this vector.- Specified by:
append
in interfaceRealVector
- Parameters:
in
- double array to append.- Returns:
- a new vector
-
getSubVector
public RealVector getSubVector(int index, int n)
Get a subvector from consecutive elements.- Specified by:
getSubVector
in interfaceRealVector
- Parameters:
index
- index of first element.n
- number of elements to be retrieved.- Returns:
- a vector containing n elements.
-
setEntry
public void setEntry(int index, double value)
Set a single element.- Specified by:
setEntry
in interfaceRealVector
- Parameters:
index
- element index.value
- new value for the element.- See Also:
RealVector.getEntry(int)
-
setSubVector
public void setSubVector(int index, RealVector v)
Set a set of consecutive elements.- Specified by:
setSubVector
in interfaceRealVector
- Overrides:
setSubVector
in classAbstractRealVector
- Parameters:
index
- index of first element to be set.v
- vector containing the values to set.- See Also:
RealVector.setSubVector(int, double[])
-
setSubVector
public void setSubVector(int index, double[] v)
Set a set of consecutive elements.- Specified by:
setSubVector
in interfaceRealVector
- Overrides:
setSubVector
in classAbstractRealVector
- Parameters:
index
- index of first element to be set.v
- vector containing the values to set.- See Also:
RealVector.setSubVector(int, RealVector)
-
set
public void set(int index, ArrayRealVector v) throws MatrixIndexException
Set a set of consecutive elements.- Parameters:
index
- index of first element to be set.v
- vector containing the values to set.- Throws:
MatrixIndexException
- if the index is inconsistent with vector size
-
set
public void set(double value)
Set all elements to a single value.- Specified by:
set
in interfaceRealVector
- Overrides:
set
in classAbstractRealVector
- 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
- Overrides:
toArray
in classAbstractRealVector
- Returns:
- array containing a copy of vector elements
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
checkVectorDimensions
protected void checkVectorDimensions(RealVector v) throws java.lang.IllegalArgumentException
Check if instance and specified vectors have the same dimension.- Overrides:
checkVectorDimensions
in classAbstractRealVector
- Parameters:
v
- vector to compare instance with- Throws:
java.lang.IllegalArgumentException
- if the vectors do not have the same dimension
-
checkVectorDimensions
protected void checkVectorDimensions(int n) throws java.lang.IllegalArgumentException
Check if instance dimension is equal to some expected value.- Overrides:
checkVectorDimensions
in classAbstractRealVector
- Parameters:
n
- expected dimension.- Throws:
java.lang.IllegalArgumentException
- if the dimension is inconsistent with vector size
-
isNaN
public boolean isNaN()
Returns true if any coordinate of this vector is NaN; false otherwise- Specified by:
isNaN
in interfaceRealVector
- Returns:
- true if any coordinate of this vector is NaN; false otherwise
-
isInfinite
public boolean isInfinite()
Returns true if any coordinate of this vector is infinite and none are NaN; false otherwise- Specified by:
isInfinite
in interfaceRealVector
- Returns:
- true if any coordinate of this vector is infinite and none are NaN; false otherwise
-
equals
public boolean equals(java.lang.Object other)
Test for the equality of two real vectors.If all coordinates of two real vectors are exactly the same, and none are
Double.NaN
, the two real vectors are considered to be equal.NaN
coordinates are considered to affect globally the vector and be equals to each other - i.e, if either (or all) coordinates of the real vector are equal toDouble.NaN
, the real vector is equal to a vector with allDouble.NaN
coordinates.- Overrides:
equals
in classjava.lang.Object
- Parameters:
other
- Object to test for equality to this- Returns:
- true if two vector objects are equal, false if object is null, not an instance of RealVector, or not equal to this RealVector instance
-
hashCode
public int hashCode()
Get a hashCode for the real vector.All NaN values have the same hash code.
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code value for this object
-
-