Example usage for org.apache.commons.math3.stat.descriptive.moment StandardDeviation getResult

List of usage examples for org.apache.commons.math3.stat.descriptive.moment StandardDeviation getResult

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive.moment StandardDeviation getResult.

Prototype

@Override
public double getResult() 

Source Link

Usage

From source file:com.cloudera.oryx.rdf.common.information.NumericInformationTest.java

private static double differentialEntropy(StandardDeviation stdev) {
    return FastMath.log(stdev.getResult() * FastMath.sqrt(2.0 * FastMath.PI * FastMath.E));
}

From source file:com.itemanalysis.psychometrics.irt.equating.MeanSigmaMethod.java

private void evaluate() {
    Mean mX = new Mean();
    StandardDeviation sdX = new StandardDeviation(populationStdDev);
    Mean mY = new Mean();
    StandardDeviation sdY = new StandardDeviation(populationStdDev);
    ItemResponseModel irmX;//  ww  w . jav  a  2 s  . c  om
    ItemResponseModel irmY;

    for (String s : sY) {
        irmX = itemFormX.get(s);
        irmY = itemFormY.get(s);

        irmX.incrementMeanSigma(mX, sdX);
        irmY.incrementMeanSigma(mY, sdY);

    }

    if (checkRaschModel()) {
        slope = 1.0;
    } else {
        slope = sdY.getResult() / sdX.getResult();
    }
    intercept = mY.getResult() - slope * mX.getResult();

}

From source file:de.biomedical_imaging.ij.nanotrackj.Track.java

/**
 * //w ww  . ja  v a2  s  .  c  om
 * @param driftx Drift in x direction (in pixels)
 * @param drifty Drift in y direction (in pixels)
 * @param tau Timelag
 * @return [0] = The mean squared displacement, [1] = Number of data points
 */
public double[] getMeanSquareDisplacementSD(double driftx, double drifty, int tau) {

    double msd = 0;

    StandardDeviation sd = new StandardDeviation();
    int N = 0;
    for (int i = tau; i < this.size(); ++i) {

        msd = Math.pow(this.get(i - tau).getX() - this.get(i).getX() - tau * driftx, 2)
                + Math.pow(this.get(i - tau).getY() - this.get(i).getY() - tau * drifty, 2);
        sd.increment(msd);

        ++N;
    }

    double[] result = new double[2];
    result[0] = sd.getResult();
    result[1] = N;
    return result;
}

From source file:com.itemanalysis.jmetrik.stats.transformation.LinearTransformationAnalysis.java

