public double predict(double value) { return this.simpleRegression.predict(value); } }
@Override double predict(List<Double> given) { return R.predict(given.get(0)); }
@Override public double[] getFitYvalues() { final double[] counts = new double[nPoints]; int i = 0; for (final double x : getXvalues()) { counts[i++] = regressionChosen.predict(x); } return counts; }
/** * Predicts the time of a taxi to arrive from a certain direction and Euclidean distance. * * @param direction The direction from which the taxi arrives. * @param distance The Euclidean distance that the taxi has to drive. * @return A prediction of the time that the taxi will be traveling or -1 if no prediction is * possible, yet. */ public int predictTravelTime(int direction, double distance) { byte directionBucket = getDirectionBucket(direction); double prediction = models[directionBucket].predict(distance); if (Double.isNaN(prediction)) { return -1; } else { return (int)prediction; } }
private static void addTrend(final Chart chart, final Series series, final List<Object> xdata) { final SimpleRegression model = new SimpleRegression(); final Iterator<? extends Number> y = series.getYData().iterator(); for (int x = 0; y.hasNext(); x++) { model.addData(x, y.next().doubleValue()); } final Color mc = series.getMarkerColor(); final Color c = new Color(mc.getRed(), mc.getGreen(), mc.getBlue(), 0x60); final Series trend = chart.addSeries(series.getName() + " (trend)", Arrays.asList(xdata.get(0), xdata.get(xdata.size() - 1)), Arrays.asList(model.predict(0), model.predict(xdata.size() - 1)) ); trend.setLineColor(c); trend.setMarker(SeriesMarker.NONE); } }
public Double getWorkerWageRegr(double qualifiedWage, double costThreshold, Map<String, Category> priors) { SimpleRegression regression = new SimpleRegression(); for (int m=1; m<=41; m+=4) { double cost = getWorkerCost(m, priors, 1000); if (cost == 0) break; regression.addData(Math.log(cost), m); } double d = regression.predict(Math.log(costThreshold)); return qualifiedWage/d; }
private static void addTrend(final Chart chart, final Series series, final List<Object> xdata) { final SimpleRegression model = new SimpleRegression(); final Iterator<? extends Number> y = series.getYData().iterator(); for (int x = 0; y.hasNext(); x++) { model.addData(x, y.next().doubleValue()); } final Color mc = series.getMarkerColor(); final Color c = new Color(mc.getRed(), mc.getGreen(), mc.getBlue(), 0x60); final Series trend = chart.addSeries(series.getName() + " (trend)", Arrays.asList(xdata.get(0), xdata.get(xdata.size() - 1)), Arrays.asList(model.predict(0), model.predict(xdata.size() - 1)) ); trend.setLineColor(c); trend.setMarker(SeriesMarker.NONE); } }
@NonNull private static PredictionData getPredictionData(int attempt, String tagId, ArrayList<GlucoseData> trendList) { PredictionData predictedGlucose = new PredictionData(); SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < trendList.size(); i++) { regression.addData(trendList.size() - i, (trendList.get(i)).glucoseLevel); } predictedGlucose.glucoseLevel = (int)regression.predict(15 + PREDICTION_TIME); predictedGlucose.trend = regression.getSlope(); predictedGlucose.confidence = regression.getSlopeConfidenceInterval(); predictedGlucose.errorCode = PredictionData.Result.OK; predictedGlucose.realDate = trendList.get(0).realDate; predictedGlucose.sensorId = tagId; predictedGlucose.attempt = attempt; predictedGlucose.sensorTime = trendList.get(0).sensorTime; return predictedGlucose; } }
import org.apache.commons.math3.stat.regression.SimpleRegression; public class Try_Regression { public static void main(String[] args) { // creating regression object, passing true to have intercept term SimpleRegression simpleRegression = new SimpleRegression(true); // passing data to the model // model will be fitted automatically by the class simpleRegression.addData(new double[][] { {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6} }); // querying for model parameters System.out.println("slope = " + simpleRegression.getSlope()); System.out.println("intercept = " + simpleRegression.getIntercept()); // trying to run model for unknown data System.out.println("prediction for 1.5 = " + simpleRegression.predict(1.5)); } }
@Override protected double doAnalysis(final ThroughputHistory history) { final SimpleRegression regression = new SimpleRegression(); for (int i = 1; i <= this.window; i++) { final double xaxis = history.getTimestampOfEntry(i); final double yaxis = history.getThroughputOfEntry(i); regression.addData(xaxis, yaxis); } final double currentTime = history.getTimestampOfEntry(0); double prediction = regression.predict(currentTime); if (Double.isNaN(prediction) || prediction < 0 || Double.isInfinite(prediction)) { prediction = 0; } return prediction; }
private void annotateNormalizedProfile(final SimpleRegression regression) { if (!annotate || regression == null) return; // mark slope final double xCenter = (xMin + xMax) / 2; final double ySlope = regression.predict(xCenter); drawDottedLine(xMin, ySlope, xCenter, ySlope); drawDottedLine(xCenter, yMin, xCenter, ySlope); // mark intercept if (regression.hasIntercept()) markPoint(new UPoint(0, regression.getIntercept()), DOT, 8); // assemble legend final double rsqred = regression.getRSquare(); final double k = -regression.getSlope(); tempLegend.append("k= ").append(ShollUtils.d2s(k)); tempLegend.append(" (R\u00B2= ").append(ShollUtils.d2s(rsqred)).append(")\n"); }
final double predicted = regression.predict( i );
/** * Gets the robust loess parameter estimates. * * @param y the dependent variable * @return the robust loess parameter estimates */ public static double[] getRobustLoessParameterEstimates(final double... y) { final double[] x = createIndependentArray(y.length); final SimpleRegression tricubeRegression = createWeightedLinearRegression(x, y, getTricubeWeights(y.length)); final double[] residuals = new double[y.length]; for (int i = 0; i < y.length; i++) { residuals[i] = y[i] - tricubeRegression.predict(x[i]); } final SimpleRegression tricubeBySqrRegression = createWeightedLinearRegression(x, y, getTricubeBisquareWeights(residuals)); final double[] estimates = tricubeBySqrRegression.regress().getParameterEstimates(); if (Double.isNaN(estimates[0]) || Double.isNaN(estimates[1])) { return tricubeRegression.regress().getParameterEstimates(); } return estimates; }
/** * Gets the robust loess parameter estimates. * * @param y the y array * @return the robust loess parameter estimates */ public static double[] getRobustLoessParameterEstimates(final double[] y) { int n = y.length; double[] x = new double[n]; for (int i = 0; i < n; i++) { x[i] = i + 1; } SimpleRegression tricubeRegression = createWeigthedLinearRegression(x, y, getTricubeWeigts(n)); double[] residuals = new double[n]; for (int i = 0; i < n; i++) { residuals[i] = y[i] - tricubeRegression.predict(x[i]); } SimpleRegression tricubeBySquareRegression = createWeigthedLinearRegression( x, y, getTricubeBisquareWeigts(residuals)); double[] estimates = tricubeBySquareRegression.regress() .getParameterEstimates(); if (Double.isNaN(estimates[0]) || Double.isNaN(estimates[1])) { return tricubeRegression.regress().getParameterEstimates(); } return estimates; }
final double value = regression.predict( categoryIndex++ );