|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.mahout.math.AbstractVector
org.apache.mahout.math.SequentialAccessSparseVector
public class SequentialAccessSparseVector
Implements vector that only stores non-zero doubles as a pair of parallel arrays (OrderedIntDoubleMapping),
one int[], one double[]. If there are k non-zero elements in the vector, this implementation has
O(log(k)) random-access read performance, and O(k) random-access write performance, which is far below that
of the hashmap based RandomAccessSparseVector
. This
class is primarily used for operations where the all the elements will be accessed in a read-only fashion
sequentially: methods which operate not via get() or set(), but via iterateNonZero(), such as (but not limited
to) :
Note that the Vector passed to these above methods may (and currently, are) be used in a random access fashion, so for example, calling SequentialAccessSparseVector.dot(SequentialAccessSparseVector) is slow. TODO: this need not be the case - both are ordered, so this should be very fast if implmented in this class
OrderedIntDoubleMapping
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.apache.mahout.math.Vector |
---|
Vector.Element |
Field Summary | |
---|---|
protected org.apache.mahout.math.OrderedIntDoubleMapping |
values
|
Fields inherited from class org.apache.mahout.math.AbstractVector |
---|
lengthSquared, size |
Constructor Summary | |
---|---|
SequentialAccessSparseVector()
For serialization purposes only. |
|
SequentialAccessSparseVector(int cardinality)
|
|
SequentialAccessSparseVector(int cardinality,
int size)
|
|
SequentialAccessSparseVector(SequentialAccessSparseVector other)
|
|
SequentialAccessSparseVector(SequentialAccessSparseVector other,
boolean shallowCopy)
|
|
SequentialAccessSparseVector(java.lang.String name,
int cardinality)
|
|
SequentialAccessSparseVector(java.lang.String name,
int cardinality,
int size)
|
|
SequentialAccessSparseVector(Vector other)
|
Method Summary | |
---|---|
SequentialAccessSparseVector |
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()
Iterates over all non-zero elements. |
SequentialAccessSparseVector |
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 |
---|
addTo, aggregate, aggregate, asFormatString, assign, 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 |
---|
protected org.apache.mahout.math.OrderedIntDoubleMapping values
Constructor Detail |
---|
public SequentialAccessSparseVector()
public SequentialAccessSparseVector(int cardinality, int size)
public SequentialAccessSparseVector(java.lang.String name, int cardinality, int size)
public SequentialAccessSparseVector(java.lang.String name, int cardinality)
public SequentialAccessSparseVector(int cardinality)
public SequentialAccessSparseVector(Vector other)
public SequentialAccessSparseVector(SequentialAccessSparseVector other, boolean shallowCopy)
public SequentialAccessSparseVector(SequentialAccessSparseVector other)
Method Detail |
---|
protected Matrix matrixLike(int rows, int columns)
AbstractVector
matrixLike
in class AbstractVector
rows
- the row cardinalitycolumns
- the column cardinality
public SequentialAccessSparseVector clone()
Vector
clone
in interface Vector
clone
in class AbstractVector
public double getQuick(int index)
Vector
index
- an int index
public void setQuick(int index, double value)
Vector
index
- an int index into the receivervalue
- a double value to setpublic int getNumNondefaultElements()
Vector
public SequentialAccessSparseVector like()
Vector
public Vector like(int newCardinality)
Vector
newCardinality
- an int specifying the desired cardinality
public java.util.Iterator<Vector.Element> iterateNonZero()
Vector
Vector.getElement(int)
for the given index
Iterator
over all non-zero elementspublic java.util.Iterator<Vector.Element> iterateAll()
Vector
Vector.getElement(int)
for the given index
Iterator
over all elementspublic boolean equals(java.lang.Object o)
Vector
s can be equal
even if the underlying implementation is not equal.
equals
in class java.lang.Object
o
- The object to compare
AbstractVector.equivalent(Vector, Vector)
public Vector.Element getElement(int index)
Vector
index
- Index of the Vector.Element required
public double dot(Vector x)
Vector
dot
in interface Vector
dot
in class AbstractVector
x
- a Vector
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |