org.apache.mahout.math
Class RandomAccessSparseVector

java.lang.Object
  extended by org.apache.mahout.math.AbstractVector
      extended by org.apache.mahout.math.RandomAccessSparseVector
All Implemented Interfaces:
java.lang.Cloneable, Vector

public class RandomAccessSparseVector
extends AbstractVector

Implements vector that only stores non-zero doubles


Nested Class Summary
 class RandomAccessSparseVector.Element
           
 
Field Summary
protected  OpenIntDoubleHashMap values
           
 
Fields inherited from class org.apache.mahout.math.AbstractVector
lengthSquared, size
 
Constructor Summary
RandomAccessSparseVector()
          For serialization purposes only.
RandomAccessSparseVector(int cardinality)
           
RandomAccessSparseVector(int cardinality, int size)
           
RandomAccessSparseVector(RandomAccessSparseVector other, boolean shallowCopy)
           
RandomAccessSparseVector(java.lang.String name, int cardinality)
           
RandomAccessSparseVector(java.lang.String name, int cardinality, int size)
           
RandomAccessSparseVector(Vector other)
           
 
Method Summary
 void addTo(Vector v)
          Add the elements to the other vector and results are stored in that vector.
 Vector assign(Vector other)
          Assign the other matrix values to the receiver
 RandomAccessSparseVector clone()
          Return a copy of the recipient
 double dot(Vector x)
          Return the dot product of the recipient and the argument
 boolean equals(java.lang.Object o)
          Indicate whether the two objects are the same or not.
 Vector.Element getElement(int index)
          Return an object of Vector.Element representing an element of this Vector.
 int getNumNondefaultElements()
          Return the number of values in the recipient
 double getQuick(int index)
          Return the value at the given index, without checking bounds
 java.util.Iterator<Vector.Element> iterateAll()
          Iterates over all elements

* NOTE: Implementations may choose to reuse the Element returned for performance reasons, so if you need a copy of it, you should call Vector.getElement(int) for the given index

 java.util.Iterator<Vector.Element> iterateNonZero()
          NOTE: this implementation reuses the Vector.Element instance for each call of next().
 RandomAccessSparseVector like()
          Return an empty matrix of the same underlying class as the receiver
 Vector like(int newCardinality)
          Return an empty matrix of the same underlying class as the receiver and of the given cardinality
protected  Matrix matrixLike(int rows, int columns)
          Subclasses must override to return an appropriately sparse or dense result
 void setQuick(int index, double value)
          Set the value at the given index, without checking bounds
 
Methods inherited from class org.apache.mahout.math.AbstractVector
aggregate, aggregate, asFormatString, assign, assign, assign, assign, assign, cross, decodeVector, divide, dotSelf, equivalent, get, get, getDistanceSquared, getLabelBindings, getLengthSquared, getName, hashCode, maxValue, maxValueIndex, minus, norm, normalize, normalize, plus, plus, set, set, set, setLabelBindings, setName, size, strictEquivalence, times, times, viewPart, zSum
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

values

protected OpenIntDoubleHashMap values
Constructor Detail

RandomAccessSparseVector

public RandomAccessSparseVector()
For serialization purposes only.


RandomAccessSparseVector

public RandomAccessSparseVector(int cardinality)

RandomAccessSparseVector

public RandomAccessSparseVector(int cardinality,
                                int size)

RandomAccessSparseVector

public RandomAccessSparseVector(java.lang.String name,
                                int cardinality)

RandomAccessSparseVector

public RandomAccessSparseVector(java.lang.String name,
                                int cardinality,
                                int size)

RandomAccessSparseVector

public RandomAccessSparseVector(Vector other)

RandomAccessSparseVector

public RandomAccessSparseVector(RandomAccessSparseVector other,
                                boolean shallowCopy)
Method Detail

matrixLike

protected Matrix matrixLike(int rows,
                            int columns)
Description copied from class: AbstractVector
Subclasses must override to return an appropriately sparse or dense result

Specified by:
matrixLike in class AbstractVector
Parameters:
rows - the row cardinality
columns - the column cardinality
Returns:
a Matrix

clone

public RandomAccessSparseVector clone()
Description copied from interface: Vector
Return a copy of the recipient

Specified by:
clone in interface Vector
Overrides:
clone in class AbstractVector
Returns:
a new Vector

assign

public Vector assign(Vector other)
Description copied from interface: Vector
Assign the other matrix values to the receiver

Specified by:
assign in interface Vector
Overrides:
assign in class AbstractVector
Parameters:
other - a Vector
Returns:
the modified receiver

getQuick

public double getQuick(int index)
Description copied from interface: Vector
Return the value at the given index, without checking bounds

Parameters:
index - an int index
Returns:
the double at the index

setQuick

public void setQuick(int index,
                     double value)
Description copied from interface: Vector
Set the value at the given index, without checking bounds

Parameters:
index - an int index into the receiver
value - a double value to set

getNumNondefaultElements

public int getNumNondefaultElements()
Description copied from interface: Vector
Return the number of values in the recipient

Returns:
an int

like

public RandomAccessSparseVector like()
Description copied from interface: Vector
Return an empty matrix of the same underlying class as the receiver

Returns:
a Vector

like

public Vector like(int newCardinality)
Description copied from interface: Vector
Return an empty matrix of the same underlying class as the receiver and of the given cardinality

Parameters:
newCardinality - an int specifying the desired cardinality
Returns:
a Vector

iterateNonZero

public java.util.Iterator<Vector.Element> iterateNonZero()
NOTE: this implementation reuses the Vector.Element instance for each call of next(). If you need to preserve the instance, you need to make a copy of it

Returns:
an NonZeroIterator over the Elements.
See Also:
getElement(int)

iterateAll

public java.util.Iterator<Vector.Element> iterateAll()
Description copied from interface: Vector
Iterates over all elements

* NOTE: Implementations may choose to reuse the Element returned for performance reasons, so if you need a copy of it, you should call Vector.getElement(int) for the given index

Returns:
An Iterator over all elements

equals

public boolean equals(java.lang.Object o)
Indicate whether the two objects are the same or not. Two Vectors can be equal even if the underlying implementation is not equal.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare
Returns:
true if the objects have the same cell values and same name, false otherwise.

* @see AbstractVector#strictEquivalence(Vector, Vector)

See Also:
AbstractVector.equivalent(Vector, Vector)

getElement

public Vector.Element getElement(int index)
Description copied from interface: Vector
Return an object of Vector.Element representing an element of this Vector. Useful when designing new iterator types.

Parameters:
index - Index of the Vector.Element required
Returns:
The Vector.Element Object

addTo

public void addTo(Vector v)
Description copied from interface: Vector
Add the elements to the other vector and results are stored in that vector.

Specified by:
addTo in interface Vector
Overrides:
addTo in class AbstractVector

dot

public double dot(Vector x)
Description copied from interface: Vector
Return the dot product of the recipient and the argument

Specified by:
dot in interface Vector
Overrides:
dot in class AbstractVector
Parameters:
x - a Vector
Returns:
a new Vector


Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.