25package umontreal.ssj.stat.list;
27import umontreal.ssj.stat.Tally;
28import umontreal.ssj.stat.TallyStore;
29import java.util.logging.Level;
30import java.util.logging.Logger;
31import cern.colt.matrix.DoubleMatrix1D;
90 private double[] tempArray;
91 private double[][] sxy;
95 private boolean isStable =
true;
98 private double[] curAverages;
101 private double[][] curSum2;
102 private Logger log = Logger.getLogger(
"umontreal.ssj.stat.list");
132 for (
int i = 0; i < size; i++)
147 for (
int i = 0; i < size; i++)
153 private void createSxy() {
156 curAverages =
new double[l];
157 curSum2 =
new double[l - 1][];
158 for (
int i = 0; i < l - 1; i++)
159 curSum2[i] =
new double[l - 1 - i];
161 sxy =
new double[l - 1][];
162 for (
int i = 0; i < l - 1; i++)
163 sxy[i] =
new double[l - 1 - i];
165 tempArray =
new double[l];
171 if (isModifiable()) {
176 for (
int i = 0; i < curAverages.length; i++)
178 for (
int i = 0; i < curSum2.length; i++)
179 for (
int j = 0; j < curSum2[i].length; j++)
182 for (
int i = 0; i < sxy.length; i++)
183 for (
int j = 0; j < sxy[i].length; j++)
195 public void add(
double[] x) {
199 structSize = (isStable) ? curSum2.length : sxy.length;
200 if (structSize != l - 1)
201 throw new IllegalArgumentException(
"The structure's size mismatches the list's size");
208 for (
int i1 = 0; i1 < l - 1; i1++)
209 for (
int i2 = i1 + 1; i2 < l; i2++)
210 curSum2[i1][i2 - i1 - 1] += (numObs - 1) * (x[i1] - curAverages[i1]) * (x[i2] - curAverages[i2])
212 for (
int i = 0; i < l; i++)
213 curAverages[i] += (x[i] - curAverages[i]) / numObs;
216 for (
int i1 = 0; i1 < l - 1; i1++)
217 for (
int i2 = i1 + 1; i2 < l; i2++)
218 sxy[i1][i2 - i1 - 1] += x[i1] * x[i2];
221 public void add(DoubleMatrix1D x) {
222 x.toArray(tempArray);
226 public double covariance(
int i,
int j) {
236 Tally tallyi =
get(i);
237 Tally tallyj =
get(j);
238 if (tallyi ==
null || tallyj ==
null)
240 int n = tallyi.numberObs();
241 if (n != tallyj.numberObs()) {
242 log.logp(Level.WARNING,
"ListOfTalliesWithCovariance",
"covariance",
243 "Tally " + i +
", with name " + tallyi.getName() +
", contains " + n +
" observations while " +
"tally "
244 + j +
", with name " + tallyj.getName() +
", contains " + tallyj.numberObs() +
"observations");
249 log.logp(Level.WARNING,
"ListOfTalliesWithCovariance",
"covariance",
250 "Tally " + i +
", with name " + tallyi.getName() +
", contains " + n +
" observation");
253 if (tallyi instanceof TallyStore && tallyj instanceof TallyStore)
254 return ((TallyStore) tallyi).covariance((TallyStore) tallyj);
256 return curSum2[i][j - i - 1] / (n - 1);
258 double sum1 = tallyi.sum();
259 double sum2 = tallyj.sum();
260 double sum12 = sxy[i][j - i - 1];
261 return (sum12 - sum1 * sum2 / n) / (n - 1);
272 ta.tempArray =
new double[size()];
273 if (curAverages !=
null)
274 ta.curAverages = curAverages.clone();
276 ta.sxy =
new double[sxy.length][];
277 for (
int i = 0; i < sxy.length; i++)
278 ta.sxy[i] = sxy[i].clone();
280 if (curSum2 !=
null) {
281 ta.curSum2 =
new double[curSum2.length][];
282 for (
int i = 0; i < curSum2.length; i++)
283 ta.curSum2[i] = curSum2[i].clone();
This class is a variant of Tally for which the individual observations are stored in a list implement...
static ListOfTalliesWithCovariance< TallyStore > createWithTallyStore(int size)
This factory method constructs and returns a list of tallies with size instances of umontreal....
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.
void add(double[] x)
Adds a new vector of observations x to this list of tallies, and updates the internal data structures...
ListOfTalliesWithCovariance< E > clone()
Clones this object.
static ListOfTalliesWithCovariance< Tally > createWithTally(int size)
This factory method constructs and returns a list of tallies with size instances of umontreal....
void variance(double[] v)
Provides support for lists of statistical probes.