umontreal.iro.lecuyer.stat.list
Class ListOfTallies<E extends Tally>
- java.lang.Object
-
- umontreal.iro.lecuyer.stat.list.ListOfStatProbes<E>
-
- umontreal.iro.lecuyer.stat.list.ListOfTallies<E>
-
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess
- Direct Known Subclasses:
- ListOfTalliesWithCovariance
public class ListOfTallies<E extends Tally> extends ListOfStatProbes<E>
-
-
Constructor Summary
Constructors Constructor and Description ListOfTallies()Constructs a new empty list of tallies.ListOfTallies(java.lang.String name)Constructs a new empty list of tallies with name name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(double[] x)Adds the observation x[i] in tally i of this list, for i = 0, ..., size() - 1.booleanareAllNumberObsEqual()Tests that every tally in this list contains the same number of observations.voidaverage(double[] r)Computes the average for each tally in this list, and stores the averages in the array r.ListOfTallies<E>clone()Clones this object.voidcorrelation(DoubleMatrix2D c)Similar tocovariancefor computing the sample correlation matrix.doublecorrelation(int i, int j)Returns the empirical correlation between the observations in tallies with indices i and j.voidcovariance(DoubleMatrix2D c)Constructs and returns the sample covariance matrix for the tallies in this list.doublecovariance(int i, int j)Returns the empirical covariance of the observations in tallies with indices i and j.static ListOfTallies<Tally>createWithTally(int size)This factory method constructs and returns a list of tallies with size instances ofTally.static ListOfTallies<TallyStore>createWithTallyStore(int size)This factory method constructs and returns a list of tallies with size instances ofTallyStore.intnumberObs()Assuming that each tally in this list contains the same number of observations, returns the number of observations in tally 0, or 0 if this list is empty.voidstandardDeviation(double[] std)For each tally in this list, computes the sample standard deviation, and stores the standard deviations into the array std.voidvariance(double[] v)For each tally in this list, computes the sample variance, and stores the variances into the array v.-
Methods inherited from class umontreal.iro.lecuyer.stat.list.ListOfStatProbes
add, add, addAll, addAll, addArrayOfObservationListener, clear, clearArrayOfObservationListeners, contains, containsAll, equals, get, getName, hashCode, indexOf, init, 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
-
-
-
-
Constructor Detail
-
ListOfTallies
public ListOfTallies()
Constructs a new empty list of tallies.
-
ListOfTallies
public ListOfTallies(java.lang.String name)
Constructs a new empty list of tallies with name name.- Parameters:
name- the name of the new list.
-
-
Method Detail
-
createWithTally
public static ListOfTallies<Tally> createWithTally(int size)
This factory method constructs and returns a list of tallies with size instances ofTally.- Parameters:
size- the size of the list.- Returns:
- the created list.
-
createWithTallyStore
public static ListOfTallies<TallyStore> createWithTallyStore(int size)
This factory method constructs and returns a list of tallies with size instances ofTallyStore.- Parameters:
size- the size of the list.- Returns:
- the created list.
-
add
public void add(double[] x)
Adds the observation x[i] in tally i of this list, for i = 0, ..., size() - 1. No observation is added if the value is Double.NaN, or if collecting is turned OFF. If broadcasting is ON, the given array is notified to all registered observers. The given array x not being stored by this object, it can be freely used and modified after the call to this method.- Parameters:
x- the array of observations.- Throws:
java.lang.NullPointerException- if x is null.java.lang.IllegalArgumentException- if the length of x does not correspond to size().
-
numberObs
public int numberObs()
Assuming that each tally in this list contains the same number of observations, returns the number of observations in tally 0, or 0 if this list is empty.- Returns:
- the number of observations.
-
areAllNumberObsEqual
public boolean areAllNumberObsEqual()
Tests that every tally in this list contains the same number of observations. This returns true if and only if all tallies have the same number of observations, or if this list is empty. If observations are always added using theaddmethod from this class, and notaddfromTally, this method always returns true.- Returns:
- the success indicator of the test.
-
average
public void average(double[] r)
Computes the average for each tally in this list, and stores the averages in the array r. If the tally i has no observation, the Double.NaN value is stored in the array, at index i.- Overrides:
averagein classListOfStatProbes<E extends Tally>- Parameters:
r- the array to be filled with averages.
-
variance
public void variance(double[] v)
For each tally in this list, computes the sample variance, and stores the variances into the array v. If, for some tally i, there are not enough observations for estimating the variance, Double.NaN is stored in the array.- Parameters:
v- the array to be filled with sample variances.- Throws:
java.lang.NullPointerException- if v is null.java.lang.IllegalArgumentException- if v.length does not correspond tosize.
-
standardDeviation
public void standardDeviation(double[] std)
For each tally in this list, computes the sample standard deviation, and stores the standard deviations into the array std. This is equivalent to callingvarianceand performing a square root on every element of the filled array.- Parameters:
std- the array to be filled with standard deviations.- Throws:
java.lang.NullPointerException- if std is null.java.lang.IllegalArgumentException- if std.length does not correspond to size().
-
covariance
public double covariance(int i, int j)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 bySX, Y =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
∑k=1n(xk - bar(X)n)(yk - bar(Y)n) = [tex2html_wrap_indisplay275](∑k=1nxkyk -
∑k=1nxk∑r=1nyr).
ListOfTalliesWithCovariancesubclass provides an alternative implementation of this method which does not require the observations to be stored.- Parameters:
i- the index of the first tally.j- the index of the second tally.- Returns:
- the value of the covariance.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- if one or both indices are out of bounds.
-
correlation
public double correlation(int i, int j)Returns the empirical correlation between the observations in tallies with indices i and j. If the tally i contains a sample of the random variate X and the tally j contains a sample of Y, this corresponds toCor(X, Y) = Cov(X, Y)/((X)(Y))1/2.This method uses
covarianceto obtain an estimate of the covariance, andvariancein classTallyto obtain the sample variances.- Parameters:
i- the index of the first tally.j- the index of the second tally.- Returns:
- the value of the correlation.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- if one or both indices are out of bounds.
-
covariance
public void covariance(DoubleMatrix2D c)
Constructs and returns the sample covariance matrix for the tallies in this list. The given d×d matrix c, where d = size(), is filled with the computed sample covariances. Element c.get (i, j) corresponds to the result of covariance (i, j).- Parameters:
c- the matrix to be filled with the sample covariances.- Throws:
java.lang.NullPointerException- if c is null.java.lang.IllegalArgumentException- if the number of rows or columns in c does not correspond to size().
-
correlation
public void correlation(DoubleMatrix2D c)
Similar tocovariancefor computing the sample correlation matrix.- Parameters:
c- the matrix to be filled with the correlations.- Throws:
java.lang.NullPointerException- if c is null.java.lang.IllegalArgumentException- if the number of rows or columns in c does not correspond tosize.
-
clone
public ListOfTallies<E> clone()
Clones this object. This makes a shallow copy of this list, i.e., this does not clone all the tallies in the list. The created clone is modifiable, even if the original list is unmodifiable.- Overrides:
clonein classListOfStatProbes<E extends Tally>
-
-
DMelt 3.0 © DataMelt by jWork.ORG