gov.sandia.cognition.math.matrix
Class AbstractVector

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<Vector,VectorEntry>
              extended by gov.sandia.cognition.math.matrix.AbstractVector
All Implemented Interfaces:
Vector, Vectorizable, VectorSpace<Vector,VectorEntry>, Ring<Vector>, CloneableSerializable, Serializable, Cloneable, Iterable<VectorEntry>
Direct Known Subclasses:
AbstractMTJVector

@CodeReviews(reviews={@CodeReview(reviewer="Kevin R. Dixon",date="2008-02-27",changesNeeded=false,comments={"Minor changes to formatting and documentation for equals().","Otherwise, looks good."}),@CodeReview(reviewer="Jonathan McClain",date="2006-05-16",changesNeeded=false,comments="Added some documentation and other minor changes. Looks ok.")})
public abstract class AbstractVector
extends AbstractVectorSpace<Vector,VectorEntry>
implements Vector

Abstract implementation of some of the Vector interface, in a storage-free manner

Since:
1.0
Author:
Kevin R. Dixon, Justin Basilico
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface gov.sandia.cognition.math.matrix.VectorSpace
VectorSpace.Entry
 
Field Summary
static String DEFAULT_DELIMITER
          The default delimiter for a vector.
 
Constructor Summary
AbstractVector()
           
 
Method Summary
 void assertDimensionalityEquals(int otherDimensionality)
          Asserts that the dimensionality of this vector equals the given dimensionality.
static void assertEqualDimensionality(Vector first, Vector second)
          Throws a DimensionalityMismatchException if first.getDimensionality() != second.getDimensionality(), otherwise this function has no effect
 void assertSameDimensionality(Vector other)
          Asserts that this vector has the same dimensionality as the given vector.
 boolean checkSameDimensionality(Vector other)
          Determines if this and other have the same number of dimensions (size)
 void convertFromVector(Vector parameters)
          Assigns the values in the provided vector into this.
 Vector convertToVector()
          Returns this.
 Vector dotDivide(Vector other)
          Element-wise division of this by other.
 void dotDivideEquals(Vector other)
          Inline element-wise division of this by other.
 boolean equals(Object other)
          Determines if two RingType objects are equal
 boolean equals(Vector other, double effectiveZero)
          Determines if two RingType objects are effectively equal
 int hashCode()
           
 double[] toArray()
          Converts this vector to a new array of doubles, in the same order as they are in the vector.
 String toString()
          Converts a vector to a string that consists of each value in the vector
 String toString(NumberFormat format)
          Converts the vector to a String, using the given formatter.
 String toString(NumberFormat format, String delimiter)
          Converts the vector to a String, using the given formatter and delimiter.
 Vector transform(UnivariateScalarFunction function)
          Applies the given function to each of the elements of this vector and returns a new vector with the result.
 void transformEquals(UnivariateScalarFunction function)
          Applies the given function to each of the elements of this vector and sets them to the result.
 Vector transformNonZeros(UnivariateScalarFunction function)
          Applies the given function to each of the non-zero elements of this vector and returns a new vector with the result.
 void transformNonZerosEquals(UnivariateScalarFunction function)
          Applies the given function to each of the non-zero elements of this vector and sets them to the result.
 
Methods inherited from class gov.sandia.cognition.math.matrix.AbstractVectorSpace
angle, cosine, euclideanDistance, isUnitVector, isUnitVector, isZero, norm, norm1, norm2, norm2Squared, normInfinity, scaleEquals, sum, unitVector, unitVectorEquals
 
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, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.math.matrix.Vector
clone, getDimensionality, getElement, isSparse, outerProduct, setElement, stack, subVector, times
 
Methods inherited from interface gov.sandia.cognition.math.matrix.VectorSpace
angle, cosine, dotProduct, euclideanDistance, euclideanDistanceSquared, isUnitVector, isUnitVector, norm, norm1, norm2, norm2Squared, normInfinity, sum, unitVector, unitVectorEquals
 
Methods inherited from interface gov.sandia.cognition.math.Ring
dotTimes, dotTimesEquals, isZero, isZero, minus, minusEquals, negative, negativeEquals, plus, plusEquals, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaledPlusEquals, scaleEquals, zero
 
Methods inherited from interface java.lang.Iterable
iterator
 

Field Detail

DEFAULT_DELIMITER

public static final String DEFAULT_DELIMITER
The default delimiter for a vector.

See Also:
Constant Field Values
Constructor Detail

AbstractVector

public AbstractVector()
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<Vector>
Overrides:
equals in class AbstractVectorSpace<Vector,VectorEntry>
Parameters:
other - RingType to compare against this
Returns:
True if the two objects are equal, false otherwise

equals

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

Specified by:
equals in interface Ring<Vector>
Overrides:
equals in class AbstractVectorSpace<Vector,VectorEntry>
Parameters:
other - RingType to compare against this
effectiveZero - tolerance threshold for element-wise equality
Returns:
True if the two objects are equal, false otherwise

