|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.math.linear.AbstractRealVector
org.apache.commons.math.linear.OpenMapRealVector
public class OpenMapRealVector
This class implements the RealVector interface with a OpenIntToDoubleHashMap backing store.
| Nested Class Summary | |
|---|---|
protected class |
OpenMapRealVector.OpenMapEntry
Implementation of Entry optimized for OpenMap. |
protected class |
OpenMapRealVector.OpenMapSparseIterator
Iterator class to do iteration over just the non-zero elements. |
| 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 | |
|---|---|
static double |
DEFAULT_ZERO_TOLERANCE
Default Tolerance for having a value considered zero. |
| Constructor Summary | |
|---|---|
|
OpenMapRealVector()
Build a 0-length vector. |
|
OpenMapRealVector(double[] values)
Create from a double array. |
|
OpenMapRealVector(Double[] values)
Create from a Double array. |
|
OpenMapRealVector(double[] values,
double epsilon)
Create from a double array, specifying zero tolerance. |
|
OpenMapRealVector(Double[] values,
double epsilon)
Create from a Double array. |
|
OpenMapRealVector(int dimension)
Construct a (dimension)-length vector of zeros. |
|
OpenMapRealVector(int dimension,
double epsilon)
Construct a (dimension)-length vector of zeros, specifying zero tolerance. |
|
OpenMapRealVector(int dimension,
int expectedSize)
Build a vector with known the sparseness (for advanced use only). |
|
OpenMapRealVector(int dimension,
int expectedSize,
double epsilon)
Build a vector with known the sparseness and zero tolerance setting (for advanced use only). |
|
OpenMapRealVector(OpenMapRealVector v)
Copy constructor. |
protected |
OpenMapRealVector(OpenMapRealVector v,
int resize)
Build a resized vector, for use with append. |
|
OpenMapRealVector(RealVector v)
Generic copy constructor. |
| Method Summary | |
|---|---|
OpenMapRealVector |
add(OpenMapRealVector v)
Optimized method to add two OpenMapRealVectors. |
RealVector |
add(RealVector v)
Compute the sum of this vector and v. |
OpenMapRealVector |
append(double d)
Construct a vector by appending a double to this vector. |
OpenMapRealVector |
append(double[] a)
Construct a vector by appending a double array to this vector. |
OpenMapRealVector |
append(OpenMapRealVector v)
Optimized method to append a OpenMapRealVector. |
OpenMapRealVector |
append(RealVector v)
Construct a vector by appending a vector to this vector. |
OpenMapRealVector |
copy()
Returns a (deep) copy of this vector. |
double |
dotProduct(OpenMapRealVector v)
Optimized method to compute the dot product with an OpenMapRealVector. |
double |
dotProduct(RealVector v)
Compute the dot product. |
OpenMapRealVector |
ebeDivide(double[] v)
Element-by-element division. |
OpenMapRealVector |
ebeDivide(RealVector v)
Element-by-element division. |
OpenMapRealVector |
ebeMultiply(double[] v)
Element-by-element multiplication. |
OpenMapRealVector |
ebeMultiply(RealVector v)
Element-by-element multiplication. |
boolean |
equals(Object obj)
Implementation Note: This performs an exact comparison, and as a result it is possible for a.subtract(b} to be the zero vector, while
a.equals(b) == false. |
double[] |
getData()
Returns vector entries as a double array. |
int |
getDimension()
Returns the size of the vector. |
double |
getDistance(double[] v)
Distance between two vectors. |
double |
getDistance(OpenMapRealVector v)
Optimized method to compute distance. |
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(OpenMapRealVector v)
Distance between two vectors. |
double |
getL1Distance(RealVector v)
Distance between two vectors. |
double |
getLInfDistance(double[] v)
Distance between two vectors. |
double |
getLInfDistance(RealVector v)
Distance between two vectors. |
double |
getSparcity()
Deprecated. as of 2.2 replaced by the correctly spelled getSparsity() |
double |
getSparsity()
|
OpenMapRealVector |
getSubVector(int index,
int n)
Get a subvector from consecutive elements. |
int |
hashCode()
|
protected boolean |
isDefaultValue(double value)
Determine if this value is within epsilon of zero. |
boolean |
isInfinite()
Check whether any coordinate of this vector is infinite and none are NaN. |
boolean |
isNaN()
Check whether any coordinate of this vector is NaN. |
OpenMapRealVector |
mapAdd(double d)
Add a value to each entry. |
OpenMapRealVector |
mapAddToSelf(double d)
Add a value to each entry. |
RealMatrix |
outerProduct(double[] v)
Compute the outer product. |
OpenMapRealVector |
projection(double[] v)
Find the orthogonal projection of this vector onto another vector. |
RealVector |
projection(RealVector v)
Find the orthogonal projection of this vector onto another vector. |
void |
set(double value)
Set all elements to a single value. |
void |
setEntry(int index,
double value)
Set a single element. |
void |
setSubVector(int index,
double[] v)
Set a set of consecutive elements. |
void |
setSubVector(int index,
RealVector v)
Set a set of consecutive elements. |
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. |
OpenMapRealVector |
subtract(double[] v)
Subtract v from this vector. |
OpenMapRealVector |
subtract(OpenMapRealVector v)
Optimized method to subtract OpenMapRealVectors. |
OpenMapRealVector |
subtract(RealVector v)
Subtract v from this vector. |
double[] |
toArray()
Convert the vector to a double array. |
void |
unitize()
Converts this vector into a unit vector. |
OpenMapRealVector |
unitVector()
Creates a unit vector pointing in the direction of this vector. |
| Methods inherited from class org.apache.commons.math.linear.AbstractRealVector |
|---|
add, checkIndex, checkVectorDimensions, checkVectorDimensions, dotProduct, getL1Norm, getLInfNorm, getMaxIndex, getMaxValue, getMinIndex, getMinValue, getNorm, iterator, map, mapAbs, mapAbsToSelf, mapAcos, mapAcosToSelf, mapAsin, mapAsinToSelf, mapAtan, mapAtanToSelf, mapCbrt, mapCbrtToSelf, mapCeil, mapCeilToSelf, mapCos, mapCosh, mapCoshToSelf, mapCosToSelf, mapDivide, mapDivideToSelf, mapExp, mapExpm1, mapExpm1ToSelf, mapExpToSelf, mapFloor, mapFloorToSelf, mapInv, mapInvToSelf, mapLog, mapLog10, mapLog10ToSelf, mapLog1p, mapLog1pToSelf, mapLogToSelf, mapMultiply, mapMultiplyToSelf, mapPow, mapPowToSelf, mapRint, mapRintToSelf, mapSignum, mapSignumToSelf, mapSin, mapSinh, mapSinhToSelf, mapSinToSelf, mapSqrt, mapSqrtToSelf, mapSubtract, mapSubtractToSelf, mapTan, mapTanh, mapTanhToSelf, mapTanToSelf, mapToSelf, mapUlp, mapUlpToSelf, outerProduct |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.apache.commons.math.linear.RealVector |
|---|
add, dotProduct, getL1Norm, getLInfNorm, getNorm, iterator, map, mapAbs, mapAbsToSelf, mapAcos, mapAcosToSelf, mapAsin, mapAsinToSelf, mapAtan, mapAtanToSelf, mapCbrt, mapCbrtToSelf, mapCeil, mapCeilToSelf, mapCos, mapCosh, mapCoshToSelf, mapCosToSelf, mapDivide, mapDivideToSelf, mapExp, mapExpm1, mapExpm1ToSelf, mapExpToSelf, mapFloor, mapFloorToSelf, mapInv, mapInvToSelf, mapLog, mapLog10, mapLog10ToSelf, mapLog1p, mapLog1pToSelf, mapLogToSelf, mapMultiply, mapMultiplyToSelf, mapPow, mapPowToSelf, mapRint, mapRintToSelf, mapSignum, mapSignumToSelf, mapSin, mapSinh, mapSinhToSelf, mapSinToSelf, mapSqrt, mapSqrtToSelf, mapSubtract, mapSubtractToSelf, mapTan, mapTanh, mapTanhToSelf, mapTanToSelf, mapToSelf, mapUlp, mapUlpToSelf, outerProduct |
| Field Detail |
|---|
public static final double DEFAULT_ZERO_TOLERANCE
| Constructor Detail |
|---|
public OpenMapRealVector()
Zero-length vectors may be used to initialized construction of vectors
by data gathering. We start with zero-length and use either the OpenMapRealVector(OpenMapRealVector, int) constructor
or one of the append method (append(double), append(double[]), append(RealVector)) to gather data
into this vector.
public OpenMapRealVector(int dimension)
dimension - size of the vector
public OpenMapRealVector(int dimension,
double epsilon)
dimension - Size of the vectorepsilon - The tolerance for having a value considered zero
protected OpenMapRealVector(OpenMapRealVector v,
int resize)
v - The original vectorresize - The amount to resize it
public OpenMapRealVector(int dimension,
int expectedSize)
dimension - The size of the vectorexpectedSize - The expected number of non-zero entries
public OpenMapRealVector(int dimension,
int expectedSize,
double epsilon)
dimension - The size of the vectorexpectedSize - The expected number of non-zero entriesepsilon - The tolerance for having a value considered zeropublic OpenMapRealVector(double[] values)
values - The set of values to create from
public OpenMapRealVector(double[] values,
double epsilon)
values - The set of values to create fromepsilon - The tolerance for having a value considered zeropublic OpenMapRealVector(Double[] values)
values - The set of values to create from
public OpenMapRealVector(Double[] values,
double epsilon)
values - The set of values to create fromepsilon - The tolerance for having a value considered zeropublic OpenMapRealVector(OpenMapRealVector v)
v - The instance to copy frompublic OpenMapRealVector(RealVector v)
v - The instance to copy from| Method Detail |
|---|
protected boolean isDefaultValue(double value)
value - The value to test
true if this value is within epsilon to zero, false otherwise
public RealVector add(RealVector v)
throws IllegalArgumentException
v.
add in interface RealVectoradd in class AbstractRealVectorv - Vector to be added.
this + v.
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public OpenMapRealVector add(OpenMapRealVector v)
throws IllegalArgumentException
v - Vector to add with
this with v
IllegalArgumentException - If the dimensions don't matchpublic OpenMapRealVector append(OpenMapRealVector v)
v - vector to append
v to selfpublic OpenMapRealVector append(RealVector v)
append in interface RealVectorv - vector to append to this one.
public OpenMapRealVector append(double d)
append in interface RealVectord - double to append.
public OpenMapRealVector append(double[] a)
append in interface RealVectora - double array to append.
public OpenMapRealVector copy()
copy in interface RealVectorcopy in class AbstractRealVector
public double dotProduct(OpenMapRealVector v)
throws IllegalArgumentException
v - The vector to compute the dot product with
this and v
IllegalArgumentException - If the dimensions don't match
public double dotProduct(RealVector v)
throws IllegalArgumentException
dotProduct in interface RealVectordotProduct in class AbstractRealVectorv - vector with which dot product should be computed
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public OpenMapRealVector ebeDivide(RealVector v)
throws IllegalArgumentException
ebeDivide in interface RealVectorv - vector by which instance elements must be divided
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public OpenMapRealVector ebeDivide(double[] v)
throws IllegalArgumentException
ebeDivide in interface RealVectorebeDivide in class AbstractRealVectorv - vector by which instance elements must be divided
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public OpenMapRealVector ebeMultiply(RealVector v)
throws IllegalArgumentException
ebeMultiply in interface RealVectorv - vector by which instance elements must be multiplied
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public OpenMapRealVector ebeMultiply(double[] v)
throws IllegalArgumentException
ebeMultiply in interface RealVectorebeMultiply in class AbstractRealVectorv - vector by which instance elements must be multiplied
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public OpenMapRealVector getSubVector(int index,
int n)
throws MatrixIndexException
getSubVector in interface RealVectorindex - index of first element.n - number of elements to be retrieved.
MatrixIndexExceptionpublic double[] getData()
getData in interface RealVectorgetData in class AbstractRealVectorpublic int getDimension()
getDimension in interface RealVector
public double getDistance(OpenMapRealVector v)
throws IllegalArgumentException
v - The vector to compute distance to
this and v
IllegalArgumentException - If the dimensions don't match
public double getDistance(RealVector v)
throws IllegalArgumentException
This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
getDistance in interface RealVectorgetDistance in class AbstractRealVectorv - vector to which distance is requested
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentExceptionRealVector.getL1Distance(RealVector),
RealVector.getLInfDistance(RealVector),
RealVector.getNorm()
public double getDistance(double[] v)
throws IllegalArgumentException
This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.
getDistance in interface RealVectorgetDistance in class AbstractRealVectorv - vector to which distance is requested
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentExceptionRealVector.getL1Distance(double[]),
RealVector.getLInfDistance(double[]),
RealVector.getNorm()
public double getEntry(int index)
throws MatrixIndexException
getEntry in interface RealVectorindex - Index location of entry to be fetched.
index.
MatrixIndexExceptionRealVector.setEntry(int, double)public double getL1Distance(OpenMapRealVector v)
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
v - vector to which distance is requested
public double getL1Distance(RealVector v)
throws IllegalArgumentException
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
getL1Distance in interface RealVectorgetL1Distance in class AbstractRealVectorv - vector to which distance is requested
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentExceptionRealVector.getDistance(RealVector),
RealVector.getLInfDistance(RealVector),
RealVector.getL1Norm()
public double getL1Distance(double[] v)
throws IllegalArgumentException
This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.
getL1Distance in interface RealVectorgetL1Distance in class AbstractRealVectorv - vector to which distance is requested
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentExceptionRealVector.getDistance(double[]),
RealVector.getLInfDistance(double[]),
RealVector.getL1Norm()
public double getLInfDistance(RealVector v)
throws IllegalArgumentException
This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
getLInfDistance in interface RealVectorgetLInfDistance in class AbstractRealVectorv - vector to which distance is requested
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentExceptionRealVector.getDistance(RealVector),
RealVector.getL1Distance(RealVector),
RealVector.getLInfNorm()
public double getLInfDistance(double[] v)
throws IllegalArgumentException
This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.
getLInfDistance in interface RealVectorgetLInfDistance in class AbstractRealVectorv - vector to which distance is requested
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentExceptionRealVector.getDistance(double[]),
RealVector.getL1Distance(double[]),
RealVector.getLInfNorm()public boolean isInfinite()
NaN.
isInfinite in interface RealVectortrue if any coordinate of this vector is infinite and
none are NaN, false otherwise.public boolean isNaN()
NaN.
isNaN in interface RealVectortrue if any coordinate of this vector is NaN,
false otherwise.public OpenMapRealVector mapAdd(double d)
mapAdd in interface RealVectormapAdd in class AbstractRealVectord - Value to be added to each entry.
this + d.public OpenMapRealVector mapAddToSelf(double d)
mapAddToSelf in interface RealVectormapAddToSelf in class AbstractRealVectord - Value to be added to each entry.
this.
public RealMatrix outerProduct(double[] v)
throws IllegalArgumentException
outerProduct in interface RealVectorouterProduct in class AbstractRealVectorv - vector with which outer product should be computed
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public RealVector projection(RealVector v)
throws IllegalArgumentException
projection in interface RealVectorv - vector onto which instance must be projected
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public OpenMapRealVector projection(double[] v)
throws IllegalArgumentException
projection in interface RealVectorprojection in class AbstractRealVectorv - vector onto which instance must be projected
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public void setEntry(int index,
double value)
throws MatrixIndexException
setEntry in interface RealVectorindex - element index.value - new value for the element.
MatrixIndexExceptionRealVector.getEntry(int)
public void setSubVector(int index,
RealVector v)
throws MatrixIndexException
setSubVector in interface RealVectorsetSubVector in class AbstractRealVectorindex - index of first element to be set.v - vector containing the values to set.
MatrixIndexExceptionRealVector.setSubVector(int, double[])
public void setSubVector(int index,
double[] v)
throws MatrixIndexException
setSubVector in interface RealVectorsetSubVector in class AbstractRealVectorindex - index of first element to be set.v - vector containing the values to set.
MatrixIndexExceptionRealVector.setSubVector(int, RealVector)public void set(double value)
set in interface RealVectorset in class AbstractRealVectorvalue - single value to set for all elements
public OpenMapRealVector subtract(OpenMapRealVector v)
throws IllegalArgumentException
v - The vector to subtract from this
this and v
IllegalArgumentException - If the dimensions don't match
public OpenMapRealVector subtract(RealVector v)
throws IllegalArgumentException
v from this vector.
subtract in interface RealVectorsubtract in class AbstractRealVectorv - Vector to be subtracted.
this - v.
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentException
public OpenMapRealVector subtract(double[] v)
throws IllegalArgumentException
v from this vector.
subtract in interface RealVectorsubtract in class AbstractRealVectorv - Vector to be subtracted.
this - v.
DimensionMismatchException - if v is not the same size as this vector.
IllegalArgumentExceptionpublic OpenMapRealVector unitVector()
The instance is not changed by this method.
unitVector in interface RealVectorunitVector in class AbstractRealVectorpublic void unitize()
The instance itself is changed by this method.
unitize in interface RealVectorunitize in class AbstractRealVectorpublic double[] toArray()
The array is independent from vector data, it's elements are copied.
toArray in interface RealVectortoArray in class AbstractRealVectorpublic int hashCode()
Implementation Note: This works on exact values, and as a result
it is possible for a.subtract(b) to be the zero vector, while
a.hashCode() != b.hashCode().
hashCode in class Objectpublic boolean equals(Object obj)
Implementation Note: This performs an exact comparison, and as a result
it is possible for a.subtract(b} to be the zero vector, while
a.equals(b) == false.
equals in class Object@Deprecated public double getSparcity()
getSparsity()
public double getSparsity()
public Iterator<RealVector.Entry> sparseIterator()
RealVector.iterator().
sparseIterator in interface RealVectorsparseIterator in class AbstractRealVector
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||