SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
ListOfFunctionOfMultipleMeansTallies.java
1/*
2 * Class: ListOfFunctionOfMultipleMeansTallies
3 * Description: List of statistical collectors for a vector of functions
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 2007
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.list;
25
26import umontreal.ssj.stat.FunctionOfMultipleMeansTally;
27import umontreal.ssj.util.MultivariateFunction;
28import cern.colt.matrix.DoubleMatrix1D;
29import cern.colt.matrix.DoubleMatrix2D;
30
43 double[][] temp = null;
44
49 super();
50 }
51
58 super(name);
59 }
60
79
93 public void add(double[][] x) {
94 if (x.length != size())
95 throw new IllegalArgumentException("Invalid number of vectors of observations: the given length is " + x.length
96 + ", but the required length is " + size());
97 if (collect)
98 for (int i = 0; i < size(); i++) {
100 if (ta != null)
101 ta.add(x[i]);
102 }
103 }
104
117 public void add(DoubleMatrix2D x) {
118 if (x.rows() != size())
119 throw new IllegalArgumentException("Invalid number of vectors of observations: the given number is " + x.rows()
120 + ", but the required number is " + size());
121 if (collect)
122 for (int i = 0; i < size(); i++) {
124 if (ta != null)
125 ta.add(x.viewRow(i).toArray());
126 }
127 }
128
146 public void addSameDimension(double[]... x) {
147 final int l = size();
148 final int d = getDimension();
149 if (x.length != d)
150 throw new IllegalArgumentException(
151 "The length of the given array must be " + d + " while its actual length is " + x.length);
152
153 if (x.length == 0 || l == 0)
154 return;
155
156 if (l != x[0].length)
157 throw new IllegalArgumentException("The given arrays must have the same length");
158
159 for (int i = 0; i < x.length - 1; i++)
160 if (x[i].length != x[i + 1].length)
161 throw new IllegalArgumentException("The given arrays must have the same length");
162
163 if ((temp == null) || (temp.length != l) || (temp[0].length != d))
164 temp = new double[l][d];
165
166 for (int i = 0; i < l; i++)
167 for (int j = 0; j < d; j++)
168 temp[i][j] = x[j][i];
169 add(temp);
170 }
171
177 public void addSameDimension(DoubleMatrix1D... x) {
178 final int l = size();
179 final int d = getDimension();
180 if (x.length != d)
181 throw new IllegalArgumentException(
182 "The length of the given array must be " + d + " while its actual length is " + x.length);
183
184 if (x.length == 0 || l == 0)
185 return;
186
187 if (l != x[0].size())
188 throw new IllegalArgumentException("The given arrays must have the same length");
189
190 for (int i = 0; i < x.length - 1; i++)
191 if (x[i].size() != x[i + 1].size())
192 throw new IllegalArgumentException("The given arrays must have the same length");
193
194 if ((temp == null) || (temp.length != l) || (temp[0].length != d))
195 temp = new double[l][d];
196
197 for (int i = 0; i < l; i++)
198 for (int j = 0; j < d; j++)
199 temp[i][j] = x[j].get(i);
200 add(temp);
201 }
202
209 public int getDimension() {
210 if (size() == 0)
211 return 0;
213 return t0 == null ? 0 : t0.getDimension();
214 }
215
223 public int numberObs() {
224 if (size() == 0)
225 return 0;
227 return t0 == null ? 0 : t0.numberObs();
228 }
229
237 public boolean areAllNumberObsEqual() {
238 final int l = size();
239 int n = numberObs();
240 for (int i = 1; i < l; i++) {
242 if (t.numberObs() != n)
243 return false;
244 }
245 return true;
246 }
247
253 public void average(double[] a) {
254 super.average(a);
255 for (int i = 0; i < a.length; i++)
256 if (!Double.isNaN(a[i]) && get(i).numberObs() == 0)
257 a[i] = Double.NaN;
258 }
259
271 public void variance(double[] v) {
272 if (v.length != size())
273 throw new IllegalArgumentException("Incompatible array length: the given length is " + v.length
274 + " while the required length is " + size());
275 for (int i = 0; i < v.length; i++) {
276 FunctionOfMultipleMeansTally tally = get(i);
277 if (tally == null || tally.numberObs() < 2)
278 v[i] = Double.NaN;
279 else
280 v[i] = tally.variance();
281 }
282 }
283
294 public void standardDeviation(double[] v) {
295 if (v.length != size())
296 throw new IllegalArgumentException("Incompatible array length: the given length is " + v.length
297 + " while the required length is " + size());
298 for (int i = 0; i < v.length; i++) {
299 FunctionOfMultipleMeansTally tally = get(i);
300 if (tally == null || tally.numberObs() < 2)
301 v[i] = Double.NaN;
302 else
303 v[i] = tally.standardDeviation();
304 }
305 }
306
314 if (temp != null) {
315 clone.temp = new double[temp.length][temp[0].length];
316 for (int i = 0; i < temp.length; i++)
317 for (int j = 0; j < temp[i].length; i++)
318 clone.temp[i][j] = temp[i][j];
319 }
320
321 return clone;
322 }
323}
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...
void add(double[][] x)
For each tally i in this list, adds the vector x[i].
void addSameDimension(double[]... x)
For each element i of this list of tallies, adds the vector of observations x[0][i],...
static ListOfFunctionOfMultipleMeansTallies< FunctionOfMultipleMeansTally > create(MultivariateFunction func, int d, int size)
This factory method constructs and returns a list of tallies with size instances of .
ListOfFunctionOfMultipleMeansTallies(String name)
Constructs a new empty list of tallies with name name.
int getDimension()
Assuming that each tally in this list has the same dimension, returns the dimension of tally&#160;0,...
void standardDeviation(double[] v)
For each tally in this list, computes the standard deviation, and stores it into v.
boolean areAllNumberObsEqual()
Tests that every tally in this list contains the same number of observations.
void variance(double[] v)
For each tally in this list, computes the sample variance and stores it into v.
void average(double[] a)
Computes the function of averages for each tally in this list.
void addSameDimension(DoubleMatrix1D... x)
Equivalent to addSameDimension(double[][]) x.toArray(), without copying the elements of x into a temp...
void add(DoubleMatrix2D x)
Equivalent to add(x.toArray()), without copying the elements of x into a temporary 2D array.
int numberObs()
Assuming that each tally in this list contains the same number of observations, returns the number of...
ListOfFunctionOfMultipleMeansTallies< E > clone()
Clones this object.
Represents a function of multiple variables.
Provides support for lists of statistical probes.