hashCode

public int hashCode()
Overrides:
hashCode in class Object

checkSameDimensionality

public boolean checkSameDimensionality(Vector other)
Description copied from interface: Vector
Determines if this and other have the same number of dimensions (size)

Specified by:
checkSameDimensionality in interface Vector
Parameters:
other - vector to compare to
Returns:
true iff this.getDimensionality() == other.getDimensionality(), false otherwise

assertSameDimensionality

public void assertSameDimensionality(Vector other)
Description copied from interface: Vector
Asserts that this vector has the same dimensionality as the given vector. If this assertion fails, a DimensionalityMismatchException is thrown.

Specified by:
assertSameDimensionality in interface Vector
Parameters:
other - The other vector to compare to.

assertDimensionalityEquals

public void assertDimensionalityEquals(int otherDimensionality)
Description copied from interface: Vector
Asserts that the dimensionality of this vector equals the given dimensionality. If this assertion fails, a DimensionalityMismatchException is thrown.

Specified by:
assertDimensionalityEquals in interface Vector
Parameters:
otherDimensionality - The dimensionality of the.

assertEqualDimensionality

public static void assertEqualDimensionality(Vector first,
                                             Vector second)
Throws a DimensionalityMismatchException if first.getDimensionality() != second.getDimensionality(), otherwise this function has no effect

Parameters:
first - first vector to consider
second - second vector to consider

dotDivide

public Vector dotDivide(Vector other)
Description copied from interface: Vector
Element-wise division of this by other. Note that if other has zero elements the result will contain NaN values.

Specified by:
dotDivide in interface Vector
Parameters:
other - The other ring whose elements will divide into this one.
Returns:
A new ring of equal size whose elements are equal to the corresponding element in this divided by the element in other.

dotDivideEquals

public void dotDivideEquals(Vector other)
Description copied from interface: Vector
Inline element-wise division of this by other. Note that if other has zero elements this will contain NaN values.

Specified by:
dotDivideEquals in interface Vector
Parameters:
other - The other vector whose elements will divide into this one.

transform

public Vector transform(UnivariateScalarFunction function)
Description copied from interface: Vector
Applies the given function to each of the elements of this vector and returns a new vector with the result. Note that this is a dense operation where zero elements will be passed to the function.

Specified by:
transform in interface Vector
Parameters:
function - The function from double to double to apply.
Returns:
A new vector whose elements represent the result of applying the function to corresponding element in this vector.

transformEquals

public void transformEquals(UnivariateScalarFunction function)
Description copied from interface: Vector
Applies the given function to each of the elements of this vector and sets them to the result.

Specified by:
transformEquals in interface Vector
Parameters:
function - The function from double to double to apply.

transformNonZeros

public Vector transformNonZeros(UnivariateScalarFunction function)
Description copied from interface: Vector
Applies the given function to each of the non-zero elements of this vector and returns a new vector with the result.

Specified by:
transformNonZeros in interface Vector
Parameters:
function - The function from double to double to apply to the non-zero elements.
Returns:
A new vector whose elements represent the result of applying the function to the corresponding element in this vector, except for zeros, which are exactly the same as in this vector.

transformNonZerosEquals

public void transformNonZerosEquals(UnivariateScalarFunction function)
Description copied from interface: Vector
Applies the given function to each of the non-zero elements of this vector and sets them to the result.

Specified by:
transformNonZerosEquals in interface Vector
Parameters:
function - The function from double to double to apply to the non-zero elements.

toArray

public double[] toArray()
Description copied from interface: Vector
Converts this vector to a new array of doubles, in the same order as they are in the vector. The returned will be safe in that no references are maintained by this vector.

Specified by:
toArray in interface Vector
Returns:
The vector as a dense array of doubles. Its length will be equal to the dimensionality of the vector.

toString

public String toString()
Converts a vector to a string that consists of each value in the vector

Specified by:
toString in interface Vector
Overrides:
toString in class Object
Returns:
String containing the elements of this

toString

public String toString(NumberFormat format)
Description copied from interface: Vector
Converts the vector to a String, using the given formatter.

Specified by:
toString in interface Vector
Parameters:
format - The number format to use.
Returns:
The string representation of the vector.

toString

public String toString(NumberFormat format,
                       String delimiter)
Description copied from interface: Vector
Converts the vector to a String, using the given formatter and delimiter.

Specified by:
toString in interface Vector
Parameters:
format - The number format to use.
delimiter - The delimiter to use.
Returns:
The string representation of the vector.

convertToVector

public Vector convertToVector()
Returns this.

Specified by:
convertToVector in interface Vectorizable
Returns:
This.

convertFromVector

public void convertFromVector(Vector parameters)
Assigns the values in the provided vector into this.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - The vector to convert.