org.apache.mahout.math
Class DenseVector

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

public class DenseVector
extends AbstractVector

Implements vector as an array of doubles


Nested Class Summary
 
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
DenseVector()
          For serialization purposes only
DenseVector(DenseVector values, boolean shallowCopy)
           
DenseVector(double[] values)
          Construct a new instance using provided values
DenseVector(double[] values, boolean shallowCopy)
           
DenseVector(int cardinality)
          Construct a new instance of the given cardinality
DenseVector(Vector vector)
          Copy-constructor (for use in turning a sparse vector into a dense one, for example)
 
Method Summary
 void addAll(Vector v)
           
 Vector assign(DenseVector vector)
           
 Vector assign(double value)
          Assign the value to all elements of the receiver
 DenseVector clone()
          Return a copy of the recipient
 double dot(Vector x)
          Return the dot product of the recipient and the argument
protected  double dotSelf()
           
 boolean equals(Object o)
          Determines whether this Vector represents the same logical vector as another object.
 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 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
 void incrementQuick(int index, double increment)
          Increment the value at the given index by the given value.
 boolean isAddConstantTime()
          Return true iff adding a new (nonzero) element takes constant time for this vector.
 boolean isDense()
           
 boolean isSequentialAccess()
           
 Iterator<Vector.Element> iterateNonZero()
          Returns an iterator that traverses this Vector from 0 to cardinality-1, in that order.
 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

 DenseVector 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)
          Merge a set of (index, value) pairs into the vector.
 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, createOptimizedCopy, cross, divide, get, getDistanceSquared, getElement, getLengthSquared, getNumNonZeroElements, hashCode, 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

DenseVector

public DenseVector()
For serialization purposes only


DenseVector

public DenseVector(double[] values)
Construct a new instance using provided values

Parameters:
values - - array of values

DenseVector

public DenseVector(double[] values,
                   boolean shallowCopy)

DenseVector

public DenseVector(DenseVector values,
                   boolean shallowCopy)

DenseVector

public DenseVector(int cardinality)
Construct a new instance of the given cardinality

Parameters:
cardinality - - number of values in the vector

DenseVector

public DenseVector(Vector vector)
Copy-constructor (for use in turning a sparse vector into a dense one, for example)

Parameters:
vector - The vector to copy
Method Detail

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

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 DenseVector 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

isSequentialAccess

public boolean isSequentialAccess()
Returns:
true

dotSelf

protected double dotSelf()
Overrides:
dotSelf in class AbstractVector

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 DenseVector like()
Description copied from interface: Vector
Return an empty vector of the same underlying class as the receiver

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

incrementQuick

public void incrementQuick(int index,
                           double increment)
Description copied from interface: Vector
Increment the value at the given index by the given value.

Specified by:
incrementQuick in interface Vector
Overrides:
incrementQuick in class AbstractVector
Parameters:
index - an int index into the receiver
increment - sets the value at the given index to value + increment;

assign

public Vector assign(double value)
Description copied from interface: Vector
Assign the value to all elements of the receiver

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

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

assign

public Vector assign(DenseVector vector)

mergeUpdates

public void mergeUpdates(OrderedIntDoubleMapping updates)
Description copied from interface: Vector
Merge a set of (index, value) pairs into the vector.

Parameters:
updates - an ordered mapping of indices to values to be merged in.

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

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.


iterateNonZero

public Iterator<Vector.Element> iterateNonZero()
Returns an iterator that traverses this Vector from 0 to cardinality-1, in that order.

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

equals

public boolean equals(Object o)
Description copied from class: AbstractVector
Determines whether this Vector represents the same logical vector as another object. Two Vectors are equal (regardless of implementation) if the value at each index is the same, and the cardinalities are the same.

Overrides:
equals in class AbstractVector

addAll

public void addAll(Vector v)


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