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, set
clear, containsKey, decrement, decrement, decrementAll, decrementAll, getMaxValue, getMaxValueKey, getMaxValueKeys, getMinValue, getMinValueKey, getMinValueKeys, increment, incrementAll, incrementAll, isEmpty, keySet, setAll, setAll, size
finalize, getClass, notify, notifyAll, wait, wait, wait
getMaxValue, getMinValue
asMap, decrement, decrement, decrementAll, decrementAll, entrySet, get, getMaxValue, getMinValue, increment, increment, incrementAll, incrementAll, set, setAll, setAll
clear, containsKey, getMaxValueKey, getMaxValueKeys, getMinValueKey, getMinValueKeys, isEmpty, keySet, size
public 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()
AbstractCloneableSerializable
Object
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 CloneableSerializable
clone
in class AbstractMutableDoubleMap<KeyType>
public boolean equals(java.lang.Object other)
Ring
equals
in interface Ring<InfiniteVector<KeyType>>
equals
in class java.lang.Object
other
- RingType to compare against this
public boolean equals(InfiniteVector<KeyType> other, double effectiveZero)
Ring
equals
in interface Ring<InfiniteVector<KeyType>>
other
- RingType to compare against this
effectiveZero
- tolerance threshold for element-wise equalitypublic int hashCode()
hashCode
in class java.lang.Object
public double sum()
VectorSpace
sum
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
public double norm1()
VectorSpace
norm1
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
public double norm2()
VectorSpace
norm2
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
public double norm2Squared()
VectorSpace
norm2Squared
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
public double normInfinity()
VectorSpace
normInfinity
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
public double norm(double power)
VectorSpace
norm
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)
VectorSpace
cosine
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)
VectorSpace
angle
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)
VectorSpace
this
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)
VectorSpace
this
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()
VectorSpace
unitVector
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
public void unitVectorEquals()
VectorSpace
unitVectorEquals
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
public boolean isUnitVector()
VectorSpace
isUnitVector
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
public boolean isUnitVector(double tolerance)
VectorSpace
isUnitVector
in interface VectorSpace<InfiniteVector<KeyType>,InfiniteVector.Entry<KeyType>>
tolerance
- The tolerance around 1.0 to allow the length.public double dot(InfiniteVector<KeyType> other)
VectorSpace
dot
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)
VectorSpace
dotProduct
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)
Ring
this
and other
plus
in interface Ring<InfiniteVector<KeyType>>
other
- object to add to this
this
and other
public void plusEquals(InfiniteVector<KeyType> other)
Ring
this
and other
plusEquals
in interface Ring<InfiniteVector<KeyType>>
other
- object to add to this
public InfiniteVector<KeyType> minus(InfiniteVector<KeyType> other)
Ring
other
from this
minus
in interface Ring<InfiniteVector<KeyType>>
other
- object to subtract from this
this
and other
public void minusEquals(InfiniteVector<KeyType> other)
Ring
other
from
this
minusEquals
in interface Ring<InfiniteVector<KeyType>>
other
- object to subtract from this
public InfiniteVector<KeyType> dotTimes(InfiniteVector<KeyType> other)
Ring
this
and other
dotTimes
in interface Ring<InfiniteVector<KeyType>>
other
- elements of other will be multiplied to the corresponding
elements of this
this
and
other
public void dotTimesEquals(InfiniteVector<KeyType> other)
Ring
this
and
other
dotTimesEquals
in interface Ring<InfiniteVector<KeyType>>
other
- elements of other will be multiplied to the corresponding
elements of this
public InfiniteVector<KeyType> scale(double scaleFactor)
Ring
this
by scaleFactor
scale
in interface Ring<InfiniteVector<KeyType>>
scaleFactor
- amount to scale the elements of this
this
public void scaleEquals(double scaleFactor)
Ring
this
by
scaleFactor
scaleEquals
in interface Ring<InfiniteVector<KeyType>>
scaleFactor
- amount to scale the elements of this
public InfiniteVector<KeyType> scaledPlus(double scaleFactor, InfiniteVector<KeyType> other)
Ring
this
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)
Ring
this
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)
Ring
other
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)
Ring
other
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()
Ring
this
, 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()
Ring
isZero
in interface Ring<InfiniteVector<KeyType>>
public boolean isZero(double effectiveZero)
Ring
isZero
in interface Ring<InfiniteVector<KeyType>>
effectiveZero
- Tolerance threshold for element-wise equalitypublic void compact()
AbstractMutableDoubleMap
compact
in interface InfiniteVector<KeyType>
compact
in class AbstractMutableDoubleMap<KeyType>
public void forEachEntry(InfiniteVector.KeyValueConsumer<? super KeyType> consumer)
InfiniteVector
forEachEntry
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)
InfiniteVector
forEachNonZero
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.Object
public java.util.Iterator<InfiniteVector.Entry<KeyType>> iterator()
iterator
in interface java.lang.Iterable<InfiniteVector.Entry<KeyType>>
public InfiniteVector<KeyType> negative()
Ring
this
, such that
this.plus( this.negative() )
has only zero elements.negative
in interface Ring<InfiniteVector<KeyType>>
this
public void negativeEquals()
Ring
this
negativeEquals
in interface Ring<InfiniteVector<KeyType>>