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:es.upm.oeg.tools.rdfshapes.libdemo.CommonsMathDemo.java

public static void main(String[] args) {

    DescriptiveStatistics stats = new DescriptiveStatistics();

    int inputArray[] = { 3, 4, 5, 6, 2, 3, 4, 3, 3, 4, 3, 6, 3, 2, 3, 1, 2, 1, 1, 1, 3 };

    // Add the data from the array
    for (int i = 0; i < inputArray.length; i++) {
        stats.addValue(inputArray[i]);/*from w  ww.j  a  va  2s  .  co  m*/
    }

    double mean = stats.getMean();
    double std = stats.getStandardDeviation();
    double median = stats.getPercentile(50);

    System.out.println("mean" + stats.getMean());
    System.out.println("standard deviation" + stats.getStandardDeviation());
    System.out.println("skewness" + stats.getSkewness());

}

From source file:com.sop4j.SimpleStatistics.java

public static void main(String[] args) {
    final MersenneTwister rng = new MersenneTwister(); // used for RNG... READ THE DOCS!!!
    final int[] values = new int[NUM_VALUES];

    final DescriptiveStatistics descriptiveStats = new DescriptiveStatistics(); // stores values
    final SummaryStatistics summaryStats = new SummaryStatistics(); // doesn't store values
    final Frequency frequency = new Frequency();

    // add numbers into our stats
    for (int i = 0; i < NUM_VALUES; ++i) {
        values[i] = rng.nextInt(MAX_VALUE);

        descriptiveStats.addValue(values[i]);
        summaryStats.addValue(values[i]);
        frequency.addValue(values[i]);/*w  w w. j  a va 2  s.c  o  m*/
    }

    // print out some standard stats
    System.out.println("MIN: " + summaryStats.getMin());
    System.out.println("AVG: " + String.format("%.3f", summaryStats.getMean()));
    System.out.println("MAX: " + summaryStats.getMax());

    // get some more complex stats only offered by DescriptiveStatistics
    System.out.println("90%: " + descriptiveStats.getPercentile(90));
    System.out.println("MEDIAN: " + descriptiveStats.getPercentile(50));
    System.out.println("SKEWNESS: " + String.format("%.4f", descriptiveStats.getSkewness()));
    System.out.println("KURTOSIS: " + String.format("%.4f", descriptiveStats.getKurtosis()));

    // quick and dirty stats (need a little help from Guava to convert from int[] to double[])
    System.out.println("MIN: " + StatUtils.min(Doubles.toArray(Ints.asList(values))));
    System.out.println("AVG: " + String.format("%.4f", StatUtils.mean(Doubles.toArray(Ints.asList(values)))));
    System.out.println("MAX: " + StatUtils.max(Doubles.toArray(Ints.asList(values))));

    // some stats based upon frequencies
    System.out.println("NUM OF 7s: " + frequency.getCount(7));
    System.out.println("CUMULATIVE FREQUENCY OF 7: " + frequency.getCumFreq(7));
    System.out.println("PERCENTAGE OF 7s: " + frequency.getPct(7));
}

From source file:com.intuit.tank.vm.common.util.ReportUtil.java

public static final String[] getSummaryData(String key, DescriptiveStatistics stats) {
    String[] ret = new String[ReportUtil.SUMMARY_HEADERS.length + PERCENTILES.length];
    int i = 0;/*  w  w w  . j  a v  a2s . c  o  m*/
    ret[i++] = key;// Page ID
    ret[i++] = INT_NF.format(stats.getN());// Sample Size
    ret[i++] = DOUBLE_NF.format(stats.getMean());// Mean
    ret[i++] = INT_NF.format(stats.getPercentile(50));// Meadian
    ret[i++] = INT_NF.format(stats.getMin());// Min
    ret[i++] = INT_NF.format(stats.getMax());// Max
    ret[i++] = DOUBLE_NF.format(stats.getStandardDeviation());// Std Dev
    ret[i++] = DOUBLE_NF.format(stats.getKurtosis());// Kurtosis
    ret[i++] = DOUBLE_NF.format(stats.getSkewness());// Skewness
    ret[i++] = DOUBLE_NF.format(stats.getVariance());// Varience
    for (int n = 0; n < PERCENTILES.length; n++) {
        ret[i++] = INT_NF.format(stats.getPercentile((Integer) PERCENTILES[n][1]));// Percentiles
    }
    return ret;
}

From source file:com.github.aptd.simulation.core.statistic.local.CStatistic.java

/**
 * write data/*from www .  j  a  v a 2  s .co m*/
 *
 * @param p_writer writer instance
 * @param p_name section name
 * @param p_statistic statistic value
 */
