List of usage examples for org.apache.commons.math3.stat.regression SimpleRegression getMeanSquareError
public double getMeanSquareError()
From source file:de.qaware.chronix.timeseries.RegressionTest.java
@Test public void testRegression() { SimpleRegression regression = new SimpleRegression(); regression.addData(0.0, 1.0);/* www . 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:eu.tango.energymodeller.energypredictor.CpuOnlyEnergyPredictor.java
/** * This calculates the mathematical function that predicts the power * consumption given the cpu utilisation. * * @param host The host to get the function for * @return The mathematical function that predicts the power consumption * given the cpu utilisation.//from www . j a v a2 s . c o m */ private PredictorFunction<LinearFunction> retrieveModel(Host host) { if (modelCache.containsKey(host)) { /** * A small cache avoids recalculating the regression so often. */ return modelCache.get(host); } LinearFunction model = new LinearFunction(); SimpleRegression regressor = new SimpleRegression(true); for (HostEnergyCalibrationData data : host.getCalibrationData()) { regressor.addData(data.getCpuUsage(), data.getWattsUsed()); } model.setIntercept(regressor.getIntercept()); model.setCoefficient(regressor.getSlope()); PredictorFunction<LinearFunction> answer = new PredictorFunction<>(model, regressor.getSumSquaredErrors(), Math.sqrt(regressor.getMeanSquareError())); modelCache.put(host, answer); return answer; }
From source file:org.apache.solr.client.solrj.io.eval.RegressionEvaluator.java
@Override public Object doWork(Object first, Object second) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }//from w ww. java 2 s . co m if (null == second) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the second value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } List<?> l1 = (List<?>) first; List<?> l2 = (List<?>) second; if (l2.size() < l1.size()) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - first list (%d) has more values than the second list (%d)", toExpression(constructingFactory), l1.size(), l2.size())); } SimpleRegression regression = new SimpleRegression(); for (int idx = 0; idx < l1.size(); ++idx) { regression.addData(((BigDecimal) l1.get(idx)).doubleValue(), ((BigDecimal) l2.get(idx)).doubleValue()); } Map<String, Number> map = new HashMap<>(); map.put("slope", regression.getSlope()); map.put("intercept", regression.getIntercept()); map.put("R", regression.getR()); map.put("N", regression.getN()); map.put("RSquare", regression.getRSquare()); map.put("regressionSumSquares", regression.getRegressionSumSquares()); map.put("slopeConfidenceInterval", regression.getSlopeConfidenceInterval()); map.put("interceptStdErr", regression.getInterceptStdErr()); map.put("totalSumSquares", regression.getTotalSumSquares()); map.put("significance", regression.getSignificance()); map.put("meanSquareError", regression.getMeanSquareError()); return new RegressionTuple(regression, map); }
From source file:org.apache.solr.client.solrj.io.stream.RegressionEvaluator.java
public Tuple evaluate(Tuple tuple) throws IOException { if (subEvaluators.size() != 2) { throw new IOException("Regress expects 2 columns as parameters"); }/*ww w. j a v a 2 s . c o m*/ StreamEvaluator colEval1 = subEvaluators.get(0); StreamEvaluator colEval2 = subEvaluators.get(1); List<Number> numbers1 = (List<Number>) colEval1.evaluate(tuple); List<Number> numbers2 = (List<Number>) colEval2.evaluate(tuple); double[] column1 = new double[numbers1.size()]; double[] column2 = new double[numbers2.size()]; for (int i = 0; i < numbers1.size(); i++) { column1[i] = numbers1.get(i).doubleValue(); } for (int i = 0; i < numbers2.size(); i++) { column2[i] = numbers2.get(i).doubleValue(); } SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < column1.length; i++) { regression.addData(column1[i], column2[i]); } Map map = new HashMap(); map.put("slope", regression.getSlope()); map.put("intercept", regression.getIntercept()); map.put("R", regression.getR()); map.put("N", regression.getN()); map.put("regressionSumSquares", regression.getRegressionSumSquares()); map.put("slopeConfidenceInterval", regression.getSlopeConfidenceInterval()); map.put("interceptStdErr", regression.getInterceptStdErr()); map.put("totalSumSquares", regression.getTotalSumSquares()); map.put("significance", regression.getSignificance()); map.put("meanSquareError", regression.getMeanSquareError()); return new RegressionTuple(regression, map); }