public String transformScore() throws SQLException {
    Statement stmt = null;/*  ww  w . j  av a2s .  com*/
    ResultSet rs = null;
    Double constrainedScore = null;

    try {
        //add variable to db
        dao.addColumnToDb(conn, tableName, addedVariableInfo);

        conn.setAutoCommit(false);//begin transaction

        Table sqlTable = new Table(tableName.getNameForDatabase());
        SelectQuery select = new SelectQuery();
        select.addColumn(sqlTable, selectedVariable.getName().nameForDatabase());
        select.addColumn(sqlTable, addedVariableInfo.getName().nameForDatabase());
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        rs = stmt.executeQuery(select.toString());

        this.firePropertyChange("message", "", "Transforming scores...");

        double origValue = 0.0;
        double transValue = 0.0;
        double z = 0.0;

        StandardDeviation sd = new StandardDeviation();
        Mean mean = new Mean();
        Min min = new Min();
        Max max = new Max();

        while (rs.next()) {
            origValue = rs.getDouble(selectedVariable.getName().nameForDatabase());
            if (!rs.wasNull()) {
                sd.increment(origValue);
                mean.increment(origValue);
                min.increment(origValue);
                max.increment(origValue);
            }
            updateProgress();
        }

        double meanValue = mean.getResult();
        double sdValue = sd.getResult();
        double minValue = min.getResult();
        double maxValue = max.getResult();
        double A = 1.0;
        double B = 0.0;

        rs.beforeFirst();

        while (rs.next()) {
            origValue = rs.getDouble(selectedVariable.getName().nameForDatabase());
            if (!rs.wasNull()) {
                if (type1) {
                    z = (origValue - meanValue) / sdValue;
                    transValue = scaleSd * z + scaleMean;
                    transValue = checkConstraints(transValue);
                } else {
                    A = (maxPossibleScore - minPossibleScore) / (maxValue - minValue);
                    B = minPossibleScore - minValue * A;
                    transValue = origValue * A + B;
                    transValue = checkConstraints(transValue);
                }

                descriptiveStatistics.increment(transValue);

                rs.updateDouble(addedVariableInfo.getName().nameForDatabase(), transValue);
                rs.updateRow();
            }
            updateProgress();
        }

        conn.commit();
        conn.setAutoCommit(true);

        //create output
        DefaultLinearTransformation linearTransformation = new DefaultLinearTransformation();
        linearTransformation.setScale(A);
        linearTransformation.setIntercept(B);

        StringBuilder sb = new StringBuilder();
        Formatter f = new Formatter(sb);
        f.format(publishHeader());
        f.format(descriptiveStatistics.toString());
        f.format(linearTransformation.toString());
        f.format("%n");
        f.format("%n");
        return f.toString();

    } catch (SQLException ex) {
        conn.rollback();
        conn.setAutoCommit(true);
        throw ex;
    } finally {
        if (rs != null)
            rs.close();
        if (stmt != null)
            stmt.close();
    }

}

From source file:com.itemanalysis.psychometrics.histogram.Histogram.java

private void createHistogram(double[] x) {
    n = x.length;/* w ww.  j  a  v  a  2s .co  m*/
    Min min = new Min();
    Max max = new Max();
    Mean mean = new Mean();
    StandardDeviation sd = new StandardDeviation();

    for (int i = 0; i < x.length; i++) {
        min.increment(x[i]);
        max.increment(x[i]);
        mean.increment(x[i]);
        sd.increment(x[i]);
    }

    double range = max.getResult() - min.getResult();
    double lowestBoundary = min.getResult() - range / 1000;
    double largestBoundary = max.getResult() + range / 1000;

    if (binCalculationType == BinCalculationType.SCOTT) {
        binCalc = new ScottBinCalculation(n, min.getResult(), max.getResult(), sd.getResult());
    } else if (binCalculationType == BinCalculationType.FREEDMAN_DIACONIS) {
        Percentile percentile = new Percentile();
        double q1 = percentile.evaluate(x, 25);
        double q3 = percentile.evaluate(x, 75);
        binCalc = new FreedmanDiaconisBinCalculation(n, min.getResult(), max.getResult(), q1, q3);
    } else if (binCalculationType == BinCalculationType.STURGES) {
        binCalc = new SturgesBinCalculation(n, min.getResult(), max.getResult());
    }

    numberOfBins = binCalc.numberOfBins();
    binWidth = binCalc.binWidth();

    //create bins
    createBins(lowestBoundary, largestBoundary);

    //count observations in each bin
    for (int i = 0; i < n; i++) {
        for (Bin b : bins) {
            b.increment(x[i]);
        }
    }
}

From source file:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurveAnalysis.java

