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:
java.lang.Cloneable, Vector

public class VectorView
extends AbstractVector

Implements subset view of a Vector


Nested Class Summary
 class VectorView.AllIterator
           
 class VectorView.Element
           
 class VectorView.NonZeroIterator
           
 
Field Summary
 
Fields inherited from class org.apache.mahout.math.AbstractVector
lengthSquared, size
 
Constructor Summary
VectorView()
          For serialization purposes only
VectorView(Vector vector, int offset, int cardinality)
           
 
Method Summary
 void addTo(Vector v)
          Add the elements to the other vector and results are stored in that vector.
 Vector 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)
           
 double getDistanceSquared(Vector v)
          Get the square of the distance between this vector and the other vector.
 Vector.Element getElement(int index)
          Return an object of Vector.Element representing an element of this Vector.
 double getLengthSquared()
          Return the sum of squares of all elements in the 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
 int hashCode()
           
 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.
 Vector like()
          Return an empty matrix of the same underlying class as the receiver
 Vector like(int cardinality)
          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
 int size()
          Return the cardinality of the recipient (the maximum number of values)
 Vector viewPart(int offset, int length)
          Return a new matrix containing the subset of the recipient
 
Methods inherited from class org.apache.mahout.math.AbstractVector
aggregate, aggregate, asFormatString, assign, assign, assign, assign, assign, assign, cross, decodeVector, divide, dotSelf, equivalent, get, get, getLabelBindings, getName, maxValue, maxValueIndex, minus, norm, normalize, normalize, plus, plus, set, set, set, setLabelBindings, setName, strictEquivalence, times, times, zSum
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, 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

size

public int size()
Description copied from interface: Vector
Return the cardinality of the recipient (the maximum number of values)

Specified by:
size in interface Vector
Overrides:
size in class AbstractVector
Returns:
an int

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

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

like

public Vector 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 cardinality)
Description copied from interface: Vector
Return an empty matrix of the same underlying class as the receiver and of the given cardinality

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

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

viewPart

public Vector viewPart(int offset,
                       int length)
Description copied from interface: Vector
Return a new matrix 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 java.util.Iterator<Vector.Element> iterateNonZero()
Description copied from interface: Vector
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 Vector.getElement(int) for the given index

Returns:
An Iterator over all non-zero elements

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

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

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

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractVector

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

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

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


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