Example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getSkewness

List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getSkewness

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getSkewness.

Prototype

public double getSkewness() 

Source Link

Document

Returns the skewness of the available values.

Usage

From source file:com.github.jessemull.microflexbigdecimal.stat.SkewnessTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.//from  w ww  .j a v a  2 s  .  c o m
 */
@Test
public void testAggregatedPlateCollectionIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    List<Plate> collection = Arrays.asList(arrayIndices);
    Map<Plate, BigDecimal> aggregatedReturnedMap = skewness.platesAggregated(collection, begin, end - begin,
            mc);

    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : plate) {
            resultList.addAll(well.data().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : collection) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.SkewnessTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *//*from   w  w w. ja v a  2 s  .c  o m*/
@Test
public void testAggregatedSetCollection() {

    List<WellSet> collection = new ArrayList<WellSet>();

    for (Plate plate : array) {
        collection.add(plate.dataSet());
    }

    Map<WellSet, BigDecimal> aggregatedReturnedMap = skewness.setsAggregated(collection, mc);
    Map<WellSet, BigDecimal> aggregatedResultMap = new TreeMap<WellSet, BigDecimal>();

    for (WellSet set : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : set) {
            resultList.addAll(well.data());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet set : collection) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.SkewnessTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array./*from   www  .  java  2s  . c o  m*/
 */
@Test
public void testAggregatedPlateArrayIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    Map<Plate, BigDecimal> aggregatedReturnedMap = skewness.platesAggregated(arrayIndices, begin, end - begin,
            mc);
    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : arrayIndices) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : arrayIndices) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.fpuna.preproceso.PreprocesoTS.java