private void initializeGridPoints() throws SQLException {
    Statement stmt = null;/*from   w w  w  . j a va  2  s . c  om*/
    ResultSet rs = null;

    //connect to db
    try {
        Table sqlTable = new Table(tableName.getNameForDatabase());
        SelectQuery select = new SelectQuery();
        select.addColumn(sqlTable, regressorVariable.getName().nameForDatabase());
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = stmt.executeQuery(select.toString());

        Min min = new Min();
        Max max = new Max();
        Mean mean = new Mean();
        StandardDeviation sd = new StandardDeviation();

        double value = 0.0;
        while (rs.next()) {
            value = rs.getDouble(regressorVariable.getName().nameForDatabase());
            if (!rs.wasNull()) {
                min.increment(value);
                max.increment(value);
                mean.increment(value);
                sd.increment(value);
            }
            updateProgress();
        }
        rs.close();
        stmt.close();

        //evaluation points
        double sdv = sd.getResult();
        double mn = mean.getResult();
        double lower = mn - 2.5 * sdv;
        double upper = mn + 2.5 * sdv;
        bwAdjustment *= sdv;
        bandwidth = new NonparametricIccBandwidth(sampleSize, bwAdjustment);
        gridPoints = command.getFreeOption("gridpoints").getInteger();
        //            uniformDistributionApproximation = new UniformDistributionApproximation(
        //                    min.getResult(), max.getResult(), gridPoints);
        uniformDistributionApproximation = new UniformDistributionApproximation(lower, upper, gridPoints);

    } catch (SQLException ex) {
        throw ex;
    } finally {
        if (rs != null)
            rs.close();
        if (stmt != null)
            stmt.close();
    }

}

From source file:com.itemanalysis.psychometrics.rasch.JMLE.java

public void linearTransformation(DefaultLinearTransformation lt, int precision) {
    Mean pMean = new Mean();
    StandardDeviation pSd = new StandardDeviation();

    //set transformation and rescale persons
    double newScale = lt.getScale();
    double newMean = lt.getIntercept();
    double oldPersonMean = pMean.evaluate(theta);
    double oldPersonSd = pSd.evaluate(theta);

    lt.setScaleAndIntercept(oldPersonMean, newMean, oldPersonSd, newScale);

    for (int i = 0; i < theta.length; i++) {
        theta[i] = lt.transform(theta[i]);
    }// w w  w. ja  v a  2s .c o  m

    //set transformation and rescale items
    Mean iMean = new Mean();
    StandardDeviation iSd = new StandardDeviation();
    double tempDifficulty = 0.0;

    for (VariableName v : items.keySet()) {
        tempDifficulty = items.get(v).getDifficulty();
        iMean.increment(tempDifficulty);
        iSd.increment(tempDifficulty);
    }

    lt.setScaleAndIntercept(iMean.getResult(), newMean, iSd.getResult(), newScale);

    for (VariableName v : items.keySet()) {
        items.get(v).linearTransformation(lt, precision);
    }

    //set transformation and rescale thresholds
    RatingScaleThresholds tempThresholds = null;

    for (String s : thresholds.keySet()) {
        tempThresholds = thresholds.get(s);
        lt.setScaleAndIntercept(tempThresholds.getThresholdMean(), newMean,
                tempThresholds.getThresholdStandardDeviation(), newScale);
        thresholds.get(s).linearTransformation(lt, precision);
    }
}

From source file:com.itemanalysis.psychometrics.irt.equating.MeanSigmaMethodTest.java

/**
 * Tests the calculations needed for mean/mean and mean/sigma scale linking.
 * Item parameters and true values obtained from example 2 from the STUIRT
 * program by Michael Kolen and colleagues. Note that the original example
 * used teh PARSCALE version of item parameters. These were converted to
 * ICL type parameters by subtracting a step from the item difficulty.
 *
 *//*w  w  w  .jav a2s  . c  o  m*/
