Example usage for org.apache.commons.math3.stat.regression SimpleRegression SimpleRegression

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

Introduction

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

Prototype

public SimpleRegression() 

Source Link

Document

Create an empty SimpleRegression instance

Usage

From source file:com.idylwood.Statistics.java

public static SimpleRegression regress(List<YahooFinance.Pair> pairs) {
    SimpleRegression regress = new SimpleRegression();
    regress.addData(data(pairs));/*  ww w  . j  a  v  a2  s . c  o m*/

    return regress;
}

From source file:de.qaware.chronix.timeseries.RegressionTest.java

@Test
public void testRegression() {

    SimpleRegression regression = new SimpleRegression();
    regression.addData(0.0, 1.0);//from w  w w .  ja  v a2 s. c  om
    regression.addData(1.0, 2.5);
    regression.addData(2.0, 3.0);

    double slope = regression.getSlope();
    double intercept = regression.getIntercept();
    long n = regression.getN();
    double err = regression.getMeanSquareError();
}

From source file:broadwick.statistics.regression.SimpleLinearRegression.java

/**
 * Create an empty SimpleLinearRegression instance.
 */
public SimpleLinearRegression() {
    regression = new SimpleRegression();
}

From source file:jp.ac.tohoku.ecei.sb.metabolomeqc.basiccorrector.helper.RegressionTest.java

@Test
public void testRegression() {
    SimpleRegression simpleRegression = new SimpleRegression();
    simpleRegression.addData(0.0, 1);//from  w  ww .j a v a  2  s.c  om
    simpleRegression.addData(0.5, 2);
    simpleRegression.addData(1.0, 3);
    simpleRegression.addData(1.5, 4);
    RegressionResults result = simpleRegression.regress();
    Assert.assertArrayEquals(new double[] { 1, 2 }, result.getParameterEstimates(), 0);
}

From source file:cloudnet.workloads.prediction.SimpleRegressionPredictionStrategy.java

@Override
public Long predictValue(long futureTimeStamp, long currTimeStamp, WorkloadHistory history) {
    Ensure.NotNull(history, "history");

    SimpleRegression r = new SimpleRegression();
    for (Map.Entry<Long, Long> entry : history.getWorkloadHistory().entrySet()) {
        r.addData(entry.getKey(), entry.getValue());
    }/*from ww w.ja v a2 s .c o m*/

    double predicted = r.predict(futureTimeStamp);
    return predicted == Double.NaN || predicted < 0 ? null : (long) predicted;
}

From source file:net.anthonypoon.fintech.assignment.one.part2.Portfolio.java

public Portfolio(String name, List<Stock> stockList, Index index, double riskFreeR) {
    this.name = name;
    // dereference the list
    for (Stock stock : stockList) {
        this.stockList.add(new Stock(stock));
    }//from  www  .j a va 2  s.com
    this.riskFreeR = riskFreeR;
    this.refIndex = index;
    this.marketVar = Math.pow(refIndex.getStd(), 2);
    for (Stock stock : this.stockList) {
        stock.setExReturn(stock.getRate() - riskFreeR);
        SimpleRegression regress = new SimpleRegression();
        List<Double> stockRList = stock.getRList();
        List<Double> indexRList = index.getRList();
        for (int i = 0; i < stockRList.size(); i++) {
            regress.addData(indexRList.get(i), stockRList.get(i));
        }
        stock.setAlpha(regress.getIntercept());
        stock.setBeta(regress.getSlope());
        stock.setEK(Math.sqrt(
                Math.pow(stock.getStd(), 2) - Math.pow(regress.getSlope(), 2) * Math.pow(index.getStd(), 2)));
    }
}

From source file:com.facebook.presto.operator.aggregation.TestFloatRegrSlopeAggregation.java

@Override
public Object getExpectedValue(int start, int length) {
    if (length <= 1) {
        return null;
    }//from  ww w .j  a  v  a  2  s  . c  o m
    SimpleRegression regression = new SimpleRegression();
    for (int i = start; i < start + length; i++) {
        regression.addData(i + 2, i);
    }
    return (float) regression.getSlope();
}

From source file:com.facebook.presto.operator.aggregation.TestDoubleRegrSlopeAggregation.java

@Override
public Object getExpectedValue(int start, int length) {
    if (length <= 1) {
        return null;
    }/*from   w w  w . j  ava  2  s  . c o  m*/
    SimpleRegression regression = new SimpleRegression();
    for (int i = start; i < start + length; i++) {
        regression.addData(i + 2, i);
    }
    return regression.getSlope();
}

From source file:com.facebook.presto.operator.aggregation.TestFloatRegrInterceptAggregation.java

@Override
public Object getExpectedValue(int start, int length) {
    if (length <= 1) {
        return null;
    }//from   w ww  .  j  ava  2s . c om
    SimpleRegression regression = new SimpleRegression();
    for (int i = start; i < start + length; i++) {
        regression.addData(i + 2, i);
    }
    return (float) regression.getIntercept();
}

From source file:com.facebook.presto.operator.aggregation.TestDoubleRegrInterceptAggregation.java

@Override
public Object getExpectedValue(int start, int length) {
    if (length <= 1) {
        return null;
    }//from   ww w .  java  2s .  c o m
    SimpleRegression regression = new SimpleRegression();
    for (int i = start; i < start + length; i++) {
        regression.addData(i + 2, i);
    }
    return regression.getIntercept();
}