private static void calculoFeatures(Registro[] muestras, String activity) {

    DescriptiveStatistics stats_x = new DescriptiveStatistics();
    DescriptiveStatistics stats_y = new DescriptiveStatistics();
    DescriptiveStatistics stats_z = new DescriptiveStatistics();
    //DescriptiveStatistics stats_m1 = new DescriptiveStatistics();
    //DescriptiveStatistics stats_m2 = new DescriptiveStatistics();
    double[] fft_x;
    double[] fft_y;
    double[] fft_z;
    double[] AR_4;

    for (int i = 0; i < muestras.length; i++) {
        stats_x.addValue(muestras[i].getValor_x());
        stats_y.addValue(muestras[i].getValor_y());
        stats_z.addValue(muestras[i].getValor_z());
    }/*from  w ww  .  j av  a2 s.  c  om*/

    //********* FFT *********
    fft_x = Util.transform(stats_x.getValues());
    fft_y = Util.transform(stats_y.getValues());
    fft_z = Util.transform(stats_z.getValues());

    //******************* Eje X *******************//
    //mean(s) - Arithmetic mean
    System.out.print(stats_x.getMean() + ",");
    //std(s) - Standard deviation
    System.out.print(stats_x.getStandardDeviation() + ",");
    //mad(s) - Median absolute deviation
    //
    //max(s) - Largest values in array
    System.out.print(stats_x.getMax() + ",");
    //min(s) - Smallest value in array
    System.out.print(stats_x.getMin() + ",");
    //skewness(s) - Frequency signal Skewness
    System.out.print(stats_x.getSkewness() + ",");
    //kurtosis(s) - Frequency signal Kurtosis
    System.out.print(stats_x.getKurtosis() + ",");
    //energy(s) - Average sum of the squares
    System.out.print(stats_x.getSumsq() / stats_x.getN() + ",");
    //entropy(s) - Signal Entropy
    System.out.print(Util.calculateShannonEntropy(fft_x) + ",");
    //iqr (s) Interquartile range
    System.out.print(stats_x.getPercentile(75) - stats_x.getPercentile(25) + ",");
    try {
        //autoregression (s) -4th order Burg Autoregression coefficients
        AR_4 = AutoRegression.calculateARCoefficients(stats_x.getValues(), 4, true);
        System.out.print(AR_4[0] + ",");
        System.out.print(AR_4[1] + ",");
        System.out.print(AR_4[2] + ",");
        System.out.print(AR_4[3] + ",");
    } catch (Exception ex) {
        Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex);
    }
    //meanFreq(s) - Frequency signal weighted average
    System.out.print(Util.meanFreq(fft_x, stats_x.getValues()) + ",");

    //******************* Eje Y *******************//
    //mean(s) - Arithmetic mean
    System.out.print(stats_y.getMean() + ",");
    //std(s) - Standard deviation
    System.out.print(stats_y.getStandardDeviation() + ",");
    //mad(s) - Median absolute deviation
    //
    //max(s) - Largest values in array
    System.out.print(stats_y.getMax() + ",");
    //min(s) - Smallest value in array
    System.out.print(stats_y.getMin() + ",");
    //skewness(s) - Frequency signal Skewness
    System.out.print(stats_y.getSkewness() + ",");
    //kurtosis(s) - Frequency signal Kurtosis
    System.out.print(stats_y.getKurtosis() + ",");
    //energy(s) - Average sum of the squares
    System.out.print(stats_y.getSumsq() / stats_y.getN() + ",");
    //entropy(s) - Signal Entropy
    System.out.print(Util.calculateShannonEntropy(fft_y) + ",");
    //iqr (s) Interquartile range
    System.out.print(stats_y.getPercentile(75) - stats_y.getPercentile(25) + ",");
    try {
        //autoregression (s) -4th order Burg Autoregression coefficients
        AR_4 = AutoRegression.calculateARCoefficients(stats_y.getValues(), 4, true);
        System.out.print(AR_4[0] + ",");
        System.out.print(AR_4[1] + ",");
        System.out.print(AR_4[2] + ",");
        System.out.print(AR_4[3] + ",");
    } catch (Exception ex) {
        Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex);
    }
    //meanFreq(s) - Frequency signal weighted average
    System.out.print(Util.meanFreq(fft_y, stats_y.getValues()) + ",");

    //******************* Eje Z *******************//
    //mean(s) - Arithmetic mean
    System.out.print(stats_z.getMean() + ",");
    //std(s) - Standard deviation
    System.out.print(stats_z.getStandardDeviation() + ",");
    //mad(s) - Median absolute deviation
    //
    //max(s) - Largest values in array
    System.out.print(stats_z.getMax() + ",");
    //min(s) - Smallest value in array
    System.out.print(stats_z.getMin() + ",");
    //skewness(s) - Frequency signal Skewness
    System.out.print(stats_z.getSkewness() + ",");
    //kurtosis(s) - Frequency signal Kurtosis
    System.out.print(stats_z.getKurtosis() + ",");
    //energy(s) - Average sum of the squares
    System.out.print(stats_z.getSumsq() / stats_z.getN() + ",");
    //entropy(s) - Signal Entropy
    System.out.print(Util.calculateShannonEntropy(fft_z) + ",");
    //iqr (s) Interquartile range
    System.out.print(stats_z.getPercentile(75) - stats_z.getPercentile(25) + ",");
    try {
        //autoregression (s) -4th order Burg Autoregression coefficients
        AR_4 = AutoRegression.calculateARCoefficients(stats_z.getValues(), 4, true);
        System.out.print(AR_4[0] + ",");
        System.out.print(AR_4[1] + ",");
        System.out.print(AR_4[2] + ",");
        System.out.print(AR_4[3] + ",");
    } catch (Exception ex) {
        Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex);
    }
    //meanFreq(s) - Frequency signal weighted average
    System.out.print(Util.meanFreq(fft_z, stats_z.getValues()) + ",");

    //******************* Feature combinados *******************/
    //sma(s1; s2; s3) - Signal magnitude area
    System.out.print(Util.sma(stats_x.getValues(), stats_y.getValues(), stats_z.getValues()) + ",");
    //correlation(s1; s2) - Pearson Correlation coefficient
    System.out.print(new PearsonsCorrelation().correlation(stats_x.getValues(), stats_y.getValues()) + ",");
    System.out.print(new PearsonsCorrelation().correlation(stats_x.getValues(), stats_z.getValues()) + ",");
    System.out.print(new PearsonsCorrelation().correlation(stats_y.getValues(), stats_z.getValues()) + ",");

    //******************* Actividad *******************/
    System.out.print(activity);
    System.out.print("\n");
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.SkewnessBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using an array.
 *//*from  ww w  . ja v  a2 s .c  om*/
