SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
MatrixOfFunctionOfMultipleMeansTallies.java
1/*
2 * Class: MatrixOfFunctionOfMultipleMeansTallies
3 * Description: Statistical collectors for functions of multiple means.
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author Éric Buist
9 * @since 2006
10
11 * SSJ is free software: you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License (GPL) as published by the
13 * Free Software Foundation, either version 3 of the License, or
14 * any later version.
15
16 * SSJ is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20
21 * A copy of the GNU General Public License is available at
22 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
23 */
24package umontreal.ssj.stat.matrix;
25
26import umontreal.ssj.stat.FunctionOfMultipleMeansTally;
27import umontreal.ssj.util.MultivariateFunction;
28import cern.colt.matrix.DoubleMatrix2D;
29import cern.colt.matrix.DoubleMatrix3D;
30import umontreal.ssj.stat.Tally;
31import umontreal.ssj.stat.list.ListOfFunctionOfMultipleMeansTallies;
32import umontreal.ssj.stat.list.ListOfTallies;
33import umontreal.ssj.util.PrintfFormat;
34
47 extends MatrixOfStatProbes<E> {
48 double[][][] temp;
49
59 public MatrixOfFunctionOfMultipleMeansTallies(int numRows, int numColumns) {
60 super(numRows, numColumns);
61 }
62
74 public MatrixOfFunctionOfMultipleMeansTallies(String name, int numRows, int numColumns) {
75 super(name, numRows, numColumns);
76 }
77
92 int d, int numRows, int numColumns) {
94 numRows, numColumns);
95 for (int r = 0; r < numRows; r++)
96 for (int c = 0; c < numColumns; c++)
97 matrix.set(r, c, new FunctionOfMultipleMeansTally(func, d));
98 return matrix;
99 }
100
110 public void add(double[][][] x) {
111 if (x.length != rows())
112 throw new IllegalArgumentException(
113 "The length of the given array must " + "correspond to the number of rows in the matrix");
114 if (collect)
115 for (int i = 0; i < x.length; i++) {
116 if (x[i].length != columns())
117 throw new IllegalArgumentException(
118 "The length of the array x[" + i + "] must correspond to the number of columns in the matrix");
119 for (int j = 0; j < x[i].length; j++)
120 get(i, j).add(x[i][j]);
121 }
122 }
123
137 public void add(DoubleMatrix3D x) {
138 if (x.rows() != rows())
139 throw new IllegalArgumentException("The number of rows of the given matrix must "
140 + "correspond to the number of rows in the matrix of probes");
141 if (x.columns() != columns())
142 throw new IllegalArgumentException("The number of columns of the given matrix must "
143 + "correspond to the number of columns in the matrix of probes");
144 if (collect)
145 for (int i = 0; i < rows(); i++)
146 for (int j = 0; j < x.columns(); j++)
147 get(i, j).add(x.viewSlice(i).viewRow(j).toArray());
148 }
149
170 public void addSameDimension(DoubleMatrix2D... x) {
171 final int nr = rows();
172 final int nc = columns();
173 final int d = getDimension();
174
175 if (x.length != d)
176 throw new IllegalArgumentException(
177 "The length of the given array must be " + d + " while its actual length is " + x.length);
178
179 if (x.length == 0 || nr == 0 || nc == 0)
180 return;
181
182 if (nr != x[0].rows() || nc != x[0].columns())
183 throw new IllegalArgumentException("The given matrices must have the same dimensions");
184
185 for (int i = 0; i < x.length - 1; i++)
186 if (x[i].rows() != x[i + 1].rows() || x[i].columns() != x[i + 1].columns())
187 throw new IllegalArgumentException("The given arrays must have the same length");
188
189 if ((temp == null) || (temp.length != nr) || (temp[0].length != nc) || (temp[0][0].length != d))
190 temp = new double[nr][nc][d];
191
192 for (int r = 0; r < nr; r++)
193 for (int c = 0; c < nc; c++)
194 for (int j = 0; j < d; j++)
195 temp[r][c][j] = x[j].getQuick(r, c);
196 add(temp);
197 }
198
205 public int getDimension() {
206 if (rows() == 0 || columns() == 0)
207 return 0;
208 FunctionOfMultipleMeansTally t0 = get(0, 0);
209 return t0 == null ? 0 : t0.getDimension();
210 }
211
219 public int numberObs() {
220 if (rows() == 0 || columns() == 0)
221 return 0;
222 FunctionOfMultipleMeansTally t0 = get(0, 0);
223 return t0 == null ? 0 : t0.numberObs();
224 }
225
233 public boolean areAllNumberObsEqual() {
234 final int nr = rows();
235 final int nc = columns();
236 int n = numberObs();
237 for (int r = 0; r < nr; r++)
238 for (int c = 0; c < nc; c++) {
239 FunctionOfMultipleMeansTally t = get(r, c);
240 if (t.numberObs() != n)
241 return false;
242 }
243 return true;
244 }
245
251 public void average(DoubleMatrix2D m) {
252 super.average(m);
253 for (int i = 0; i < m.rows(); i++)
254 for (int j = 0; j < m.columns(); j++)
255 if (!Double.isNaN(m.getQuick(i, j)) && get(i, j).numberObs() == 0)
256 m.setQuick(i, j, Double.NaN);
257 }
258
272 public void variance(DoubleMatrix2D m) {
273 if (m.rows() != rows())
274 throw new IllegalArgumentException(
275 "Invalid number of rows in the given matrix: required " + rows() + " but found " + m.rows());
276 if (m.columns() != columns())
277 throw new IllegalArgumentException(
278 "Invalid number of columns in the given matrix: required " + columns() + " but found " + m.columns());
279 for (int r = 0; r < rows(); r++)
280 for (int c = 0; c < columns(); c++) {
281 FunctionOfMultipleMeansTally tally = get(r, c);
282 m.setQuick(r, c, tally != null && tally.numberObs() >= 2 ? tally.variance() : Double.NaN);
283 }
284 }
285
298 public void standardDeviation(DoubleMatrix2D m) {
299 if (m.rows() != rows())
300 throw new IllegalArgumentException(
301 "Invalid number of rows in the given matrix: required " + rows() + " but found " + m.rows());
302 if (m.columns() != columns())
303 throw new IllegalArgumentException(
304 "Invalid number of columns in the given matrix: required " + columns() + " but found " + m.columns());
305 for (int r = 0; r < rows(); r++)
306 for (int c = 0; c < columns(); c++) {
307 FunctionOfMultipleMeansTally tally = get(r, c);
308 m.setQuick(r, c, tally != null && tally.numberObs() >= 2 ? tally.standardDeviation() : Double.NaN);
309 }
310 }
311
318 if (temp != null) {
319 clone.temp = new double[temp.length][temp[0].length][temp[0].length];
320 for (int i = 0; i < temp.length; i++)
321 for (int j = 0; j < temp[i].length; i++)
322 for (int k = 0; k < temp[i][j].length; k++)
323 clone.temp[i][j][k] = temp[i][j][k];
324 }
325
326 return clone;
327 }
328}
Represents a statistical collector for estimating a function of multiple means with a confidence inte...
int numberObs()
Returns the number of vectors of observations given to this probe since its last initialization.
int getDimension()
Returns the dimension of this tally, i.e., the size of any vector of observations.
double standardDeviation()
Returns the square root of variance.
double variance()
Estimates where is the number of vectors of observations given to this collector since the last ini...
int getDimension()
Assuming that each tally in this matrix has the same dimension, returns the dimension of tally (0,...
void addSameDimension(DoubleMatrix2D... x)
For each element (r, c) of this matrix of tallies, adds the vector of observations x[0]....
void add(DoubleMatrix3D x)
Equivalent to add(x.toArray()), without copying the elements of x into a temporary 3D array.
void average(DoubleMatrix2D m)
Computes the average for each function of multiple means tally in the matrix.
MatrixOfFunctionOfMultipleMeansTallies< E > clone()
Clones this object.
MatrixOfFunctionOfMultipleMeansTallies(int numRows, int numColumns)
Constructs a new unnamed matrix of function of multiple means tallies with numRows rows,...
void add(double[][][] x)
For each function of multiple means tally with row index&#160;r and column index&#160;c, adds the vector of o...
void variance(DoubleMatrix2D m)
For each tally in the matrix, computes the sample variance, and stores it into the given matrix.
static MatrixOfFunctionOfMultipleMeansTallies< FunctionOfMultipleMeansTally > create(MultivariateFunction func, int d, int numRows, int numColumns)
This factory method constructs and returns a matrix of function of multiple means tallies with numRow...
void standardDeviation(DoubleMatrix2D m)
For each tally in the matrix, computes the standard deviation, and stores it into the matrix m.
boolean areAllNumberObsEqual()
Tests that every tally in this matrix contains the same number of observations.
int numberObs()
Assuming that each tally in this matrix contains the same number of observations, returns the number ...
MatrixOfFunctionOfMultipleMeansTallies(String name, int numRows, int numColumns)
Constructs a new empty matrix of function of multiple means tallies with name name,...
Represents a function of multiple variables.
Provides facilities to construct and manage rectangular 2D arrays of statistical probes.