List of usage examples for org.apache.commons.math.stat.regression OLSMultipleLinearRegression setNoIntercept
public void setNoIntercept(boolean noIntercept)
From source file:ca.uwaterloo.iss4e.algorithm.PARX.java
public static double[] computePARModel(final List<Double> readings, final List<Double> temperatures, int currentIndex, int trainingSize, int order, int seasons) throws SMASException { Pair pair = PARX.prepareAllVariables(readings, temperatures, currentIndex, trainingSize, order, seasons); double[] Y = (double[]) pair.getKey(); double[][] X = (double[][]) pair.getValue(); OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression(); regression.setNoIntercept(true); regression.newSampleData(Y, X);// w ww .j a va2 s. c om double[] beta = regression.estimateRegressionParameters(); return beta; }
From source file:ca.uwaterloo.iss4e.algorithm.PARX.java
public static double[] getLoadByTemperature(final List<Double> readings, final List<Double> temperatures, int order) throws SMASException { int seasons = 24; Pair pair = PARX.prepareAllVariables(readings, temperatures, readings.size() - 1, readings.size(), order, seasons);/*from w w w. j a v a2 s . co m*/ double[] Y = (double[]) pair.getKey(); double[][] X = (double[][]) pair.getValue(); OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression(); regression.setNoIntercept(true); regression.newSampleData(Y, X); double[] beta = regression.estimateRegressionParameters(); double[] loadByTemp = new double[Y.length * seasons]; int startIndex = readings.size() - Y.length * seasons; for (int i = 0; i < loadByTemp.length; ++i) { double t = temperatures.get(i + startIndex); loadByTemp[i] = beta[order + 0] * (t > 20 ? (t - 20) : 0) + beta[order + 1] * ((5 <= t && t < 16) ? (16 - t) : 0) + beta[order + 2] * (t < 5 ? (5 - t) : 0); } return loadByTemp; }
From source file:dfs.OLSTrendLine.java
@Override public void setValues(double[] y, double[] x) { if (x.length != y.length) { throw new IllegalArgumentException( String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length)); }//www . j a va 2 s . c o m double[][] xData = new double[x.length][]; for (int i = 0; i < x.length; i++) { // the implementation determines how to produce a vector of predictors from a single x xData[i] = xVector(x[i]); } if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were given for (int i = 0; i < x.length; i++) { y[i] = Math.log(y[i]); } } OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression(); ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired ols.newSampleData(y, xData); // provide the data to the model coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs }