Example usage for org.apache.commons.math.stat.regression SimpleRegression addData

List of usage examples for org.apache.commons.math.stat.regression SimpleRegression addData

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.regression SimpleRegression addData.

Prototype

public void addData(double[][] data) 

Source Link

Document

Adds the observations represented by the elements in data.

Usage

From source file:emlab.util.TrendEstimator.java

public static double[] estimateLinearTrend(double[][] input, double[] predictionYears) {
    ;/*w  w w . java2  s. c  om*/
    //Get logarithm of second trend
    SimpleRegression sr = new SimpleRegression();
    sr.addData(input);
    double result[] = new double[predictionYears.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = sr.predict(predictionYears[i]);
    }
    return result;

}

From source file:emlab.util.TrendEstimator.java

public static double[] estimateGeometricTrend(double[][] input, double[] predictionYears) {
    //Get logarithm of second trend
    for (int i = 0; i < input.length; i++) {
        input[i][1] = Math.log(input[i][1]);
    }/*from  ww  w .j  av a 2s  .co  m*/
    //input[1]=log;
    SimpleRegression sr = new SimpleRegression();
    sr.addData(input);
    double result[] = new double[predictionYears.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = Math.exp(sr.predict(predictionYears[i]));
    }
    return result;

}

From source file:emlab.util.GeometricTrendRegressionTest.java

@Test
public void testLinearTrendEstimation() {
    double[][] input = { { 0, 1 }, { 1, 1.1 }, { 2, 1.2 }, { 3, 1.3 }, { 4, 1.4 } };
    double[] predictionYears = { 5, 6, 7, 8 };
    double[] expectedResults = { 1.5, 1.6, 1.7, 1.8 };
    SimpleRegression sr = new SimpleRegression();
    sr.addData(input);
    for (int i = 0; i < predictionYears.length; i++) {
        assert (expectedResults[i] == sr.predict(predictionYears[i]));
    }//from   ww  w . ja va 2s .  c  o m
}

From source file:com.netxforge.netxstudio.common.math.NativeFunctions.java

/**
 * Return a {@link GenericsTuple tuple} with a key being the slope and the
 * value being the intercept of the trendline.
 * //from  w w w  .  j av  a2 s .co  m
 */
public GenericsTuple<Double, Double> trend(double[][] dataPair) {

    SimpleRegression regression = new SimpleRegression();
    regression.addData(dataPair);
    double slope = regression.getSlope();
    double intercept = regression.getIntercept();

    return new GenericsTuple<Double, Double>(slope, intercept);
}

From source file:org.noisemap.core.ProgressionOrbisGisManager.java

@Override
public void run() {
    while (enabled) {
        double progression = (getMainProgression() * 100);
        if (monitor != null) {
            monitor.progressTo((long) progression);
            if (monitor.isCancelled()) {
                break;
            }/*from w  w  w .j av a  2 s .  c o  m*/
        }
        // Evaluate computation time and print it in console.
        if (progressionHistoryTime.isEmpty()) {
            if (progression > 0) {
                progressionHistoryTime.push(System.currentTimeMillis());
                progressionHistoryValue.push(progression);
            }
        } else {
            if (lastPushedProgress < System.currentTimeMillis() - historyTimeStep) {
                //reg.addData(progression,System.currentTimeMillis());
                lastPushedProgress = System.currentTimeMillis();
                if ((int) (progression - progressionHistoryValue.lastElement()) >= 1) {
                    progressionHistoryTime.push(System.currentTimeMillis());
                    progressionHistoryValue.push(progression);
                }
                //Estimate end of computation
                SimpleRegression reg = new SimpleRegression();
                double prog[][] = new double[progressionHistoryTime.size() + 1][2];
                for (int t = 0; t < progressionHistoryTime.size(); t++) {
                    prog[t][0] = progressionHistoryValue.get(t);
                    prog[t][1] = progressionHistoryTime.get(t);
                }
                prog[progressionHistoryTime.size()][0] = progression;
                prog[progressionHistoryTime.size()][1] = System.currentTimeMillis();
                reg.addData(prog);
                lastEstimation = reg.predict(100);
                //If estimation fails, use simple estimation
                if (lastEstimation < System.currentTimeMillis() && progressionHistoryTime.size() > 1) {
                    lastEstimation = System.currentTimeMillis()
                            + (System.currentTimeMillis() - progressionHistoryTime.get(1)) * 100 / progression;
                }
            }
        }

        //Round
        progression = (((int) (progression * 100000)) / 100000.);
        if (lastEstimation > 0) {
            System.out.println(progression + " % remaining "
                    + getHumanTime((long) lastEstimation - System.currentTimeMillis()));
        } else {
            System.out.println(progression + " %");
        }

        try {
            Thread.sleep(updateInterval);
        } catch (InterruptedException e) {
            break;
        }
    }
}