@Test
public void mixedFormatDescriptiveStatisticsTestFormX() {
    System.out.println("Mixed format descriptive statistics test Form X");

    ItemResponseModel[] irm = new ItemResponseModel[17];

    irm[0] = new Irm3PL(0.751335, -0.897391, 0.244001, 1.7);
    irm[1] = new Irm3PL(0.955947, -0.811477, 0.242883, 1.7);
    irm[2] = new Irm3PL(0.497206, -0.858681, 0.260893, 1.7);
    irm[3] = new Irm3PL(0.724000, -0.123911, 0.243497, 1.7);
    irm[4] = new Irm3PL(0.865200, 0.205889, 0.319135, 1.7);
    irm[5] = new Irm3PL(0.658129, 0.555228, 0.277826, 1.7);
    irm[6] = new Irm3PL(1.082118, 0.950549, 0.157979, 1.7);
    irm[7] = new Irm3PL(0.988294, 1.377501, 0.084828, 1.7);
    irm[8] = new Irm3PL(1.248923, 1.614355, 0.181874, 1.7);
    irm[9] = new Irm3PL(1.116682, 2.353932, 0.246856, 1.7);
    irm[10] = new Irm3PL(0.438171, 3.217965, 0.309243, 1.7);
    irm[11] = new Irm3PL(1.082206, 4.441864, 0.192339, 1.7);

    double[] step1 = { 0, -1.09327, 1.101266 };
    irm[12] = new IrmGPCM(0.269994, step1, 1.7);

    double[] step2 = { 0, 1.526148, 1.739176 };
    irm[13] = new IrmGPCM(0.972506, step2, 1.7);

    double[] step3 = { 0, 1.362356, 5.566958 };
    irm[14] = new IrmGPCM(0.378812, step3, 1.7);

    double[] step4 = { 0, 1.486566, -0.071229, 1.614823 };
    irm[15] = new IrmGPCM(0.537706, step4, 1.7);

    double[] step5 = { 0, 1.425413, 2.630705, 3.242696 };
    irm[16] = new IrmGPCM(0.554506, step5, 1.7);

    Mean discriminationX = new Mean();
    Mean difficultyX = new Mean();

    Mean difficultyMeanX = new Mean();
    StandardDeviation difficultySdX = new StandardDeviation(false);//Do not correct for bias. Use N in the denominator, not N-1.

    for (int j = 0; j < 17; j++) {
        irm[j].incrementMeanMean(discriminationX, difficultyX);
        irm[j].incrementMeanSigma(difficultyMeanX, difficultySdX);
    }

    //        System.out.println("Mean/mean descriptive statistics for Form X");
    //        System.out.println("a-mean: " + discriminationX.getResult());
    //        System.out.println("b-mean: " + difficultyX.getResult());

    assertEquals("Mean/mean check: discrimination mean", 0.7719,
            Precision.round(discriminationX.getResult(), 4), 1e-5);
    assertEquals("Mean/mean check: difficulty mean", 1.3566, Precision.round(difficultyX.getResult(), 4), 1e-5);
    assertEquals("Mean/mean check: Number of difficulties (including steps) ", 24, difficultyX.getN(), 1e-3);

    //        System.out.println();
    //        System.out.println("Mean/sigma descriptive statistics for Form X");
    //        System.out.println("b-mean: " + difficultyMeanX.getResult());
    //        System.out.println("b-sd: " + difficultySdX.getResult());
    //        System.out.println("b-N: " + difficultyMeanX.getN() + ",   " + difficultySdX.getN());

    assertEquals("Mean/sigma check: difficulty mean", 1.3566, Precision.round(difficultyMeanX.getResult(), 4),
            1e-5);
    assertEquals("Mean/sigma check: difficulty sd", 1.6372, Precision.round(difficultySdX.getResult(), 4),
            1e-5);
    assertEquals("Mean/sigma check: Number of difficulties (including steps) ", 24, difficultyMeanX.getN(),
            1e-3);
    assertEquals("Mean/sigma check: Number of difficulties (including steps) ", 24, difficultySdX.getN(), 1e-3);

}

From source file:com.itemanalysis.psychometrics.irt.equating.MeanSigmaMethodTest.java

/**
 * Tests the calculations needed for mean/mean and mean/sigma scale linking.
 * Item parameters and true values obtained from example 2 from the STUIRT
 * program by Michael Kolen and colleagues. Note that the original example
 * used teh PARSCALE version of item parameters. These were converted to
 * ICL type parameters by subtracting a step from the item difficulty.
 *
 *///from  w  w w  . j a  v a  2s  .  c om
