public class ArrayRealVector extends RealVector implements Serializable
RealVector
interface with a double array.RealVector.Entry
Constructor and Description |
---|
ArrayRealVector()
Build a 0-length vector.
|
ArrayRealVector(ArrayRealVector v)
Construct a vector from another vector, using a deep copy.
|
ArrayRealVector(ArrayRealVector v1,
ArrayRealVector v2)
Construct a vector by appending one vector to another vector.
|
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,
RealVector v2)
Construct a vector by appending one vector to another vector.
|
ArrayRealVector(double[] d)
Construct a vector from an array, copying the input array.
|
ArrayRealVector(Double[] d)
Construct a vector from an array.
|
ArrayRealVector(double[] v1,
ArrayRealVector v2)
Construct a vector by appending one vector to another vector.
|
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[] d,
int pos,
int size)
Construct a vector from part of an array.
|
ArrayRealVector(int size)
Construct a vector of zeroes.
|
ArrayRealVector(int size,
double preset)
Construct a vector with preset values.
|
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.
|
Modifier and Type | Method and Description |
---|---|
ArrayRealVector |
add(RealVector v)
Compute the sum of this vector and
v . |
void |
addToEntry(int index,
double increment)
Change an entry at the specified index.
|
ArrayRealVector |
append(ArrayRealVector v)
Construct a vector by appending a vector to this vector.
|
RealVector |
append(double v)
Construct a new vector by appending a double to this vector.
|
RealVector |
append(RealVector v)
Construct a new 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.
|
ArrayRealVector |
combine(double a,
double b,
RealVector y)
Returns a new vector representing
a * this + b * y , the linear
combination of this and y . |
ArrayRealVector |
combineToSelf(double a,
double b,
RealVector y)
Updates
this with the linear combination of this and y . |
ArrayRealVector |
copy()
Returns a (deep) copy of this vector.
|
double |
dotProduct(RealVector v)
Compute the dot product of this vector with
v . |
boolean |
equals(Object other)
Test for the equality of two real vectors.
|
double[] |
getDataRef()
Get a reference to the underlying data array.
|
int |
getDimension()
Returns the size of the vector.
|
double |
getDistance(RealVector v)
Distance between two vectors.
|
double |
getEntry(int index)
Return the entry at the specified index.
|
double |
getL1Distance(RealVector v)
Distance between two vectors.
|
double |
getL1Norm()
Returns the L1 norm of the vector.
|
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()
.
|
boolean |
isInfinite()
Check whether any coordinate of this vector is infinite and none
are
NaN . |
boolean |
isNaN()
Check if any coordinate of this vector is
NaN . |
ArrayRealVector |
map(UnivariateFunction function)
Acts as if implemented as:
return copy().mapToSelf(function);
Returns a new vector.
|
RealVector |
mapAddToSelf(double d)
Add a value to each entry.
|
RealVector |
mapDivideToSelf(double d)
Divide each entry by the argument.
|
RealVector |
mapMultiplyToSelf(double d)
Multiply each entry.
|
RealVector |
mapSubtractToSelf(double d)
Subtract a value from each entry.
|
ArrayRealVector |
mapToSelf(UnivariateFunction function)
Acts as if it is implemented as:
Entry e = null;
for (Iterator<Entry> it = iterator(); it.hasNext(); e = it.next()) {
e.setValue(function.value(e.getValue()));
}
Entries of this vector are modified in-place by this method.
|
RealMatrix |
outerProduct(RealVector v)
Compute the outer product.
|
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 sequence of consecutive elements.
|
ArrayRealVector |
subtract(RealVector v)
Subtract
v from this vector. |
double[] |
toArray()
Convert the vector to an array of
double s. |
String |
toString() |
double |
walkInDefaultOrder(RealVectorChangingVisitor visitor)
Visits (and possibly alters) all entries of this vector in default order
(increasing index).
|
double |
walkInDefaultOrder(RealVectorChangingVisitor visitor,
int start,
int end)
Visits (and possibly alters) some entries of this vector in default order
(increasing index).
|
double |
walkInDefaultOrder(RealVectorPreservingVisitor visitor)
Visits (but does not alter) all entries of this vector in default order
(increasing index).
|
double |
walkInDefaultOrder(RealVectorPreservingVisitor visitor,
int start,
int end)
Visits (but does not alter) some entries of this vector in default order
(increasing index).
|
double |
walkInOptimizedOrder(RealVectorChangingVisitor visitor)
Visits (and possibly alters) all entries of this vector in optimized
order.
|
double |
walkInOptimizedOrder(RealVectorChangingVisitor visitor,
int start,
int end)
Visits (and possibly change) some entries of this vector in optimized
order.
|
double |
walkInOptimizedOrder(RealVectorPreservingVisitor visitor)
Visits (but does not alter) all entries of this vector in optimized
order.
|
double |
walkInOptimizedOrder(RealVectorPreservingVisitor visitor,
int start,
int end)
Visits (but does not alter) some entries of this vector in optimized
order.
|
checkIndex, checkIndices, cosine, getMaxIndex, getMaxValue, getMinIndex, getMinValue, iterator, mapAdd, mapDivide, mapMultiply, mapSubtract, projection, unitize, unitVector, unmodifiableRealVector
public ArrayRealVector()
ArrayRealVector(ArrayRealVector, ArrayRealVector)
constructor
or one of the append
method (append(double)
, append(ArrayRealVector)
) to gather data
into this vector.public ArrayRealVector(int size)
size
- Size of the vector.public ArrayRealVector(int size, double preset)
size
- Size of the vectorpreset
- All entries will be set with this value.public ArrayRealVector(double[] d)
d
- Array.public ArrayRealVector(double[] d, boolean copyArray)
copyArray
may be
set to false
. This will prevent the copying and improve
performance as no new array will be built and no data will be copied.d
- Data for the new vector.copyArray
- if true
, the input array will be copied,
otherwise it will be referenced.NullArgumentException
- if d
is null
.ArrayRealVector(double[])
public ArrayRealVector(double[] d, int pos, int size)
d
- Array.pos
- Position of first entry.size
- Number of entries to copy.NullArgumentException
- if d
is null
.NumberIsTooLargeException
- if the size of d
is less
than pos + size
.public ArrayRealVector(Double[] d)
d
- Array of Double
s.public ArrayRealVector(Double[] d, int pos, int size)
d
- Array.pos
- Position of first entry.size
- Number of entries to copy.NullArgumentException
- if d
is null
.NumberIsTooLargeException
- if the size of d
is less
than pos + size
.public ArrayRealVector(RealVector v)
v
- vector to copy.NullArgumentException
- if v
is null
.public ArrayRealVector(ArrayRealVector v)
v
- Vector to copy.NullArgumentException
- if v
is null
.public ArrayRealVector(ArrayRealVector v, boolean deep)
v
- Vector to copy.deep
- If true
perform a deep copy, otherwise perform a
shallow copy.public ArrayRealVector(ArrayRealVector v1, ArrayRealVector v2)
v1
- First vector (will be put in front of the new vector).v2
- Second vector (will be put at back of the new vector).public ArrayRealVector(ArrayRealVector v1, RealVector v2)
v1
- First vector (will be put in front of the new vector).v2
- Second vector (will be put at back of the new vector).public ArrayRealVector(RealVector v1, ArrayRealVector v2)
v1
- First vector (will be put in front of the new vector).v2
- Second vector (will be put at back of the new vector).public ArrayRealVector(ArrayRealVector v1, double[] v2)
v1
- First vector (will be put in front of the new vector).v2
- Second vector (will be put at back of the new vector).public ArrayRealVector(double[] v1, ArrayRealVector v2)
v1
- First vector (will be put in front of the new vector).v2
- Second vector (will be put at back of the new vector).public ArrayRealVector(double[] v1, double[] v2)
v1
- first vector (will be put in front of the new vector)v2
- second vector (will be put at back of the new vector)public ArrayRealVector copy()
copy
in class RealVector
public ArrayRealVector add(RealVector v)
v
.
Returns a new vector. Does not change instance data.add
in class RealVector
v
- Vector to be added.this
+ v
.public ArrayRealVector subtract(RealVector v)
v
from this vector.
Returns a new vector. Does not change instance data.subtract
in class RealVector
v
- Vector to be subtracted.this
- v
.public ArrayRealVector map(UnivariateFunction function)
return copy().mapToSelf(function);Returns a new vector. Does not change instance data.
map
in class RealVector
function
- Function to apply to each entry.public ArrayRealVector mapToSelf(UnivariateFunction function)
Entry e = null; for (Iterator<Entry> it = iterator(); it.hasNext(); e = it.next()) { e.setValue(function.value(e.getValue())); }Entries of this vector are modified in-place by this method.
mapToSelf
in class RealVector
function
- Function to apply to each entry.public RealVector mapAddToSelf(double d)
mapAddToSelf
in class RealVector
d
- Value to be added to each entry.this
.public RealVector mapSubtractToSelf(double d)
mapSubtractToSelf
in class RealVector
d
- Value to be subtracted.this
.public RealVector mapMultiplyToSelf(double d)
mapMultiplyToSelf
in class RealVector
d
- Multiplication factor.this
.public RealVector mapDivideToSelf(double d)
mapDivideToSelf
in class RealVector
d
- Value to divide by.this
.public double[] getDataRef()
public double dotProduct(RealVector v)
v
.dotProduct
in class RealVector
v
- Vector with which dot product should be computedv
.public double getNorm()
The L2 norm is the root of the sum of the squared elements.
getNorm
in class RealVector
RealVector.getL1Norm()
,
RealVector.getLInfNorm()
,
RealVector.getDistance(RealVector)
public double getL1Norm()
The L1 norm is the sum of the absolute values of the elements.
getL1Norm
in class RealVector
RealVector.getNorm()
,
RealVector.getLInfNorm()
,
RealVector.getL1Distance(RealVector)
public double getLInfNorm()
The L∞ norm is the max of the absolute values of the elements.
getLInfNorm
in class RealVector
RealVector.getNorm()
,
RealVector.getL1Norm()
,
RealVector.getLInfDistance(RealVector)
public double getDistance(RealVector v)
This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of element differences, or Euclidean distance.
getDistance
in class RealVector
v
- Vector to which distance is requested.RealVector.getL1Distance(RealVector)
,
RealVector.getLInfDistance(RealVector)
,
RealVector.getNorm()
public double getL1Distance(RealVector v)
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of the elements differences.
getL1Distance
in class RealVector
v
- Vector to which distance is requested.public double getLInfDistance(RealVector v)
This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of element differences.
getLInfDistance
in class RealVector
v
- Vector to which distance is requested.RealVector.getDistance(RealVector)
,
RealVector.getL1Distance(RealVector)
,
RealVector.getLInfNorm()
public RealMatrix outerProduct(RealVector v)
outerProduct
in class RealVector
v
- Vector with which outer product should be computed.v
.public double getEntry(int index)
getEntry
in class RealVector
index
- Index location of entry to be fetched.index
.RealVector.setEntry(int, double)
public int getDimension()
getDimension
in class RealVector
public RealVector append(RealVector v)
append
in class RealVector
v
- vector to append to this one.public ArrayRealVector append(ArrayRealVector v)
v
- Vector to append to this one.public RealVector append(double v)
append
in class RealVector
v
- double to append.public RealVector getSubVector(int index, int n)
getSubVector
in class RealVector
index
- index of first element.n
- number of elements to be retrieved.public void setEntry(int index, double value)
setEntry
in class RealVector
index
- element index.value
- new value for the element.RealVector.getEntry(int)
public void addToEntry(int index, double increment)
addToEntry
in class RealVector
index
- Index location of entry to be set.increment
- Value to add to the vector entry.public void setSubVector(int index, RealVector v)
setSubVector
in class RealVector
index
- index of first element to be set.v
- vector containing the values to set.public 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 inconsistent with the vector
size.public void set(double value)
set
in class RealVector
value
- Single value to set for all elements.public double[] toArray()
double
s.
The array is independent from this vector data: the elements
are copied.toArray
in class RealVector
protected void checkVectorDimensions(RealVector v)
checkVectorDimensions
in class RealVector
v
- Vector to compare instance with.DimensionMismatchException
- if the vectors do not
have the same dimension.protected void checkVectorDimensions(int n)
checkVectorDimensions
in class RealVector
n
- Expected dimension.DimensionMismatchException
- if the dimension is
inconsistent with vector size.public boolean isNaN()
NaN
.isNaN
in class RealVector
true
if any coordinate of this vector is NaN
, false
otherwise.public boolean isInfinite()
NaN
.isInfinite
in class RealVector
true
if any coordinate of this vector is infinite and
none are NaN
, false
otherwise.public boolean equals(Object other)
Test for the equality of two real vectors. If all coordinates of two real vectors are exactly the same, and none
are 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 to NaN
, the real vector is equal to a vector with all NaN
coordinates.
This method must be overriden by concrete subclasses of RealVector
(the current implementation
throws an exception).
equals
in class RealVector
other
- Object to test for equality.true
if two vector objects are equal, false
if other
is null, not an instance of
RealVector
, or
not equal to this RealVector
instance.public int hashCode()
RealVector
(current implementation throws an
exception). All NaN
values have the same hash code.hashCode
in class RealVector
public ArrayRealVector combine(double a, double b, RealVector y)
a * this + b * y
, the linear
combination of this
and y
.
Returns a new vector. Does not change instance data.combine
in class RealVector
a
- Coefficient of this
.b
- Coefficient of y
.y
- Vector with which this
is linearly combined.a * this[i] + b * y[i]
for all i
.public ArrayRealVector combineToSelf(double a, double b, RealVector y)
this
with the linear combination of this
and y
.combineToSelf
in class RealVector
a
- Weight of this
.b
- Weight of y
.y
- Vector with which this
is linearly combined.this
, with components equal to a * this[i] + b * y[i]
for all i
.public double walkInDefaultOrder(RealVectorPreservingVisitor visitor)
walkInDefaultOrder
in class RealVector
visitor
- the visitor to be used to process the entries of this
vectorRealVectorPreservingVisitor.end()
at the end of the walkpublic double walkInDefaultOrder(RealVectorPreservingVisitor visitor, int start, int end)
walkInDefaultOrder
in class RealVector
visitor
- visitor to be used to process the entries of this vectorstart
- the index of the first entry to be visitedend
- the index of the last entry to be visited (inclusive)RealVectorPreservingVisitor.end()
at the end of the walkpublic double walkInOptimizedOrder(RealVectorPreservingVisitor visitor)
walkInOptimizedOrder
in class RealVector
visitor
- the visitor to be used to process the entries of this
vectorRealVectorPreservingVisitor.end()
at the end of the walkpublic double walkInOptimizedOrder(RealVectorPreservingVisitor visitor, int start, int end)
walkInOptimizedOrder
in class RealVector
visitor
- visitor to be used to process the entries of this vectorstart
- the index of the first entry to be visitedend
- the index of the last entry to be visited (inclusive)RealVectorPreservingVisitor.end()
at the end of the walkpublic double walkInDefaultOrder(RealVectorChangingVisitor visitor)
walkInDefaultOrder
in class RealVector
visitor
- the visitor to be used to process and modify the entries
of this vectorRealVectorChangingVisitor.end()
at the end of the walkpublic double walkInDefaultOrder(RealVectorChangingVisitor visitor, int start, int end)
walkInDefaultOrder
in class RealVector
visitor
- visitor to be used to process the entries of this vectorstart
- the index of the first entry to be visitedend
- the index of the last entry to be visited (inclusive)RealVectorChangingVisitor.end()
at the end of the walkpublic double walkInOptimizedOrder(RealVectorChangingVisitor visitor)
walkInOptimizedOrder
in class RealVector
visitor
- the visitor to be used to process the entries of this
vectorRealVectorChangingVisitor.end()
at the end of the walkpublic double walkInOptimizedOrder(RealVectorChangingVisitor visitor, int start, int end)
walkInOptimizedOrder
in class RealVector
visitor
- visitor to be used to process the entries of this vectorstart
- the index of the first entry to be visitedend
- the index of the last entry to be visited (inclusive)RealVectorChangingVisitor.end()
at the end of the walkCopyright © 2019 CNES. All rights reserved.