List of usage examples for org.apache.commons.math3.stat.correlation Covariance Covariance
public Covariance()
From source file:com.facebook.presto.operator.aggregation.TestCovarianceSampAggregation.java
@Override public Object getExpectedValue(int start, int length) { if (length <= 1) { return null; }/*from w w w.java2s .c o m*/ return new Covariance().covariance(constructDoublePrimitiveArray(start + 5, length), constructDoublePrimitiveArray(start, length), true); }
From source file:com.facebook.presto.operator.aggregation.TestFloatCovarianceSampAggregation.java
@Override public Object getExpectedValue(int start, int length) { if (length <= 1) { return null; }/* ww w. j a v a 2 s . c o m*/ return (float) new Covariance().covariance(constructDoublePrimitiveArray(start + 5, length), constructDoublePrimitiveArray(start, length), true); }
From source file:com.facebook.presto.operator.aggregation.TestCovariancePopAggregation.java
@Override public Object getExpectedValue(int start, int length) { if (length <= 0) { return null; } else if (length == 1) { return 0.; }//from w w w.ja v a 2 s. co m Covariance covariance = new Covariance(); return covariance.covariance(constructDoublePrimitiveArray(start + 5, length), constructDoublePrimitiveArray(start, length), false); }
From source file:com.facebook.presto.operator.aggregation.TestFloatCovariancePopAggregation.java
@Override public Object getExpectedValue(int start, int length) { if (length <= 0) { return null; } else if (length == 1) { return 0.f; }//from w w w . java2s. co m Covariance covariance = new Covariance(); return (float) covariance.covariance(constructDoublePrimitiveArray(start + 5, length), constructDoublePrimitiveArray(start, length), false); }
From source file:com.insightml.math.statistics.Correlation.java
public Correlation(final double[] x, final double[] y) { arrays = new double[2][x.length]; for (int i = 0; i < x.length; ++i) { arrays[0][i] = x[i];/* w w w. ja v a 2 s . c o m*/ arrays[1][i] = y[i]; } final DoubleLinkedList x2 = new DoubleLinkedList(); final DoubleLinkedList y2 = new DoubleLinkedList(); for (int i = 0; i < x.length; ++i) { if (!Double.isNaN(x[i])) { x2.add(x[i]); y2.add(y[i]); } } final double[] x2arr = x2.toArray(); final double[] y2arr = y2.toArray(); covariance = new Covariance().covariance(x2arr, y2arr); pearson = new PearsonsCorrelation().correlation(x2arr, y2arr); spearman = new SpearmansCorrelation().correlation(x2arr, y2arr); mean = (Math.abs(pearson) + Math.abs(spearman)) / 2; }
From source file:com.github.pitzcarraldo.dissimilar.Dissimilar.java
/** * Calculate the SSIM value on a window of pixels * @param pLumaOne luma values for first image * @param pLumaTwo luma values for second image * @param pWidth width of the two images * @param pHeight height of the two images * @param pWindowSize window size//from w w w . j av a 2 s . c om * @param pStartX start x coordinate for the window * @param pStartY start y coordinate for the window * @return SSIM for the window */ private static double calcSSIMOnWindow(final double[] pLumaOne, final double[] pLumaTwo, final int pWidth, final int pHeight, final int pWindowSize, final int pStartX, final int pStartY) { final double k1 = 0.01; final double k2 = 0.03; final double L = Math.pow(2, 8) - 1;//255 (at least for the moment all pixel values are 8-bit) final double c1 = Math.pow(k1 * L, 2); final double c2 = Math.pow(k2 * L, 2); final int windowWidth = ((pWindowSize + pStartX) > pWidth) ? (pWidth - pStartX) : (pWindowSize); final int windowHeight = ((pWindowSize + pStartY) > pHeight) ? (pHeight - pStartY) : (pWindowSize); if (windowWidth <= 0 || windowHeight <= 0) { System.out.println(pWidth + " " + pStartX + " " + windowWidth + " " + windowHeight); System.out.println(pHeight + " " + pStartY + " " + windowWidth + " " + windowHeight); } //store a temporary copy of the pixels double[] pixelsOne = new double[windowWidth * windowHeight]; double[] pixelsTwo = new double[windowWidth * windowHeight]; for (int h = 0; h < windowHeight; h++) { for (int w = 0; w < windowWidth; w++) { pixelsOne[(h * windowWidth) + w] = pLumaOne[(pStartY + h) * pWidth + pStartX + w]; pixelsTwo[(h * windowWidth) + w] = pLumaTwo[(pStartY + h) * pWidth + pStartX + w]; } } final double ux = new Mean().evaluate(pixelsOne, 0, pixelsOne.length); final double uy = new Mean().evaluate(pixelsTwo, 0, pixelsTwo.length); final double o2x = new Variance().evaluate(pixelsOne); final double o2y = new Variance().evaluate(pixelsTwo); final double oxy = new Covariance().covariance(pixelsOne, pixelsTwo); final double num = (2 * ux * uy + c1) * (2 * oxy + c2); final double den = (ux * ux + uy * uy + c1) * (o2x + o2y + c2); final double ssim = num / den; return ssim; }
From source file:GeMSE.GS.Analysis.Stats.TwoSampleCovariancePanel.java
private void RunAnalysis() { if (_xArray == null || _yArray == null) { CovarianceL.setText("NaN"); return;// ww w. ja va 2s .c o m } _covariance = new Covariance(); CovarianceL .setText(String.valueOf(_decFor.format(_covariance.covariance(_xArray, _yArray, _biasCorrected)))); }
From source file:com.std.Index.java
@Override public void calculate_beta(YStockQuote sp500, int timeFrame) { double[] sp500Col = Arrays.copyOfRange(sp500.get_historical_rate_of_return(), 0, timeFrame); calculate_historical_rate_of_return(timeFrame); sp500Col = Arrays.copyOfRange(sp500.get_historical_rate_of_return(), 0, this.historical_rate_of_return.length); Covariance covarianceObj = new Covariance(); Variance varianceObj = new Variance(false); double covariance = covarianceObj.covariance(historical_rate_of_return, sp500Col); double variance = varianceObj.evaluate(sp500Col); this.Beta = String.valueOf(Math.round((covariance / variance) * 100.0) / 100.0); }
From source file:org.apache.solr.client.solrj.io.eval.CovarianceEvaluator.java
@Override public Object doWork(Object... values) throws IOException { if (values.length == 2) { Object first = values[0]; Object second = values[1]; Covariance covariance = new Covariance(); return covariance.covariance( ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(), ((List) second).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray()); } else if (values.length == 1) { Matrix matrix = (Matrix) values[0]; double[][] data = matrix.getData(); Covariance covariance = new Covariance(data, true); RealMatrix coMatrix = covariance.getCovarianceMatrix(); double[][] coData = coMatrix.getData(); return new Matrix(coData); } else {//from w w w .ja v a2 s . co m throw new IOException("The cov function expects either two numeric arrays or a matrix as parameters."); } }
From source file:org.apache.solr.client.solrj.io.stream.CovarianceEvaluator.java
public Number evaluate(Tuple tuple) throws IOException { 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(); }//from w w w. ja va 2 s.c o m for (int i = 0; i < numbers2.size(); i++) { column2[i] = numbers2.get(i).doubleValue(); } Covariance covariance = new Covariance(); return covariance.covariance(column1, column2); }