Example usage for org.apache.commons.math.stat.descriptive.moment Skewness Skewness

List of usage examples for org.apache.commons.math.stat.descriptive.moment Skewness Skewness

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.descriptive.moment Skewness Skewness.

Prototype

public Skewness(Skewness original) 

Source Link

Document

Copy constructor, creates a new Skewness identical to the original

Usage

From source file:uk.ac.diamond.scisoft.analysis.dataset.Stats.java

/**
 * @param a dataset// w  w  w.ja  va  2s.  com
 * @return skewness
 */
public static Object skewness(final AbstractDataset a) {
    Object m = getFourthMoment(a);
    if (m instanceof FourthMoment) {
        return Double.valueOf((new Skewness((FourthMoment) m)).getResult());
    }

    FourthMoment[] mos = (FourthMoment[]) m;
    final int is = mos.length;
    double[] skews = new double[is];
    for (int j = 0; j < is; j++) {
        skews[j] = (new Skewness(mos[j])).getResult();
    }
    return skews;
}

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 ww  w . j a  va  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);
}