SSJ
V. 2.6.

umontreal.iro.lecuyer.stat.list
Class ListOfTalliesWithCovariance<E extends Tally>

java.lang.Object
  extended by umontreal.iro.lecuyer.stat.list.ListOfStatProbes<E>
      extended by umontreal.iro.lecuyer.stat.list.ListOfTallies<E>
          extended by umontreal.iro.lecuyer.stat.list.ListOfTalliesWithCovariance<E>
All Implemented Interfaces:
Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

public class ListOfTalliesWithCovariance<E extends Tally>
extends ListOfTallies<E>

Extends ListOfTallies to add support for the computation of the sample covariance between each pair of elements in a list, without storing all observations. This list of tallies contains internal structures to keep track of bar(X)n, i for i = 0,…, d - 1, and k=0n-1(Xi, k - bar(X)k, i)(Xj, k - bar(X)k, j)/n, for i = 0,…, d - 2 and j = 1,…, d - 1, with j > i. Here, bar(X)n, i is the ith component of bar(X)n, the average vector, and bar(X)0, i = 0 for i = 0,…, d - 1. The value Xi, k corresponds to the ith component of the kth observation Xk. These sums are updated every time a vector is added to this list, and are used to estimate the covariances.

Note: the size of the list of tallies must remain fixed because of the data structures used for computing sample covariances. As a result, the first call to init makes this list unmodifiable.

Note: for the sample covariance to be computed between a pair of tallies, the number of observations in each tally should be the same. It is therefore recommended to always add complete vectors of observations to this list. Moreover, one must use the add method in this class to add vectors of observations for the sums used for covariance estimation to be updated correctly. Failure to use this method, e.g., adding observations to each individual tally in the list, will result in an incorrect estimate of the covariances, unless the tallies in the list can store observations. For example, the following code, which adds the vector v in the list of tallies list, works correctly only if the list contains instances of TallyStore:

for (int i = 0; i < v.length; i++)
      list.get (i).add (v[i]);
But the following code is always correct:
list.add (v);


Constructor Summary
ListOfTalliesWithCovariance()
          Creates an empty list of tallies with covariance support.
ListOfTalliesWithCovariance(String name)
          Creates an empty list of tallies with covariance support and name name.
 
Method Summary
 void add(double[] x)
          Adds a new vector of observations x to this list of tallies, and updates the internal data structures computing averages, and sums of products.
 void add(cern.colt.matrix.DoubleMatrix1D x)
           
 ListOfTalliesWithCovariance<E> clone()
          Clones this object.
 double covariance(int i, int j)
          Returns the empirical covariance of the observations in tallies with indices i and j.
static ListOfTalliesWithCovariance<Tally> createWithTally(int size)
          This factory method constructs and returns a list of tallies with size instances of Tally.
static ListOfTalliesWithCovariance<TallyStore> createWithTallyStore(int size)
          This factory method constructs and returns a list of tallies with size instances of TallyStore.
 void init()
          Initializes this list of statistical probes by calling init on each element.
 
Methods inherited from class umontreal.iro.lecuyer.stat.list.ListOfTallies
areAllNumberObsEqual, average, correlation, correlation, covariance, numberObs, standardDeviation, variance
 
Methods inherited from class umontreal.iro.lecuyer.stat.list.ListOfStatProbes
add, add, addAll, addAll, addArrayOfObservationListener, clear, clearArrayOfObservationListeners, contains, containsAll, equals, get, getName, hashCode, indexOf, isBroadcasting, isCollecting, isEmpty, isModifiable, iterator, lastIndexOf, listIterator, listIterator, notifyListeners, remove, remove, removeAll, removeArrayOfObservationListener, report, retainAll, set, setBroadcasting, setCollecting, setName, setUnmodifiable, size, subList, sum, toArray, toArray
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListOfTalliesWithCovariance

public ListOfTalliesWithCovariance()
Creates an empty list of tallies with covariance support. One must fill the list with tallies, and call init before adding any observation.


ListOfTalliesWithCovariance

public ListOfTalliesWithCovariance(String name)
Creates an empty list of tallies with covariance support and name name. One must fill the list with tallies, and call init before adding any observation.

Parameters:
name - the name of the new list.
Method Detail

createWithTally

public static ListOfTalliesWithCovariance<Tally> createWithTally(int size)
This factory method constructs and returns a list of tallies with size instances of Tally.

Parameters:
size - the size of the list.
Returns:
the created list.

createWithTallyStore

public static ListOfTalliesWithCovariance<TallyStore> createWithTallyStore(int size)
This factory method constructs and returns a list of tallies with size instances of TallyStore.

Parameters:
size - the size of the list.
Returns:
the created list.

init

public void init()
Description copied from class: ListOfStatProbes
Initializes this list of statistical probes by calling init on each element.

Overrides:
init in class ListOfStatProbes<E extends Tally>

add

public void add(double[] x)
Adds a new vector of observations x to this list of tallies, and updates the internal data structures computing averages, and sums of products. One must use this method instead of adding observations to individual tallies to get a covariance estimate.

Overrides:
add in class ListOfTallies<E extends Tally>
Parameters:
x - the new vector of observations.

add

public void add(cern.colt.matrix.DoubleMatrix1D x)

covariance

public double covariance(int i,
                         int j)
Description copied from class: ListOfTallies
Returns the empirical covariance of the observations in tallies with indices i and j. If x1,…, xn represent the observations in tally i whereas y1,…, yn represent the observations in tally j, then the covariance is given by

SX, Y = 1#1∑k=1n(xk - bar(X)n)(yk - bar(Y)n) = [tex2html_wrap_indisplay273](∑k=1nxkyk - 2#2∑k=1nxkr=1nyr).

This returns Double.NaN if the tallies do not contain the same number of observations, or if they contain less than two observations. This method throws an exception if the underlying tallies are not capable of storing observations, i.e. if the tallies are not TallyStores. The ListOfTalliesWithCovariance subclass provides an alternative implementation of this method which does not require the observations to be stored.

Overrides:
covariance in class ListOfTallies<E extends Tally>
Parameters:
i - the index of the first tally.
j - the index of the second tally.
Returns:
the value of the covariance.

clone

public ListOfTalliesWithCovariance<E> clone()
Clones this object. This clones the list of tallies and the data structures holding the sums of products but not the tallies comprising the list. The created clone is modifiable, even though the original list is unmodifiable.

Overrides:
clone in class ListOfTallies<E extends Tally>

SSJ
V. 2.6.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.