@Test
public void testAggregatedSetArray() {

    WellSetBigDecimal[] setArray = new WellSetBigDecimal[array.length];

    for (int i = 0; i < setArray.length; i++) {
        setArray[i] = array[i].dataSet();
    }

    Map<WellSetBigDecimal, BigDecimal> aggregatedReturnedMap = skewness.setsAggregated(setArray, mc);
    Map<WellSetBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigDecimal, BigDecimal>();

    for (WellSetBigDecimal set : setArray) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigDecimal well : set) {
            resultList.addAll(well.data());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigDecimal set : setArray) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }

}

From source file:com.github.jessemull.microflex.stat.statbiginteger.SkewnessBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array.//w  ww  . j  a  v a2 s. co  m
 */
@Test
public void testAggregatedPlateArrayIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    Map<PlateBigInteger, BigDecimal> aggregatedReturnedMap = skewness.platesAggregated(arrayIndices, begin,
            end - begin, mc);
    Map<PlateBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigInteger, BigDecimal>();

    for (PlateBigInteger plate : arrayIndices) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateBigInteger plate : arrayIndices) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.SkewnessTest.java

/**
 * Tests the aggregated plate statistics method using an array.
 *///from   w  w  w.  j av  a  2  s .  c  o  m
@Test
public void testAggregatedSetArray() {

    WellSet[] setArray = new WellSet[array.length];

    for (int i = 0; i < setArray.length; i++) {
        setArray[i] = array[i].dataSet();
    }

    Map<WellSet, BigDecimal> aggregatedReturnedMap = skewness.setsAggregated(setArray, mc);
    Map<WellSet, BigDecimal> aggregatedResultMap = new TreeMap<WellSet, BigDecimal>();

    for (WellSet set : setArray) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : set) {
            resultList.addAll(well.data());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet set : setArray) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }

}

From source file:com.github.jessemull.microflexbiginteger.stat.SkewnessTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.//  www. j  a  v  a  2  s . c o  m
 */
@Test
public void testAggregatedPlateCollectionIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    List<Plate> collection = Arrays.asList(arrayIndices);
    Map<Plate, BigDecimal> aggregatedReturnedMap = skewness.platesAggregated(collection, begin, end - begin,
            mc);

    Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>();

    for (Plate plate : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (Plate plate : collection) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.SkewnessTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *//*from w w w.  j av  a  2s .  c om*/
@Test
public void testAggregatedSetCollection() {

    List<WellSet> collection = new ArrayList<WellSet>();

    for (Plate plate : array) {
        collection.add(plate.dataSet());
    }

    Map<WellSet, BigDecimal> aggregatedReturnedMap = skewness.setsAggregated(collection, mc);
    Map<WellSet, BigDecimal> aggregatedResultMap = new TreeMap<WellSet, BigDecimal>();

    for (WellSet set : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : set) {
            resultList.addAll(well.toBigDecimal());
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet set : collection) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.SkewnessBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.//  w  ww.  j  av a 2 s .c  o m
 */
@Test
public void testAggregatedPlateCollectionIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    List<PlateBigInteger> collection = Arrays.asList(arrayIndices);
    Map<PlateBigInteger, BigDecimal> aggregatedReturnedMap = skewness.platesAggregated(collection, begin,
            end - begin, mc);

    Map<PlateBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigInteger, BigDecimal>();

    for (PlateBigInteger plate : collection) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getSkewness();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(plate, aggregatedResult);
    }

    for (PlateBigInteger plate : collection) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}