common
Class ImplicitVector

java.lang.Object
  extended by common.ImplicitVector
Direct Known Subclasses:
DenseVector, SparseVector

public abstract class ImplicitVector
extends java.lang.Object

A sequence of floating-point numbers that is in principle infinite, but in which only a finite set of entries are represented explicitly. All entries that are not represented explicitly are assumed to be zero (some of the explicit entries may be zero as well).


Constructor Summary
ImplicitVector()
           
 
Method Summary
 double dotProduct(double[] arr)
          Returns the dot product of this vector with the given array of double values.
 double dotProduct(ImplicitVector other)
          Returns the dot product of this vector with the given vector.
abstract  double get(int i)
          Returns the value at the given index.
abstract  int ithExplicitIndex(int i)
          Returns the ith explicitly represented index in this vector.
abstract  double ithExplicitValue(int i)
          Returns the value at the ith explicitly represented index.
 int maxExplicitIndex()
          Returns the largest index at which a value is explicitly stored.
abstract  int numExplicit()
          Returns the number of explicitly represented entries in this vector.
 int sampleIndex()
          Returns an index sampled according to the probability distribution represented this by this vector.
abstract  void set(int i, double value)
           
 double sum()
          Returns the sum of the entries in this vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImplicitVector

public ImplicitVector()
Method Detail

get

public abstract double get(int i)
Returns the value at the given index. This is zero if no value is explicitly stored for the given index.


set

public abstract void set(int i,
                         double value)

numExplicit

public abstract int numExplicit()
Returns the number of explicitly represented entries in this vector.


maxExplicitIndex

public int maxExplicitIndex()
Returns the largest index at which a value is explicitly stored.


ithExplicitIndex

public abstract int ithExplicitIndex(int i)
Returns the ith explicitly represented index in this vector.

Throws:
java.lang.IndexOutOfBoundsException - if i is less than zero or greater than or equal to the number of explicitly represented entries in this vector

ithExplicitValue

public abstract double ithExplicitValue(int i)
Returns the value at the ith explicitly represented index.

Throws:
java.lang.IndexOutOfBoundsException - if i is less than zero or greater than or equal to the number of explicitly represented entries in this vector

sum

public double sum()
Returns the sum of the entries in this vector.


dotProduct

public double dotProduct(ImplicitVector other)
Returns the dot product of this vector with the given vector. The dot product is the sum, over those indices that are explicitly represented in both vectors, of the product of the values in the two vectors at that index.


dotProduct

public double dotProduct(double[] arr)
Returns the dot product of this vector with the given array of double values. This is the same as calling dotProduct with an ImplicitVector whose explicit entries are exactly those in the given array.


sampleIndex

public int sampleIndex()
Returns an index sampled according to the probability distribution represented this by this vector. Assumes the entries in this vector are non-negative and sum to 1.

Throws:
java.lang.IllegalStateException - if the sum of the probabilities is less than 1 - Util.TOLERANCE.