List of usage examples for org.apache.commons.math3.stat.regression SimpleRegression getIntercept
public double 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 w w w.j av a2 s .com*/ SimpleRegression regression = new SimpleRegression(); for (int i = start; i < start + length; i++) { regression.addData(i + 2, i); } return regression.getIntercept(); }
From source file:com.facebook.presto.operator.aggregation.TestDoubleRegrInterceptAggregation.java
private void testNonTrivialAggregation(Double[] y, Double[] x) { SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < x.length; i++) { regression.addData(x[i], y[i]);/*w w w . j av a2 s .c o m*/ } double expected = regression.getIntercept(); checkArgument(Double.isFinite(expected) && expected != 0., "Expected result is trivial"); testAggregation(expected, createDoublesBlock(y), createDoublesBlock(x)); }
From source file:com.facebook.presto.operator.aggregation.TestFloatRegrInterceptAggregation.java
@Override public Object getExpectedValue(int start, int length) { if (length <= 1) { return null; }/*w w w .j av 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.getIntercept(); }
From source file:com.facebook.presto.operator.aggregation.TestFloatRegrInterceptAggregation.java
private void testNonTrivialAggregation(Float[] y, Float[] x) { SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < x.length; i++) { regression.addData(x[i], y[i]);//from ww w . j a v a 2 s. c o m } float expected = (float) regression.getIntercept(); checkArgument(Float.isFinite(expected) && expected != 0.f, "Expected result is trivial"); testAggregation(expected, createFloatsBlock(y), createFloatsBlock(x)); }
From source file:com.facebook.presto.operator.aggregation.TestRealRegrInterceptAggregation.java
private void testNonTrivialAggregation(Float[] y, Float[] x) { SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < x.length; i++) { regression.addData(x[i], y[i]);/* w ww .j a va 2 s .com*/ } float expected = (float) regression.getIntercept(); checkArgument(Float.isFinite(expected) && expected != 0.f, "Expected result is trivial"); testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x)); }
From source file:de.qaware.chronix.timeseries.RegressionTest.java
@Test public void testRegression() { SimpleRegression regression = new SimpleRegression(); regression.addData(0.0, 1.0);//w ww .j a v a 2s . 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:cn.edu.pku.cbi.mosaichunter.filter.ExomeParameterFilter.java
@Override public void close() throws IOException { Collections.sort(sites, new Comparator<SimpleSite>() { public int compare(SimpleSite a, SimpleSite b) { if (a.depth > b.depth) { return 1; } else if (a.depth < b.depth) { return -1; } else { return 0; }/*ww w . ja v a 2 s. com*/ } }); int n = sites.size(); if (n == 0) { System.out.println("No data."); return; } int[] depth = new int[n]; long totalDepth = 0; double[] af = new double[n]; for (int i = 0; i < n; ++i) { depth[i] = sites.get(i).depth; af[i] = sites.get(i).altAf; totalDepth += depth[i]; } int maxGroups = n / minGroupSize + 2; int m = 0; double afMeanAll = 0; int[] groupSize = new int[maxGroups]; int[] groupPos = new int[maxGroups]; double[] afMean = new double[maxGroups]; double[] depthMid = new double[maxGroups]; double[] depthMidR = new double[maxGroups]; double[] afSd = new double[maxGroups]; double[] afSd2 = new double[maxGroups]; for (int i = 0; i <= n; ++i) { if (i == n || (i > 0 && depth[i] != depth[i - 1] && groupSize[m] >= minGroupSize)) { afMean[m] /= groupSize[m]; for (int j = groupPos[m]; j < i; ++j) { afSd2[m] += (af[j] - afMean[m]) * (af[j] - afMean[m]); } if (groupSize[m] > 1) { afSd2[m] /= groupSize[m] - 1; } afSd[m] = Math.sqrt(afSd2[m]); depthMid[m] = depth[(i + groupPos[m]) / 2]; depthMidR[m] = 1.0 / depthMid[m]; m++; if (i == n) { break; } groupPos[m] = i; } afMeanAll += af[i]; groupSize[m]++; afMean[m] += af[i]; } afMeanAll /= n; SimpleRegression sr = new SimpleRegression(); for (int i = 0; i < m; ++i) { sr.addData(depthMidR[i], afSd2[i]); } double k = sr.getSlope(); double d = sr.getIntercept(); double v = k / optimalDepth + d - afMeanAll * (1 - afMeanAll) / optimalDepth; double alpha = ((1 - afMeanAll) / v - 1 / afMeanAll) * afMeanAll * afMeanAll; double beta = alpha * (1 / afMeanAll - 1); long averageDepth = n == 0 ? 0 : totalDepth / n; System.out.println("average depth: " + averageDepth); System.out.println("alpha: " + Math.round(alpha)); System.out.println("beta: " + Math.round(beta)); if (rDataWriter != null) { rDataWriter.close(); } }
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 w ww .j av a2 s . c om*/ 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: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 w ww .j a v a 2 s. co 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:edu.jhu.hlt.parma.inference.transducers.UnigramLM.java
/** * Does the regression in log-space./* w w w. j a va 2 s .co m*/ * * @param cntCounter * @return */ // private double[] runLogSpaceRegression(Counter<Integer> cntCounter) { // double[] xData = new double[cntCounter.keySet().size()]; // double[] yData = new double[cntCounter.keySet().size()]; // double[] wts = new double[cntCounter.keySet().size()]; // int dataPtr = 0; // for(int cnt : cntCounter.keySet()) { // xData[dataPtr] = cnt; // yData[dataPtr++] = Math.log(cntCounter.getCount(cnt)); // } // Regression reg = new Regression(xData,yData,wts); // reg.linear(); // double[] coeffs = reg.getBestEstimates(); // assert coeffs.length == 2; // return coeffs; // } private double[] runLogSpaceRegression(Counter<Integer> cntCounter) { SimpleRegression reg = new SimpleRegression(); for (int cnt : cntCounter.keySet()) { reg.addData(cnt, Math.log(cntCounter.getCount(cnt))); } //System.out.println(reg.getIntercept()); //System.out.println(reg.getSlope()); //System.out.println(regression.getSlopeStdErr()); double[] coeffs = new double[] { reg.getIntercept(), reg.getSlope() }; return coeffs; }