List of usage examples for org.apache.commons.math3.stat StatUtils sumSq
public static double sumSq(final double[] values) throws MathIllegalArgumentException
Double.NaN
if the array is empty. From source file:kieker.tools.opad.timeseries.AggregationMethod.java
/** * This method returns the result of the aggregation under one of the defined aggregation methods. * * @param aggregationValues// w ww . j ava 2 s . c om * Values to be aggregated * @return * Result of the aggregation */ public double getAggregationValue(final double[] aggregationValues) { switch (this) { case GEOMETRIC_MEAN: return StatUtils.geometricMean(aggregationValues); case MAX: return StatUtils.max(aggregationValues); case MEAN: return StatUtils.mean(aggregationValues); case MIN: return StatUtils.min(aggregationValues); case PERCENTILE90: return StatUtils.percentile(aggregationValues, 90); case PERCENTILE95: return StatUtils.percentile(aggregationValues, 95); case PRODUCT: return StatUtils.product(aggregationValues); case SUM: return StatUtils.sum(aggregationValues); case SUMSQ: return StatUtils.sumSq(aggregationValues); case SUMLOG: return StatUtils.sumLog(aggregationValues); case VARIANCE: return StatUtils.variance(aggregationValues); default: return StatUtils.mean(aggregationValues); } }
From source file:gamlss.utilities.WLSMultipleLinearRegression.java
/** * {@inheritDoc}/*from w ww . j a va 2s .c o m*/ * Double.NaN is not applicable */ @Override public double calculateTotalSumOfSquares() { if (this.copyOriginal) { if (isNoIntercept()) { return StatUtils.sumSq(this.y.toArray()); } else { return new SecondMoment().evaluate(this.y.toArray()); } } return Double.NaN; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.algorithm.CMAES.java
@Override public void initialize() { super.initialize(); int N = problem.getNumberOfVariables(); Solution prototypeSolution = problem.newSolution(); preInitChecks(prototypeSolution);/*from w w w.ja va2 s .co m*/ // initialization if (sigma < 0) { sigma = 0.5; } if (diagonalIterations < 0) { diagonalIterations = 150 * N / lambda; } diagD = new double[N]; pc = new double[N]; ps = new double[N]; B = new double[N][N]; C = new double[N][N]; for (int i = 0; i < N; i++) { pc[i] = 0; ps[i] = 0; diagD[i] = 1; for (int j = 0; j < N; j++) { B[i][j] = 0; } for (int j = 0; j < i; j++) { C[i][j] = 0; } B[i][i] = 1; C[i][i] = diagD[i] * diagD[i]; } // initialization of xmean if (xmean == null) { xmean = new double[N]; if (initialSearchPoint == null) { for (int i = 0; i < N; i++) { RealVariable variable = (RealVariable) prototypeSolution.getVariable(i); double offset = sigma * diagD[i]; double range = (variable.getUpperBound() - variable.getLowerBound() - 2 * sigma * diagD[i]); if (offset > 0.4 * (variable.getUpperBound() - variable.getLowerBound())) { offset = 0.4 * (variable.getUpperBound() - variable.getLowerBound()); range = 0.2 * (variable.getUpperBound() - variable.getLowerBound()); } xmean[i] = variable.getLowerBound() + offset + PRNG.nextDouble() * range; } } else { for (int i = 0; i < N; i++) { xmean[i] = initialSearchPoint[i] + sigma * diagD[i] * PRNG.nextGaussian(); } } } // initialization of other parameters chiN = Math.sqrt(N) * (1.0 - 1.0 / (4.0 * N) + 1.0 / (21.0 * N * N)); mu = (int) Math.floor(lambda / 2.0); weights = new double[mu]; for (int i = 0; i < mu; i++) { weights[i] = Math.log(mu + 1) - Math.log(i + 1); } double sum = StatUtils.sum(weights); for (int i = 0; i < mu; i++) { weights[i] /= sum; } double sumSq = StatUtils.sumSq(weights); mueff = 1.0 / sumSq; // also called mucov if (cs < 0) { cs = (mueff + 2) / (N + mueff + 3); } if (damps < 0) { damps = (1 + 2 * Math.max(0, Math.sqrt((mueff - 1.0) / (N + 1)) - 1)) + cs; } if (cc < 0) { cc = 4.0 / (N + 4.0); } if (ccov < 0) { ccov = 2.0 / (N + 1.41) / (N + 1.41) / mueff + (1 - (1.0 / mueff)) * Math.min(1, (2 * mueff - 1) / (mueff + (N + 2) * (N + 2))); } if (ccovsep < 0) { ccovsep = Math.min(1, ccov * (N + 1.5) / 3.0); } postInitChecks(); }
From source file:org.apache.solr.client.solrj.io.eval.SumSqEvaluator.java
@Override public Object doWork(Object value) throws IOException { if (null == value) { return value; } else if (!(value instanceof List<?>)) { throw new IOException( String.format(Locale.ROOT, "Invalid expression %s - found type %s for value, expecting a List", toExpression(constructingFactory), value.getClass().getSimpleName())); }/*from ww w . j a v a2 s .c o m*/ List<Number> list = (List<Number>) value; if (0 == list.size()) { return list; } double[] vec = new double[list.size()]; for (int i = 0; i < vec.length; i++) { vec[i] = list.get(i).doubleValue(); } return StatUtils.sumSq(vec); }
From source file:org.ssascaling.model.timeseries.learner.apache.OLSMultipleLinearRegression.java
/** * <p>Returns the sum of squared deviations of Y from its mean.</p> * * <p>If the model has no intercept term, <code>0</code> is used for the * mean of Y - i.e., what is returned is the sum of the squared Y values.</p> * * <p>The value returned by this method is the SSTO value used in * the {@link #calculateRSquared() R-squared} computation.</p> * * @return SSTO - the total sum of squares * @see #isNoIntercept()/* w w w . j a va2 s . co m*/ * @since 2.2 */ public double calculateTotalSumOfSquares() { if (isNoIntercept()) { return StatUtils.sumSq(getY().toArray()); } else { return new SecondMoment().evaluate(getY().toArray()); } }
From source file:tech.tablesaw.api.NumberColumnTest.java
@Test public void testSummarize() { IntColumn c = IntColumn.indexColumn("t", 99, 1); IntColumn c2 = c.copy();//w w w . j av a 2 s . co m c2.appendCell(""); double c2Variance = c2.variance(); double cVariance = StatUtils.variance(c.asDoubleArray()); assertEquals(cVariance, c2Variance, 0.00001); assertEquals(StatUtils.sumLog(c.asDoubleArray()), c2.sumOfLogs(), 0.00001); assertEquals(StatUtils.sumSq(c.asDoubleArray()), c2.sumOfSquares(), 0.00001); assertEquals(StatUtils.geometricMean(c.asDoubleArray()), c2.geometricMean(), 0.00001); assertEquals(StatUtils.product(c.asDoubleArray()), c2.product(), 0.00001); assertEquals(StatUtils.populationVariance(c.asDoubleArray()), c2.populationVariance(), 0.00001); assertEquals(new DescriptiveStatistics(c.asDoubleArray()).getQuadraticMean(), c2.quadraticMean(), 0.00001); assertEquals(new DescriptiveStatistics(c.asDoubleArray()).getStandardDeviation(), c2.standardDeviation(), 0.00001); assertEquals(new DescriptiveStatistics(c.asDoubleArray()).getKurtosis(), c2.kurtosis(), 0.00001); assertEquals(new DescriptiveStatistics(c.asDoubleArray()).getSkewness(), c2.skewness(), 0.00001); assertEquals(StatUtils.variance(c.asDoubleArray()), c.variance(), 0.00001); assertEquals(StatUtils.sumLog(c.asDoubleArray()), c.sumOfLogs(), 0.00001); assertEquals(StatUtils.sumSq(c.asDoubleArray()), c.sumOfSquares(), 0.00001); assertEquals(StatUtils.geometricMean(c.asDoubleArray()), c.geometricMean(), 0.00001); assertEquals(StatUtils.product(c.asDoubleArray()), c.product(), 0.00001); assertEquals(StatUtils.populationVariance(c.asDoubleArray()), c.populationVariance(), 0.00001); assertEquals(new DescriptiveStatistics(c.asDoubleArray()).getQuadraticMean(), c.quadraticMean(), 0.00001); assertEquals(new DescriptiveStatistics(c.asDoubleArray()).getStandardDeviation(), c.standardDeviation(), 0.00001); assertEquals(new DescriptiveStatistics(c.asDoubleArray()).getKurtosis(), c.kurtosis(), 0.00001); assertEquals(new DescriptiveStatistics(c.asDoubleArray()).getSkewness(), c.skewness(), 0.00001); }