org.apache.mahout.math
Class VectorView

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

public class VectorView
extends AbstractVector

Implements subset view of a Vector


Nested Class Summary
 class VectorView.AllIterator
           
 class VectorView.NonZeroIterator
           
 
Nested classes/interfaces inherited from class org.apache.mahout.math.AbstractVector
AbstractVector.LocalElement
 
Nested classes/interfaces inherited from interface org.apache.mahout.math.Vector
Vector.Element
 
Field Summary
 
Fields inherited from class org.apache.mahout.math.AbstractVector
lengthSquared
 
Constructor Summary
VectorView()
          For serialization purposes only
VectorView(Vector vector, int offset, int cardinality)
           
 
Method Summary
 Vector clone()
          Return a copy of the recipient
 double getDistanceSquared(Vector v)
          Get the square of the distance between this vector and the other vector.
 double getIteratorAdvanceCost()
          Gets an estimate of the cost (in number of operations) it takes to advance an iterator through the nonzero elements of this vector.
 double getLengthSquared()
          Return the sum of squares of all elements in the vector.
 double getLookupCost()
          Gets an estimate of the cost (in number of operations) it takes to lookup a random element in this vector.
 int getNumNondefaultElements()
          Return the number of values in the recipient which are not the default value.
 double getQuick(int index)
          Return the value at the given index, without checking bounds
 boolean isAddConstantTime()
          Return true iff adding a new (nonzero) element takes constant time for this vector.
 boolean isDense()
           
 boolean isSequentialAccess()
           
 Iterator<Vector.Element> iterateNonZero()
          Iterates over all non-zero elements.
 Iterator<Vector.Element> iterator()
          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 AbstractVector.getElement(int) for the given index

 VectorView like()
          Return an empty vector of the same underlying class as the receiver
protected  Matrix matrixLike(int rows, int columns)
          Subclasses must override to return an appropriately sparse or dense result
 void mergeUpdates(OrderedIntDoubleMapping updates)
          Used internally by assign() to update multiple indices and values at once.
 void setQuick(int index, double value)
          Set the value at the given index, without checking bounds
 Vector viewPart(int offset, int length)
          Return a new vector containing the subset of the recipient
 
Methods inherited from class org.apache.mahout.math.AbstractVector
aggregate, aggregate, all, asFormatString, assign, assign, assign, assign, assign, assign, createOptimizedCopy, cross, divide, dot, dotSelf, equals, get, getElement, getNumNonZeroElements, hashCode, incrementQuick, invalidateCachedLength, logNormalize, logNormalize, logNormalize, maxValue, maxValueIndex, minus, minValue, minValueIndex, nonZeroes, norm, normalize, normalize, plus, plus, set, size, sparseVectorToString, times, times, toString, toString, zSum
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VectorView

public VectorView()
For serialization purposes only


VectorView

public VectorView(Vector vector,
                  int offset,
                  int cardinality)
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 Vector 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

isDense

public boolean isDense()
Returns:
true iff this implementation should be considered dense -- that it explicitly represents every value

isSequentialAccess

public boolean isSequentialAccess()
Returns:
true iff this implementation should be considered to be iterable in index order in an efficient way. In particular this implies that Vector.all() and Vector.nonZeroes() ()} return elements in ascending order by index.

like

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

Returns:
a Vector

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 which are not the default value. For instance, for a sparse vector, this would be the number of non-zero values.

Returns:
an int

viewPart

public Vector viewPart(int offset,
                       int length)
Description copied from interface: Vector
Return a new vector containing the subset of the recipient

Specified by:
viewPart in interface Vector
Overrides:
viewPart in class AbstractVector
Parameters:
offset - an int offset into the receiver
length - the cardinality of the desired result
Returns:
a new Vector

iterateNonZero

public Iterator<Vector.Element> iterateNonZero()
Description copied from class: AbstractVector
Iterates over all non-zero elements.

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

Specified by:
iterateNonZero in class AbstractVector
Returns:
An Iterator over all non-zero elements

iterator

public Iterator<Vector.Element> iterator()
Description copied from class: AbstractVector
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 AbstractVector.getElement(int) for the given index

Specified by:
iterator in class AbstractVector
Returns:
An Iterator over all elements

getLengthSquared

public double getLengthSquared()
Description copied from interface: Vector
Return the sum of squares of all elements in the vector. Square root of this value is the length of the vector.

Specified by:
getLengthSquared in interface Vector
Overrides:
getLengthSquared in class AbstractVector
Returns:
The sum of the squares of all elements in the vector.

getDistanceSquared

public double getDistanceSquared(Vector v)
Description copied from interface: Vector
Get the square of the distance between this vector and the other vector.

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

getLookupCost

public double getLookupCost()
Description copied from interface: Vector
Gets an estimate of the cost (in number of operations) it takes to lookup a random element in this vector.


getIteratorAdvanceCost

public double getIteratorAdvanceCost()
Description copied from interface: Vector
Gets an estimate of the cost (in number of operations) it takes to advance an iterator through the nonzero elements of this vector.


isAddConstantTime

public boolean isAddConstantTime()
Description copied from interface: Vector
Return true iff adding a new (nonzero) element takes constant time for this vector.


mergeUpdates

public void mergeUpdates(OrderedIntDoubleMapping updates)
Used internally by assign() to update multiple indices and values at once. Only really useful for sparse vectors (especially SequentialAccessSparseVector).

If someone ever adds a new type of sparse vectors, this method must merge (index, value) pairs into the vector.

Parameters:
updates - a mapping of indices to values to merge in the vector.


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.