gov.sandia.cognition.math.matrix
Class AbstractVectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.math.AbstractRing<VectorType>
          extended by gov.sandia.cognition.math.matrix.AbstractVectorSpace<VectorType,EntryType>
Type Parameters:
VectorType - Type of VectorSpace
EntryType - Type of Entry in the VectorSpace
All Implemented Interfaces:
VectorSpace<VectorType,EntryType>, Ring<VectorType>, CloneableSerializable, Serializable, Cloneable, Iterable<EntryType>
Direct Known Subclasses:
AbstractVector

public abstract class AbstractVectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
extends AbstractRing<VectorType>
implements VectorSpace<VectorType,EntryType>

Partial implementation of VectorSpace

Since:
3.3.1
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface gov.sandia.cognition.math.matrix.VectorSpace
VectorSpace.Entry
 
Constructor Summary
AbstractVectorSpace()
          Creates a new instance of AbstractVectorSpace
 
Method Summary
 double angle(VectorType other)
          Computes the angle between two Vectors.
 double cosine(VectorType other)
          Computes the cosine between two Vectors
 boolean equals(Object other)
          Determines if two RingType objects are equal
 boolean equals(VectorType other, double effectiveZero)
          Determines if two RingType objects are effectively equal
 double euclideanDistance(VectorType other)
          Euclidean distance between this and other, which is the 2-norm between the difference of the Vectors
 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(double effectiveZero)
          Determines if this ring is equal to zero using the element-wise effective zero value.
 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.
 void scaleEquals(double scaleFactor)
          Inline element-wise scaling of this by scaleFactor
 double sum()
          Computes the sum of the elements in the vector.
 VectorType unitVector()
          Returns the unit vector of this vector.
 void unitVectorEquals()
          Modifies this vector to be a the unit vector.
 
Methods inherited from class gov.sandia.cognition.math.AbstractRing
clone, dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, zero
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.math.matrix.VectorSpace
dotProduct, euclideanDistanceSquared
 
Methods inherited from interface gov.sandia.cognition.math.Ring
clone, dotTimes, dotTimesEquals, isZero, minus, minusEquals, negative, negativeEquals, plus, plusEquals, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaledPlusEquals, zero
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

AbstractVectorSpace

public AbstractVectorSpace()
Creates a new instance of AbstractVectorSpace

Method Detail

equals

public boolean equals(Object other)
Description copied from interface: Ring
Determines if two RingType objects are equal

Specified by:
equals in interface Ring<VectorType extends VectorSpace<VectorType,? extends EntryType>>
Overrides:
equals in class Object
Parameters:
other - RingType to compare against this
Returns:
True if the two objects are equal, false otherwise

sum

public double sum()
Description copied from interface: VectorSpace
Computes the sum of the elements in the vector.

Specified by:
sum in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Returns:
The sum of the elements in the vector.

norm1

public double norm1()
Description copied from interface: VectorSpace
1-norm of the vector (sum of absolute values in the vector)

Specified by:
norm1 in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Returns:
1-norm of the vector, [0,\infty)

norm2

public double norm2()
Description copied from interface: VectorSpace
2-norm of the vector (aka Euclidean distance of the vector)

Specified by:
norm2 in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Returns:
2-norm of the vector, [0,\infty)

norm2Squared

public double norm2Squared()
Description copied from interface: VectorSpace
Squared 2-norm of the vector (aka squared Euclidean distance of the vector)

Specified by:
norm2Squared in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Returns:
Squared 2-norm of the vector, [0,\infty)

normInfinity

public double normInfinity()
Description copied from interface: VectorSpace
Returns the infinity norm of the Vector, which is the maximum absolute value of an element in the Vector.

Specified by:
normInfinity in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Returns:
Maximum absolute value of any element in the Vector.

norm

public double norm(double power)
Description copied from interface: VectorSpace
Returns the p-norm of the Vector with the given power.

Specified by:
norm in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Parameters:
power - Power to exponentiate each entry, must be greater than 0.0, Double.POSITIVE_INFINITY
Returns:
p-norm with the given power.

angle

public double angle(VectorType other)
Description copied from interface: VectorSpace
Computes the angle between two Vectors.

Specified by:
angle in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Parameters:
other - Another vector with which to compute the angle. Must be the same dimensionality.
Returns:
The angle between the two vectors in [0, PI].

cosine

public double cosine(VectorType other)
Description copied from interface: VectorSpace
Computes the cosine between two Vectors

Specified by:
cosine in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Parameters:
other - another vector with which to compute the cosine, must be the same dimension as this
Returns:
cosine between the vectors, [0,1]

euclideanDistance

public double euclideanDistance(VectorType other)
Description copied from interface: VectorSpace
Euclidean distance between this and other, which is the 2-norm between the difference of the Vectors

Specified by:
euclideanDistance in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Parameters:
other - Vector to which to compute the distance, must be the same dimension as this
Returns:
this.minus( other ).norm2(), which is [0,\infty)

unitVector

public VectorType unitVector()
Description copied from interface: VectorSpace
Returns the unit vector of this vector. That is, a vector in the same "direction" where the length (norm2) is 1.0. This is computed by dividing each element buy the length (norm2). If this vector is all zeros, then the vector returned will be all zeros.

Specified by:
unitVector in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Returns:
The unit vector of this vector.

unitVectorEquals

public void unitVectorEquals()
Description copied from interface: VectorSpace
Modifies this vector to be a the unit vector. That is, a vector in the same "direction" where the length (norm2) is 1.0. This is computed by dividing each element buy the length (norm2). If this vector is all zeros, then this vector will all zeros.

Specified by:
unitVectorEquals in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>

isUnitVector

public boolean isUnitVector()
Description copied from interface: VectorSpace
Determines if this vector is a unit vector (norm2 = 1.0).

Specified by:
isUnitVector in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Returns:
True if this vector is a unit vector; otherwise, false.

isUnitVector

public boolean isUnitVector(double tolerance)
Description copied from interface: VectorSpace
Determines if this vector is a unit vector within some tolerance for the 2-norm.

Specified by:
isUnitVector in interface VectorSpace<VectorType extends VectorSpace<VectorType,? extends EntryType>,EntryType extends VectorSpace.Entry>
Parameters:
tolerance - The tolerance around 1.0 to allow the length.
Returns:
True if this is a unit vector within the given tolerance; otherwise, false.

equals

public boolean equals(VectorType other,
                      double effectiveZero)
Description copied from interface: Ring
Determines if two RingType objects are effectively equal

Specified by:
equals in interface Ring<VectorType extends VectorSpace<VectorType,? extends EntryType>>
Parameters:
other - RingType to compare against this
effectiveZero - tolerance threshold for element-wise equality
Returns:
True if the two objects are equal, false otherwise

scaleEquals

public void scaleEquals(double scaleFactor)
Description copied from interface: Ring
Inline element-wise scaling of this by scaleFactor

Specified by:
scaleEquals in interface Ring<VectorType extends VectorSpace<VectorType,? extends EntryType>>
Parameters:
scaleFactor - amount to scale the elements of this

isZero

public boolean isZero(double effectiveZero)
Description copied from interface: Ring
Determines if this ring is equal to zero using the element-wise effective zero value.

Specified by:
isZero in interface Ring<VectorType extends VectorSpace<VectorType,? extends EntryType>>
Parameters:
effectiveZero - Tolerance threshold for element-wise equality
Returns:
True if all of the elements of this ring are effectively zero.