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

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

Introduction

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

Prototype

public double predict(double x) 

Source Link

Document

Returns the "predicted" y value associated with the supplied x value, based on the data that has been added to the model when this method is activated.

Usage

From source file:emlab.util.TrendEstimator.java

public static double[] estimateLinearTrend(double[][] input, double[] predictionYears) {
    ;/*from   www .jav a 2 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   w  ww  .ja v  a2s.  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);/* ww  w .j  av a2 s.  co  m*/
    for (int i = 0; i < predictionYears.length; i++) {
        assert (expectedResults[i] == sr.predict(predictionYears[i]));
    }
}

From source file:guineu.modules.filter.Alignment.RANSAC.AlignmentRansacPlot.java

private List<RTs> smooth(List<RTs> list) {
    // Add points to the model in between of the real points to smooth the regression model
    Collections.sort(list, new RTs());

    for (int i = 0; i < list.size() - 1; i++) {
        RTs point1 = list.get(i);/*from ww w . j  a  va2 s . c  o m*/
        RTs point2 = list.get(i + 1);
        if (point1.RT < point2.RT - 2) {
            SimpleRegression regression = new SimpleRegression();
            regression.addData(point1.RT, point1.RT2);
            regression.addData(point2.RT, point2.RT2);
            double rt = point1.RT + 1;
            while (rt < point2.RT) {
                RTs newPoint = new RTs(rt, regression.predict(rt));
                list.add(newPoint);
                rt++;
            }

        }
    }

    return list;
}

From source file:guineu.modules.filter.Alignment.RANSACGCGC.AlignmentGCGCRansacPlot.java

private List<GCGCRTs> smooth(List<GCGCRTs> list) {
    // Add points to the model in between of the real points to smooth the regression model
    Collections.sort(list, new GCGCRTs());

    for (int i = 0; i < list.size() - 1; i++) {
        GCGCRTs point1 = list.get(i);/* w  ww .  jav a  2 s . c o  m*/
        GCGCRTs point2 = list.get(i + 1);
        if (point1.RT < point2.RT - 2) {
            SimpleRegression regression = new SimpleRegression();
            regression.addData(point1.RT, point1.RT2);
            regression.addData(point2.RT, point2.RT2);
            double rt = point1.RT + 1;
            while (rt < point2.RT) {
                GCGCRTs newPoint = new GCGCRTs(rt, regression.predict(rt));
                list.add(newPoint);
                rt++;
            }

        }
    }

    return list;
}

From source file:guineu.modules.filter.Alignment.RANSAC.RansacAlignerTask.java

private List<RTs> smooth(List<RTs> list, Range RTrange) {

    // Add one point at the begining and another at the end of the list to
    // ampliate the RT limits to cover the RT range completly
    try {//from  www .  jav a 2  s  . c  o  m
        Collections.sort(list, new RTs());

        RTs firstPoint = list.get(0);
        RTs lastPoint = list.get(list.size() - 1);

        double min = Math.abs(firstPoint.RT - RTrange.getMin());

        double RTx = firstPoint.RT - min;
        double RTy = firstPoint.RT2 - min;

        RTs newPoint = new RTs(RTx, RTy);
        list.add(newPoint);

        double max = Math.abs(RTrange.getMin() - lastPoint.RT);
        RTx = lastPoint.RT + max;
        RTy = lastPoint.RT2 + max;

        newPoint = new RTs(RTx, RTy);
        list.add(newPoint);
    } catch (Exception exception) {
    }

    // Add points to the model in between of the real points to smooth the regression model
    Collections.sort(list, new RTs());

    for (int i = 0; i < list.size() - 1; i++) {
        RTs point1 = list.get(i);
        RTs point2 = list.get(i + 1);
        if (point1.RT < point2.RT - 2) {
            SimpleRegression regression = new SimpleRegression();
            regression.addData(point1.RT, point1.RT2);
            regression.addData(point2.RT, point2.RT2);
            double rt = point1.RT + 1;
            while (rt < point2.RT) {
                RTs newPoint = new RTs(rt, regression.predict(rt));
                list.add(newPoint);
                rt++;
            }

        }
    }

    return list;
}

From source file:io.github.msdk.features.ransacaligner.RansacAlignerMethod.java