private static void apply(final IWriter p_writer, final String p_name,
        final DescriptiveStatistics p_statistic) {
    p_writer.section(1, p_name);

    p_writer.value("geometricmean", p_statistic.getGeometricMean());
    p_writer.value("kurtosis", p_statistic.getKurtosis());
    p_writer.value("max", p_statistic.getMax());
    p_writer.value("min", p_statistic.getMin());
    p_writer.value("mean", p_statistic.getMean());
    p_writer.value("count", p_statistic.getN());
    p_writer.value("25-percentile", p_statistic.getPercentile(0.25));
    p_writer.value("75-percentile", p_statistic.getPercentile(0.75));
    p_writer.value("populationvariance", p_statistic.getPopulationVariance());
    p_writer.value("quadraticmean", p_statistic.getQuadraticMean());
    p_writer.value("standdeviation", p_statistic.getStandardDeviation());
    p_writer.value("skewness", p_statistic.getSkewness());
    p_writer.value("sum", p_statistic.getSum());
    p_writer.value("sumsequared", p_statistic.getSumsq());
    p_writer.value("variance", p_statistic.getVariance());
}

From source file:com.intuit.tank.service.impl.v1.report.SummaryReportRunner.java

/**
 * @param key//from   ww  w. j  a  v a 2s  .  co m
 * @param value
 * @return
 */
private static SummaryData getSummaryData(int jobId, String key, DescriptiveStatistics stats) {
    SummaryData ret = SummaryDataBuilder.summaryData().withJobId(jobId)
            .withKurtosis(!Double.isNaN(stats.getKurtosis()) ? stats.getKurtosis() : 0).withMax(stats.getMax())
            .withMean(stats.getMean()).withMin(stats.getMin()).withPageId(key)
            .withPercentile10(stats.getPercentile(10)).withPercentile20(stats.getPercentile(20))
            .withPercentile30(stats.getPercentile(30)).withPercentile40(stats.getPercentile(40))
            .withPercentile50(stats.getPercentile(50)).withPercentile60(stats.getPercentile(60))
            .withPercentile70(stats.getPercentile(70)).withPercentile80(stats.getPercentile(80))
            .withPercentile90(stats.getPercentile(90)).withPercentile95(stats.getPercentile(95))
            .withPercentile99(stats.getPercentile(99)).withSampleSize((int) stats.getN())
            .withSkewness(!Double.isNaN(stats.getSkewness()) ? stats.getSkewness() : 0)
            .withSttDev(!Double.isNaN(stats.getStandardDeviation()) ? stats.getStandardDeviation() : 0)
            .withVarience(!Double.isNaN(stats.getVariance()) ? stats.getVariance() : 0).build();
    return ret;
}

From source file:ijfx.core.stats.DefaultImageStatisticsService.java

@Override
public Map<String, Double> descriptiveStatisticsToMap(DescriptiveStatistics descriptiveStats) {
    Map<String, Double> statistics = summaryStatisticsToMap(descriptiveStats);
    statistics.put(LBL_MEDIAN, descriptiveStats.getPercentile(50));
    statistics.put(LBL_KURTOSIS, descriptiveStats.getKurtosis());
    statistics.put(LBL_SKEWNESS, descriptiveStats.getSkewness());
    return statistics;
}

From source file:info.financialecology.finance.utilities.datastruct.DoubleTimeSeries.java

public double skewness() {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (int i = 0; i < this.values.size(); i++)
        stats.addValue(this.values.get(i));

    return stats.getSkewness();
}

From source file:com.intuit.tank.persistence.databases.BucketDataItemTest.java

/**
 * Run the DescriptiveStatistics getStats() method test.
 * //w w  w.  j av  a 2s.  c o  m
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/10/14 10:32 AM
 */
@Test
public void testGetStats_1() throws Exception {
    BucketDataItem fixture = new BucketDataItem(1, new Date(), new DescriptiveStatistics());

    DescriptiveStatistics result = fixture.getStats();

    assertNotNull(result);
    assertEquals(
            "DescriptiveStatistics:\nn: 0\nmin: NaN\nmax: NaN\nmean: NaN\nstd dev: NaN\nmedian: NaN\nskewness: NaN\nkurtosis: NaN\n",
            result.toString());
    assertEquals(Double.NaN, result.getMax(), 1.0);
    assertEquals(Double.NaN, result.getVariance(), 1.0);
    assertEquals(Double.NaN, result.getMean(), 1.0);
    assertEquals(-1, result.getWindowSize());
    assertEquals(0.0, result.getSumsq(), 1.0);
    assertEquals(Double.NaN, result.getKurtosis(), 1.0);
    assertEquals(0.0, result.getSum(), 1.0);
    assertEquals(Double.NaN, result.getSkewness(), 1.0);
    assertEquals(Double.NaN, result.getPopulationVariance(), 1.0);
    assertEquals(Double.NaN, result.getStandardDeviation(), 1.0);
    assertEquals(Double.NaN, result.getGeometricMean(), 1.0);
    assertEquals(0L, result.getN());
    assertEquals(Double.NaN, result.getMin(), 1.0);
}

