List of usage examples for org.apache.commons.math.stat.descriptive.moment FourthMoment FourthMoment
public FourthMoment()
From source file:uk.ac.diamond.scisoft.analysis.dataset.Stats.java
static private Object getFourthMoment(final AbstractDataset a) { Object obj = a.getStoredValue("moment4"); if (obj == null) { final int is = a.getElementsPerItem(); final IndexIterator iter = a.getIterator(); if (is == 1) { FourthMoment moment = new FourthMoment(); while (iter.hasNext()) { moment.increment(a.getElementDoubleAbs(iter.index)); }// w w w . ja v a 2 s. co m a.setStoredValue("moment4", moment); } else { FourthMoment[] moments = new FourthMoment[is]; for (int j = 0; j < is; j++) { moments[j] = new FourthMoment(); } while (iter.hasNext()) { for (int j = 0; j < is; j++) moments[j].increment(a.getElementDoubleAbs(iter.index + j)); } a.setStoredValue("moment4", moments); } obj = a.getStoredValue("moment4"); } return obj; }
From source file:uk.ac.diamond.scisoft.analysis.dataset.Stats.java
static private void calculateHigherMoments(final AbstractDataset a, int axis) { int rank = a.getRank(); int[] oshape = a.getShape(); int alen = oshape[axis]; oshape[axis] = 1;/*from w ww . j av a 2 s. c o m*/ int[] nshape = AbstractDataset.squeezeShape(oshape, false); DoubleDataset sk = new DoubleDataset(nshape); DoubleDataset ku = new DoubleDataset(nshape); IndexIterator qiter = sk.getIterator(true); int[] qpos = qiter.getPos(); int[] spos = oshape; while (qiter.hasNext()) { int i = 0; for (; i < axis; i++) { spos[i] = qpos[i]; } spos[i++] = 0; for (; i < rank; i++) { spos[i] = qpos[i - 1]; } FourthMoment moment = new FourthMoment(); for (int j = 0; j < alen; j++) { spos[axis] = j; final double val = a.getDouble(spos); if (Double.isInfinite(val) || Double.isNaN(val)) continue; moment.increment(val); } sk.set((new Skewness(moment)).getResult(), spos); ku.set((new Kurtosis(moment)).getResult(), spos); } a.setStoredValue("skewness-" + axis, sk); a.setStoredValue("kurtosis-" + axis, ku); }