@Test
public void mixedFormatDescriptiveStatisticsTestFormY() {
    System.out.println("Mixed format descriptive statistics test Form Y");

    ItemResponseModel[] irm = new ItemResponseModel[17];

    irm[0] = new Irm3PL(0.887276, -1.334798, 0.134406, 1.7);
    irm[1] = new Irm3PL(1.184412, -1.129004, 0.237765, 1.7);
    irm[2] = new Irm3PL(0.609412, -1.464546, 0.15139, 1.7);
    irm[3] = new Irm3PL(0.923812, -0.576435, 0.240097, 1.7);
    irm[4] = new Irm3PL(0.822776, -0.476357, 0.192369, 1.7);
    irm[5] = new Irm3PL(0.707818, -0.235189, 0.189557, 1.7);
    irm[6] = new Irm3PL(1.306976, 0.242986, 0.165553, 1.7);
    irm[7] = new Irm3PL(1.295471, 0.598029, 0.090557, 1.7);
    irm[8] = new Irm3PL(1.366841, 0.923206, 0.172993, 1.7);
    irm[9] = new Irm3PL(1.389624, 1.380666, 0.238008, 1.7);
    irm[10] = new Irm3PL(0.293806, 2.02807, 0.203448, 1.7);
    irm[11] = new Irm3PL(0.885347, 3.152928, 0.195473, 1.7);

    double[] step1 = { 0, -1.387347, 0.399117 };
    irm[12] = new IrmGPCM(0.346324, step1, 1.7);

    double[] step2 = { 0, 0.756514, 0.956014 };
    irm[13] = new IrmGPCM(1.252012, step2, 1.7);

    double[] step3 = { 0, 0.975303, 4.676299 };
    irm[14] = new IrmGPCM(0.392282, step3, 1.7);

    double[] step4 = { 0, 0.643405, -0.418869, 0.804394 };
    irm[15] = new IrmGPCM(0.660841, step4, 1.7);

    double[] step5 = { 0, 0.641293, 1.750488, 2.53802 };
    irm[16] = new IrmGPCM(0.669612, step5, 1.7);

    Mean discriminationX = new Mean();
    Mean difficultyX = new Mean();

    Mean difficultyMeanX = new Mean();
    StandardDeviation difficultySdX = new StandardDeviation(false);//Do not correct for bias. Use N in the denominator, not N-1.

    for (int j = 0; j < 17; j++) {
        irm[j].incrementMeanMean(discriminationX, difficultyX);
        irm[j].incrementMeanSigma(difficultyMeanX, difficultySdX);
    }

    //        System.out.println("Mean/mean descriptive statistics for Form X");
    //        System.out.println("a-mean: " + discriminationX.getResult());
    //        System.out.println("b-mean: " + difficultyX.getResult());

    assertEquals("Mean/mean check: discrimination mean", 0.8820,
            Precision.round(discriminationX.getResult(), 4), 1e-5);
    assertEquals("Mean/mean check: difficulty mean", 0.6435, Precision.round(difficultyX.getResult(), 4), 1e-5);
    assertEquals("Mean/mean check: Number of difficulties (including steps) ", 24, difficultyX.getN(), 1e-3);

    //        System.out.println();
    //        System.out.println("Mean/sigma descriptive statistics for Form X");
    //        System.out.println("b-mean: " + difficultyMeanX.getResult());
    //        System.out.println("b-sd: " + difficultySdX.getResult());
    //        System.out.println("b-N: " + difficultyMeanX.getN() + ",   " + difficultySdX.getN());

    assertEquals("Mean/sigma check: difficulty mean", 0.6435, Precision.round(difficultyMeanX.getResult(), 4),
            1e-5);
    assertEquals("Mean/sigma check: difficulty sd", 1.4527, Precision.round(difficultySdX.getResult(), 4),
            1e-5);
    assertEquals("Mean/sigma check: Number of difficulties (including steps) ", 24, difficultyMeanX.getN(),
            1e-3);
    assertEquals("Mean/sigma check: Number of difficulties (including steps) ", 24, difficultySdX.getN(), 1e-3);

}