From source file:iac_soap.statsq.NormVerdService.java

@Override
public NormVerdResponse calculateNormVerd(List<Double> data) throws MyFault {

    //Service Requirements 
    if (data.isEmpty()) {
        throw new MyFault("No data is provided");
    } else if (data.size() < 2) {
        throw new MyFault("A minimum of two data elements is required.");
    }/*from ww  w .j  av a2 s.c o m*/

    //Declaring Apache Commons DescriptiveStatistics
    DescriptiveStatistics stats = new DescriptiveStatistics();

    //Filling DescriptiveStatistics class with the provided dataset
    for (int i = 0; i < data.size(); i++) {
        stats.addValue(data.get(i));
    }

    //Let the DescriptiveStatistics class calculate the mean and standard deviation
    double mean = stats.getMean();
    double std = stats.getStandardDeviation();

    //Implementing the KolmogorovSmirnov test & calculating the kurtosis and skewness
    NormalDistribution x = new NormalDistribution(mean, std);
    double p_value = TestUtils.kolmogorovSmirnovTest(x, stats.getValues(), false);
    double kurtosis = stats.getKurtosis();
    double skewness = stats.getSkewness();
    boolean result = false;

    //Check if the dataset is a normal distribution:
    //KolmogorovSmirnov p_value should be >= 0.05
    //Both kurtosis and skewness should be between -2.0 and 2.0
    if (kurtosis < 2.0 && kurtosis > -2.0 && skewness < 2.0 && skewness > -2.0 && p_value >= 0.05) {
        result = true;
    }

    //Response message:
    NormVerdResponse nvr = new NormVerdResponse(result, p_value, kurtosis, skewness);

    return nvr;
}

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

private static TrainingSetFeature calculoFeaturesMagnitud(List<Registro> muestras, String activity) {

    TrainingSetFeature Feature = new TrainingSetFeature();
    DescriptiveStatistics stats_m = new DescriptiveStatistics();

    double[] fft_m;
    double[] AR_4;

    muestras = Util.calcMagnitud(muestras);

    for (int i = 0; i < muestras.size(); i++) {
        stats_m.addValue(muestras.get(i).getM_1());
    }/* ww  w  . j av a  2  s  .c o  m*/

    //********* FFT *********
    //fft_m = Util.transform(stats_m.getValues());
    fft_m = FFTMixedRadix.fftPowerSpectrum(stats_m.getValues());

    //******************* Calculos Magnitud *******************//
    //mean(s) - Arithmetic mean
    System.out.print(stats_m.getMean() + ",");
    Feature.setMeanX((float) stats_m.getMean());

    //std(s) - Standard deviation
    System.out.print(stats_m.getStandardDeviation() + ",");
    Feature.setStdX((float) stats_m.getStandardDeviation());

    //mad(s) - Median absolute deviation
    //
    //max(s) - Largest values in array
    System.out.print(stats_m.getMax() + ",");
    Feature.setMaxX((float) stats_m.getMax());

    //min(s) - Smallest value in array
    System.out.print(stats_m.getMin() + ",");
    Feature.setMinX((float) stats_m.getMin());

    //skewness(s) - Frequency signal Skewness
    System.out.print(stats_m.getSkewness() + ",");
    Feature.setSkewnessX((float) stats_m.getSkewness());

    //kurtosis(s) - Frequency signal Kurtosis
    System.out.print(stats_m.getKurtosis() + ",");
    Feature.setKurtosisX((float) stats_m.getKurtosis());

    //energy(s) - Average sum of the squares
    System.out.print(stats_m.getSumsq() / stats_m.getN() + ",");
    Feature.setEnergyX((float) (stats_m.getSumsq() / stats_m.getN()));

    //entropy(s) - Signal Entropy
    System.out.print(Util.calculateShannonEntropy(fft_m) + ",");
    Feature.setEntropyX(Util.calculateShannonEntropy(fft_m).floatValue());

    //iqr (s) Interquartile range
    System.out.print(stats_m.getPercentile(75) - stats_m.getPercentile(25) + ",");
    Feature.setIqrX((float) (stats_m.getPercentile(75) - stats_m.getPercentile(25)));

    try {
        //autoregression (s) -4th order Burg Autoregression coefficients
        AR_4 = AutoRegression.calculateARCoefficients(stats_m.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] + ",");
        Feature.setArX1((float) AR_4[0]);
        Feature.setArX2((float) AR_4[1]);
        Feature.setArX3((float) AR_4[2]);
        Feature.setArX4((float) 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_m, stats_m.getValues()) + ",");
    Feature.setMeanFreqx((float) Util.meanFreq(fft_m, stats_m.getValues()));

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

    return Feature;
}