KeyType - The type of the keys (indices) into the infinite dimensional vector.public class DefaultInfiniteVector<KeyType> extends AbstractMutableDoubleMap<KeyType> implements InfiniteVector<KeyType>
InfiniteVector backed by a
LinkedHashMap.| Modifier and Type | Class and Description |
|---|---|
protected class |
DefaultInfiniteVector.SimpleIterator
Simple iterator for DefaultInfiniteVector
|
AbstractMutableDoubleMap.Entry<KeyType>, AbstractMutableDoubleMap.SimpleEntry<KeyType>, AbstractMutableDoubleMap.SimpleEntrySet<KeyType>InfiniteVector.Entry<KeyType>, InfiniteVector.KeyValueConsumer<KeyType>| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY
The default capacity is 16.
|
map| Modifier | Constructor and Description |
|---|---|
|
DefaultInfiniteVector()
Creates a new, empty instance of
DefaultInfiniteVector. |
|
DefaultInfiniteVector(int initialCapacity)
Creates a new, empty instance of
DefaultInfiniteVector with the
given initial capacity. |
protected |
DefaultInfiniteVector(java.util.LinkedHashMap<KeyType,MutableDouble> map)
Creates a new
AbstractMapInfiniteVector with the given backing
map. |
| Modifier and Type | Method and Description |
|---|---|
double |
angle(InfiniteVector<KeyType> other)
Computes the angle between two Vectors.
|
DefaultInfiniteVector<KeyType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
void |
compact()
Removes entries from the map with value of 0.0
|
double |
cosine(InfiniteVector<KeyType> other)
Computes the cosine between two Vectors
|
double |
dot(InfiniteVector<KeyType> other)
The inner product of this vector with the given vector.
|
double |
dotProduct(InfiniteVector<KeyType> other)
The inner product of this vector with the given vector.
|
InfiniteVector<KeyType> |
dotTimes(InfiniteVector<KeyType> other)
Element-wise multiplication of
this and other |
void |
dotTimesEquals(InfiniteVector<KeyType> other)
Inline element-wise multiplication of
this and
other |
boolean |
equals(InfiniteVector<KeyType> other,
double effectiveZero)
Determines if two RingType objects are effectively equal
|
boolean |
equals(java.lang.Object other)
Determines if two RingType objects are equal
|
double |
euclideanDistance(InfiniteVector<KeyType> other)
Euclidean distance between
this and other,
which is the 2-norm between the difference of the Vectors |
double |
euclideanDistanceSquared(InfiniteVector<KeyType> other)
Squared Euclidean distance between
this and
other, which is the 2-norm between the difference of the
Vectors |
void |
forEachEntry(InfiniteVector.KeyValueConsumer<? super KeyType> consumer)
Applies the given function to each active entry in this vector.
|
void |
forEachNonZero(InfiniteVector.KeyValueConsumer<? super KeyType> consumer)
Applies the given function to each non-zero entry in this vector.
|
int |
hashCode() |
boolean |
isUnitVector()
Determines if this vector is a unit vector (norm2 = 1.0).
|
boolean |
isUnitVector(double tolerance)
Determines if this vector is a unit vector within some tolerance for the
2-norm.
|
boolean |
isZero()
Determines if this ring is equal to zero.
|
boolean |
isZero(double effectiveZero)
Determines if this ring is equal to zero using the element-wise effective
zero value.
|
java.util.Iterator<InfiniteVector.Entry<KeyType>> |
iterator() |
InfiniteVector<KeyType> |
minus(InfiniteVector<KeyType> other)
Arithmetic subtraction of
other from this |
void |
minusEquals(InfiniteVector<KeyType> other)
Inline arithmetic subtraction of
other from
this |
InfiniteVector<KeyType> |
negative()
Returns the element-wise negation of
this, such that
this.plus( this.negative() ) has only zero elements. |
void |
negativeEquals()
Inline element-wise negation of
this |
double |
norm(double power)
Returns the p-norm of the Vector with the given power.
|
double |
norm1()
1-norm of the vector (sum of absolute values in the vector)
|
double |
norm2()
2-norm of the vector (aka Euclidean distance of the vector)
|
double |
norm2Squared()
Squared 2-norm of the vector (aka squared Euclidean distance of the
vector)
|
double |
normInfinity()
Returns the infinity norm of the Vector, which is the maximum
absolute value of an element in the Vector.
|
InfiniteVector<KeyType> |
plus(InfiniteVector<KeyType> other)
Arithmetic addition of
this and other |
void |
plusEquals(InfiniteVector<KeyType> other)
Inline arithmetic addition of
this and other |
InfiniteVector<KeyType> |
scale(double scaleFactor)
Element-wise scaling of
this by scaleFactor |
InfiniteVector<KeyType> |
scaledMinus(double scaleFactor,
InfiniteVector<KeyType> other)
Arithmetic subtraction
other after element-wise scaling of
other by scaleFactor from this. |
void |
scaledMinusEquals(double scaleFactor,
InfiniteVector<KeyType> other)
Inline arithmetic subtraction of
other after element-wise
scaling of other by scaleFactor from this. |
InfiniteVector<KeyType> |
scaledPlus(double scaleFactor,
InfiniteVector<KeyType> other)
Arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
void |
scaledPlusEquals(double scaleFactor,
InfiniteVector<KeyType> other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
void |
scaleEquals(double scaleFactor)
Inline element-wise scaling of
this by
scaleFactor |
double |
sum()
Computes the sum of the elements in the vector.
|
java.lang.String |
toString() |
InfiniteVector<KeyType> |
unitVector()
Returns the unit vector of this vector.
|
void |
unitVectorEquals()
Modifies this vector to be a the unit vector.
|
void |
zero()
Zeros out all elements of
this, so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 ); |
asMap, entrySet, get, increment, setclear, containsKey, decrement, decrement, decrementAll, decrementAll, getMaxValue, getMaxValueKey, getMaxValueKeys, getMinValue, getMinValueKey, getMinValueKeys, increment, incrementAll, incrementAll, isEmpty, keySet, setAll, setAll, sizefinalize, getClass, notify, notifyAll, wait, wait, waitgetMaxValue, getMinValueasMap, decrement, decrement, decrementAll, decrementAll, entrySet, get, getMaxValue, getMinValue, increment, increment, incrementAll, incrementAll, set, setAll, setAllclear, containsKey, getMaxValueKey, getMaxValueKeys, getMinValueKey, getMinValueKeys, isEmpty, keySet, sizepublic static final int DEFAULT_INITIAL_CAPACITY
public DefaultInfiniteVector()
DefaultInfiniteVector.public DefaultInfiniteVector(int initialCapacity)
DefaultInfiniteVector with the
given initial capacity.initialCapacity - The initial capacity of the data structure. Must be positive.protected DefaultInfiniteVector(java.util.LinkedHashMap<KeyType,MutableDouble> map)
AbstractMapInfiniteVector with the given backing
map.map - The backing map that the data is stored in.public DefaultInfiniteVector<KeyType> clone()
AbstractCloneableSerializableObject class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone() to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone() as the basis for your implementation.clone in interface Ring<InfiniteVector<KeyType>>clone in interface CloneableSerializableclone in class AbstractMutableDoubleMap<KeyType>public boolean equals(java.lang.Object other)
Ringequals in interface Ring<InfiniteVector<KeyType>>equals in class java.lang.Objectother - RingType to compare against thispublic boolean equals(InfiniteVector<KeyType> other, double effectiveZero)
Ringequals in interface Ring<InfiniteVector<KeyType>>other - RingType to compare against thiseffectiveZero - tolerance threshold for element-wise equalitypublic int hashCode()
hashCode in class java.lang.Objectpublic double sum()
VectorSpacesum in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>public double norm1()
VectorSpacenorm1 in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>public double norm2()
VectorSpacenorm2 in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>public double norm2Squared()
VectorSpacenorm2Squared in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>public double normInfinity()
VectorSpacenormInfinity in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>public double norm(double power)
VectorSpacenorm in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>power - Power to exponentiate each entry, must be greater than 0.0,
Double.POSITIVE_INFINITYpublic double cosine(InfiniteVector<KeyType> other)
VectorSpacecosine in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>other - another vector with which to compute the cosine, must be the
same dimension as thispublic double angle(InfiniteVector<KeyType> other)
VectorSpaceangle in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>other - Another vector with which to compute the angle. Must be the same
dimensionality.public double euclideanDistance(InfiniteVector<KeyType> other)
VectorSpacethis and other,
which is the 2-norm between the difference of the VectorseuclideanDistance in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>other - Vector to which to compute the distance, must be the same
dimension as thispublic double euclideanDistanceSquared(InfiniteVector<KeyType> other)
VectorSpacethis and
other, which is the 2-norm between the difference of the
VectorseuclideanDistanceSquared in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>other - Vector to which to compute the squared distance, must be the
same dimension as thispublic InfiniteVector<KeyType> unitVector()
VectorSpaceunitVector in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>public void unitVectorEquals()
VectorSpaceunitVectorEquals in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>public boolean isUnitVector()
VectorSpaceisUnitVector in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>public boolean isUnitVector(double tolerance)
VectorSpaceisUnitVector in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>tolerance - The tolerance around 1.0 to allow the length.public double dot(InfiniteVector<KeyType> other)
VectorSpacedot in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>other - The Vector with which to compute the dot product with this.
Must have the same dimensionality as this.public double dotProduct(InfiniteVector<KeyType> other)
VectorSpacedotProduct in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>other - The Vector with which to compute the dot product with this.
Must have the same dimensionality as this.public InfiniteVector<KeyType> plus(InfiniteVector<KeyType> other)
Ringthis and otherplus in interface Ring<InfiniteVector<KeyType>>other - object to add to thisthis and otherpublic void plusEquals(InfiniteVector<KeyType> other)
Ringthis and otherplusEquals in interface Ring<InfiniteVector<KeyType>>other - object to add to thispublic InfiniteVector<KeyType> minus(InfiniteVector<KeyType> other)
Ringother from thisminus in interface Ring<InfiniteVector<KeyType>>other - object to subtract from thisthis and otherpublic void minusEquals(InfiniteVector<KeyType> other)
Ringother from
thisminusEquals in interface Ring<InfiniteVector<KeyType>>other - object to subtract from thispublic InfiniteVector<KeyType> dotTimes(InfiniteVector<KeyType> other)
Ringthis and otherdotTimes in interface Ring<InfiniteVector<KeyType>>other - elements of other will be multiplied to the corresponding
elements of thisthis and
otherpublic void dotTimesEquals(InfiniteVector<KeyType> other)
Ringthis and
otherdotTimesEquals in interface Ring<InfiniteVector<KeyType>>other - elements of other will be multiplied to the corresponding
elements of thispublic InfiniteVector<KeyType> scale(double scaleFactor)
Ringthis by scaleFactorscale in interface Ring<InfiniteVector<KeyType>>scaleFactor - amount to scale the elements of thisthispublic void scaleEquals(double scaleFactor)
Ringthis by
scaleFactorscaleEquals in interface Ring<InfiniteVector<KeyType>>scaleFactor - amount to scale the elements of thispublic InfiniteVector<KeyType> scaledPlus(double scaleFactor, InfiniteVector<KeyType> other)
Ringthis and other after
element-wise scaling of other by scaleFactor.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x + a * y. It is typically a more efficient way of doing
this.plus(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledPlus in interface Ring<InfiniteVector<KeyType>>scaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public void scaledPlusEquals(double scaleFactor,
InfiniteVector<KeyType> other)
Ringthis and other after
element-wise scaling of other by scaleFactor.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x += a * y. It is typically a more efficient way of doing
this.plusEquals(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledPlusEquals in interface Ring<InfiniteVector<KeyType>>scaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public InfiniteVector<KeyType> scaledMinus(double scaleFactor, InfiniteVector<KeyType> other)
Ringother after element-wise scaling of
other by scaleFactor from this.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x - a * y. It is typically a more efficient way of doing
this.minus(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledMinus in interface Ring<InfiniteVector<KeyType>>scaleFactor - The scale factor to multiply by the elements of other before
subtracting from the elements of this.other - Object to scale and then subtract from this.public void scaledMinusEquals(double scaleFactor,
InfiniteVector<KeyType> other)
Ringother after element-wise
scaling of other by scaleFactor from this.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x -= a * y. It is typically a more efficient way of doing
this.minusEquals(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledMinusEquals in interface Ring<InfiniteVector<KeyType>>scaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public void zero()
Ringthis, so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 );zero in interface Ring<InfiniteVector<KeyType>>public boolean isZero()
RingisZero in interface Ring<InfiniteVector<KeyType>>public boolean isZero(double effectiveZero)
RingisZero in interface Ring<InfiniteVector<KeyType>>effectiveZero - Tolerance threshold for element-wise equalitypublic void compact()
AbstractMutableDoubleMapcompact in interface InfiniteVector<KeyType>compact in class AbstractMutableDoubleMap<KeyType>public void forEachEntry(InfiniteVector.KeyValueConsumer<? super KeyType> consumer)
InfiniteVectorforEachEntry in interface InfiniteVector<KeyType>consumer - The consumer for the entries. It is called for each active entry in
the vector, in order by increasing index.public void forEachNonZero(InfiniteVector.KeyValueConsumer<? super KeyType> consumer)
InfiniteVectorforEachNonZero in interface InfiniteVector<KeyType>consumer - The consumer for the non-zero entries. It is called for each
non-zero entry in the vector, in order by increasing index.public java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Iterator<InfiniteVector.Entry<KeyType>> iterator()
iterator in interface java.lang.Iterable<InfiniteVector.Entry<KeyType>>public InfiniteVector<KeyType> negative()
Ringthis, such that
this.plus( this.negative() ) has only zero elements.negative in interface Ring<InfiniteVector<KeyType>>thispublic void negativeEquals()
RingthisnegativeEquals in interface Ring<InfiniteVector<KeyType>>