From source file:com.github.rinde.rinsim.scenario.generator.NHPoissonProcessTest.java

@Ignore
@Test//from w w w . j ava2 s  .  c  o m
public void test() throws IOException {

    final int numSamples = 100;
    final long lengthOfScenario = 4 * 60 * 60 * 1000;
    final double period = 30 * 60 * 1000;
    final int[] orders = new int[] { 10, 20, 30, 40, 50, 75, 100, 150, 200, 500 };
    final List<Point> dataPoints = newArrayList();
    final RandomGenerator rng = new MersenneTwister(123);

    final List<Double> relHeights = newArrayList();
    for (int i = 0; i < 10; i++) {
        relHeights.add(-.999 + i * .001);
    }
    for (int i = 0; i < 100; i++) {
        relHeights.add(-.99 + i * .05);
    }
    // for (int i = 0; i < 50; i++) {
    // relHeights.add(3.99 + (i * .5));
    // }
    Files.createParentDirs(new File("files/test/times/relheight-dynamism.txt"));
    final BufferedWriter writer = Files.newWriter(new File("files/test/times/relheight-dynamism.txt"),
            Charsets.UTF_8);

    for (int k = 0; k < orders.length; k++) {
        for (int i = 0; i < relHeights.size(); i++) {
            final double d = relHeights.get(i);
            final double relHeight = d;// -.99 + (j * .05);
            // final double period = 3600d;
            final double ordersPerPeriod = orders[k] / (lengthOfScenario / period);

            final IntensityFunction intensity = IntensityFunctions.sineIntensity().height(d).period(period)
                    .area(ordersPerPeriod).build();

            System.out.printf("%1d relative height: %1.3f%n", i, relHeight);

            // final List<Double> sineTimes = FluentIterable
            // .from(
            // ContiguousSet.create(Range.closedOpen(0L, lengthOfScenario),
            // DiscreteDomain.longs()))
            // .transform(Conversion.LONG_TO_DOUBLE)
            // .transform(intensity)
            // .toList();

            // Analysis
            // .writeLoads(
            // sineTimes,
            // new File(
            // "files/test/times/sine/sine-"
            // + Strings.padStart(Integer.toString(i), 2, '0')
            // + ".intens"));

            final TimeSeriesGenerator generator = TimeSeries.nonHomogenousPoisson(lengthOfScenario, intensity);

            double max = 0;
            double sum = 0;

            final StandardDeviation sd = new StandardDeviation();
            final List<Double> dynamismValues = newArrayList();
            for (int j = 0; j < numSamples; j++) {

                List<Double> times = generator.generate(rng.nextLong());
                while (times.size() < 2) {
                    times = generator.generate(rng.nextLong());
                }

                final double dyn = Metrics.measureDynamism(times, lengthOfScenario);
                dynamismValues.add(dyn);
                sd.increment(dyn);
                sum += dyn;
                max = Math.max(max, dyn);
                // if (j < 3) {
                // // System.out.printf("%1.3f%% %d%n", dyn * 100, times.size());
                // Analysis.writeTimes(
                // lengthOfScenario,
                // times,
                // new File(
                // "files/test/times/orders"
                // + Strings.padStart(Integer.toString(i), 2, '0') + "_"
                // + j
                // + "-" + (dyn * 100)
                // + ".times"));
                // }
            }

            try {
                writer.append(Double.toString(relHeight));
                writer.append(" ");
                writer.append(Integer.toString(orders[k]));
                writer.append(" ");
                writer.append(Joiner.on(" ").join(dynamismValues).toString());
                writer.append("\n");

            } catch (final IOException e) {
                checkState(false);
            }
            System.out.printf(" > dyn %1.3f+-%1.3f%n", +(sum / numSamples), sd.getResult());
            dataPoints.add(new Point(relHeight, sum / numSamples));
        }
    }
    writer.close();
    // Analysis.writeLocationList(dataPoints, new File(
    // "files/test/times/intensity-analysis.txt"));
}