SSJ
V. labo.

umontreal.iro.lecuyer.stat.matrix
Class MatrixOfTallies<E extends Tally>

java.lang.Object
  extended by umontreal.iro.lecuyer.stat.matrix.MatrixOfStatProbes<E>
      extended by umontreal.iro.lecuyer.stat.matrix.MatrixOfTallies<E>
All Implemented Interfaces:
Cloneable, Iterable<E>

public class MatrixOfTallies<E extends Tally>
extends MatrixOfStatProbes<E>

Represents a matrix of tally statistical collectors. Each element of such a matrix is an instance of Tally, and observations can be added with the add method. This class defines factory methods to fill a newly-constructed matrix with Tally or TallyStore instances.


Constructor Summary
MatrixOfTallies(int numRows, int numColumns)
          Constructs a new unnamed matrix of tallies with numRows rows, and numColumns columns, and filled with null references.
MatrixOfTallies(String name, int numRows, int numColumns)
          Constructs a new matrix of tallies with name name, numRows rows, and numColumns columns, and filled with null references.
 
Method Summary
 void add(double[][] x)
          Same as add for a 2D array.
 void add(DoubleMatrix2D x)
          Adds the observation x.get(r, c) in the tally whose row is r and column is c, for r = 0, ..., rows - 1, and c = 0, ..., columns - 1.
 boolean areAllNumberObsEqual()
          Tests that every tally in this matrix contains the same number of observations.
 void average(DoubleMatrix2D m)
          Computes the average for each tally in the matrix.
 MatrixOfTallies<E> clone()
          Clones this object.
static MatrixOfTallies<Tally> createWithTally(int numRows, int numColumns)
          This factory method constructs and returns a matrix of tallies with numRows rows, numColumns columns, and filled with new instances of Tally.
static MatrixOfTallies<TallyStore> createWithTallyStore(int numRows, int numColumns)
          This factory method constructs and returns a matrix of tallies with numRows rows, numColumns columns, and filled with new instances of TallyStore.
 int numberObs()
          Assuming that each tally in this matrix contains the same number of observations, returns the number of observations in tally (0, 0), or 0 if this matrix has 0 row or column.
 void standardDeviation(DoubleMatrix2D m)
          For each tally in the matrix, computes the standard deviation, and stores it into the given matrix.
 void variance(DoubleMatrix2D m)
          For each tally in the matrix, computes the sample variance, and stores it into the given matrix.
 
Methods inherited from class umontreal.iro.lecuyer.stat.matrix.MatrixOfStatProbes
addMatrixOfObservationListener, clearMatrixOfObservationListeners, columnReport, columns, get, getName, init, isBroadcasting, isCollecting, iterator, notifyListeners, removeMatrixOfObservationListener, rowReport, rows, set, setBroadcasting, setCollecting, setColumns, setName, setRows, sum, viewColumn, viewRow
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixOfTallies

public MatrixOfTallies(int numRows,
                       int numColumns)
Constructs a new unnamed matrix of tallies with numRows rows, and numColumns columns, and filled with null references.

Parameters:
numRows - the number of rows in the matrix.
numColumns - the number of columns in the matrix.
Throws:
NegativeArraySizeException - if numRows or numColumns are negative.

MatrixOfTallies

public MatrixOfTallies(String name,
                       int numRows,
                       int numColumns)
Constructs a new matrix of tallies with name name, numRows rows, and numColumns columns, and filled with null references.

Parameters:
name - the global name of the matrix.
numRows - the number of rows in the matrix.
numColumns - the number of columns in the matrix.
Throws:
NegativeArraySizeException - if numRows or numColumns are negative.
Method Detail

createWithTally

public static MatrixOfTallies<Tally> createWithTally(int numRows,
                                                     int numColumns)
This factory method constructs and returns a matrix of tallies with numRows rows, numColumns columns, and filled with new instances of Tally.

Parameters:
numRows - the number of rows in the matrix.
numColumns - the number of columns in the matrix.
Returns:
the created matrix.

createWithTallyStore

public static MatrixOfTallies<TallyStore> createWithTallyStore(int numRows,
                                                               int numColumns)
This factory method constructs and returns a matrix of tallies with numRows rows, numColumns columns, and filled with new instances of TallyStore.

Parameters:
numRows - the number of rows in the matrix.
numColumns - the number of columns in the matrix.
Returns:
the created matrix.

add

public void add(DoubleMatrix2D x)
Adds the observation x.get(r, c) in the tally whose row is r and column is c, for r = 0, ..., rows - 1, and c = 0, ..., columns - 1. No observation is added if the value is Double.NaN, or if observations collecting is turned OFF. If broadcasting is ON, the given matrix is notified to all registered observers. The given matrix x not being stored by this object, it can be freely used and modified after the call to this method.

Parameters:
x - the matrix of observations.
Throws:
NullPointerException - if x is null.
IllegalArgumentException - if the dimensions of x do not correspond to the dimensions of this matrix of tallies.

add

public void add(double[][] x)
Same as add for a 2D array.


numberObs

public int numberObs()
Assuming that each tally in this matrix contains the same number of observations, returns the number of observations in tally (0, 0), or 0 if this matrix has 0 row or column.

Returns:
the number of observations.

areAllNumberObsEqual

public boolean areAllNumberObsEqual()
Tests that every tally in this matrix contains the same number of observations. This returns true if and only if all tallies have the same number of observations.

Returns:
the success indicator of the test.

average

public void average(DoubleMatrix2D m)
Computes the average for each tally in the matrix. If the tally (r, c) has no observation, the Double.NaN value is stored in the given matrix, at row r, and column c.

Overrides:
average in class MatrixOfStatProbes<E extends Tally>
Parameters:
m - the matrix to be filled with averages.

variance

public void variance(DoubleMatrix2D m)
For each tally in the matrix, computes the sample variance, and stores it into the given matrix. If, for some tally (r, c), there are not enough observations for estimating the variance, Double.NaN is stored in the corresponding element of the given matrix m.

Parameters:
m - the matrix to be filled with sample variances.
Throws:
NullPointerException - if m is null.
IllegalArgumentException - if m.rows() does not correspond to rows, or m.columns() does not correspond to columns.

standardDeviation

public void standardDeviation(DoubleMatrix2D m)
For each tally in the matrix, computes the standard deviation, and stores it into the given matrix. This is equivalent to calling variance and performing a square root on every element of the filled matrix.

Parameters:
m - the matrix to be filled with standard deviations.
Throws:
NullPointerException - if m is null.
IllegalArgumentException - if m.rows() does not correspond to rows, or m.columns() does not correspond to columns.

clone

public MatrixOfTallies<E> clone()
Clones this object.

Overrides:
clone in class MatrixOfStatProbes<E extends Tally>

SSJ
V. labo.

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