private List<RTs> smooth(List<RTs> list) {
    // Add points to the model in between of the real points to smooth the
    // regression model
    Collections.sort(list, new RTs());

    for (int i = 0; i < list.size() - 1; i++) {
        RTs point1 = list.get(i);/*from   ww  w.  java  2s  .co m*/
        RTs point2 = list.get(i + 1);
        if (point1.RT < point2.RT - 2) {
            SimpleRegression regression = new SimpleRegression();
            regression.addData(point1.RT, point1.RT2);
            regression.addData(point2.RT, point2.RT2);
            double rt = point1.RT + 1;
            while (rt < point2.RT) {
                RTs newPoint = new RTs(rt, regression.predict(rt));
                list.add(newPoint);
                rt++;
            }

        }
    }

    return list;
}

From source file:guineu.modules.filter.Alignment.RANSACGCGC.RansacGCGCAlignerTask.java

private List<GCGCRTs> smooth(List<GCGCRTs> list, Range RTrange) {

    // Add one point at the begining and another at the end of the list to
    // ampliate the RT limits to cover the RT range completly
    try {//w  ww  .java  2 s.  c om
        Collections.sort(list, new GCGCRTs());

        GCGCRTs firstPoint = list.get(0);
        GCGCRTs lastPoint = list.get(list.size() - 1);

        double min = Math.abs(firstPoint.RT - RTrange.getMin());

        double RTx = firstPoint.RT - min;
        double RTy = firstPoint.RT2 - min;

        GCGCRTs newPoint = new GCGCRTs(RTx, RTy);
        list.add(newPoint);

        double max = Math.abs(RTrange.getMin() - lastPoint.RT);
        RTx = lastPoint.RT + max;
        RTy = lastPoint.RT2 + max;

        newPoint = new GCGCRTs(RTx, RTy);
        list.add(newPoint);
    } catch (Exception exception) {
    }

    // Add points to the model in between of the real points to smooth the regression model
    Collections.sort(list, new GCGCRTs());

    for (int i = 0; i < list.size() - 1; i++) {
        GCGCRTs point1 = list.get(i);
        GCGCRTs point2 = list.get(i + 1);
        if (point1.RT < point2.RT - 2) {
            SimpleRegression regression = new SimpleRegression();
            regression.addData(point1.RT, point1.RT2);
            regression.addData(point2.RT, point2.RT2);
            double rt = point1.RT + 1;
            while (rt < point2.RT) {
                GCGCRTs newPoint = new GCGCRTs(rt, regression.predict(rt));
                list.add(newPoint);
                rt++;
            }

        }
    }

    return list;
}

From source file:guineu.modules.filter.Alignment.RANSACGCGC.RANSACGCGC.java

/**
 * Build the model creating a line with the 2 points
 * @param data vector with the points which represent all possible alignments.
 *///w w  w . j  a v  a2s  . c  o  m
private void getAllModelPoints(List<AlignGCGCStructMol> data) {

    // Create the regression line using the two points
    SimpleRegression regression = new SimpleRegression();

    for (int i = 0; i < data.size(); i++) {
        AlignGCGCStructMol point = data.get(i);
        if (point.ransacMaybeInLiers) {
            regression.addData(point.RT, point.RT2);
        }
    }

    // Add all the points which fit the model (the difference between the point
    // and the regression line is less than "t"
    for (AlignGCGCStructMol point : data) {
        double y = point.RT2;
        double bestY = regression.predict(point.RT);
        if (Math.abs(y - bestY) < t) {
            point.ransacAlsoInLiers = true;
            AlsoNumber++;
        } else {
            point.ransacAlsoInLiers = false;
        }
    }

}

From source file:guineu.modules.filter.Alignment.RANSAC.RANSAC.java

/**
 * Build the model creating a line with the 2 points
 *
 * @param data vector with the points which represent all possible
 * alignments.// w w w .ja v  a  2 s.c  om
 */
private void getAllModelPoints(List<AlignStructMol> data) {

    // Create the regression line using the two points
    SimpleRegression regression = new SimpleRegression();

    for (int i = 0; i < data.size(); i++) {
        AlignStructMol point = data.get(i);
        if (point.ransacMaybeInLiers) {
            regression.addData(point.RT, point.RT2);
        }
    }

    // Add all the points which fit the model (the difference between the point
    // and the regression line is less than "t"
    for (AlignStructMol point : data) {
        double y = point.RT2;
        double bestY = regression.predict(point.RT);
        if (Math.abs(y - bestY) < t) {
            point.ransacAlsoInLiers = true;
            AlsoNumber++;
        } else {
            point.ransacAlsoInLiers = false;
        }
    }

}