org.apache.commons.math.stat.descriptive.summary.Sum Java Examples
The following examples show how to use
org.apache.commons.math.stat.descriptive.summary.Sum.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); assertEquals(Math.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #2
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #3
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += values[i] - xbar; } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #4
Source File: MultivariateSummaryStatistics.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #5
Source File: SummaryStatisticsTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); assertEquals(Math.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #6
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); Assert.assertEquals(4, u.getMean(), 1E-14); Assert.assertEquals(4, u.getSumOfLogs(), 1E-14); Assert.assertEquals(FastMath.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); Assert.assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #7
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #8
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += values[i] - xbar; } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #9
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #10
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #11
Source File: Nopol2017_0069_s.java From coming with MIT License | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += values[i] - xbar; } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #12
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #13
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += (values[i] - xbar); } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #14
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); assertEquals(Math.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #15
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); assertEquals(Math.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #16
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); assertEquals(Math.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #17
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); assertEquals(FastMath.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #18
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #19
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += values[i] - xbar; } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #20
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += values[i] - xbar; } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #21
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #22
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += (values[i] - xbar); } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #23
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); assertEquals(FastMath.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #24
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #25
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSetterInjection() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.setMeanImpl(new Sum()); u.setSumLogImpl(new Sum()); u.addValue(1); u.addValue(3); assertEquals(4, u.getMean(), 1E-14); assertEquals(4, u.getSumOfLogs(), 1E-14); assertEquals(Math.exp(2), u.getGeometricMean(), 1E-14); u.clear(); u.addValue(1); u.addValue(2); assertEquals(3, u.getMean(), 1E-14); u.clear(); u.setMeanImpl(new Mean()); // OK after clear }
Example #26
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += values[i] - xbar; } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #27
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += values[i] - xbar; } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #28
Source File: MultivariateSummaryStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a MultivariateSummaryStatistics instance * @param k dimension of the data * @param isCovarianceBiasCorrected if true, the unbiased sample * covariance is computed, otherwise the biased population covariance * is computed */ public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) { this.k = k; sumImpl = new StorelessUnivariateStatistic[k]; sumSqImpl = new StorelessUnivariateStatistic[k]; minImpl = new StorelessUnivariateStatistic[k]; maxImpl = new StorelessUnivariateStatistic[k]; sumLogImpl = new StorelessUnivariateStatistic[k]; geoMeanImpl = new StorelessUnivariateStatistic[k]; meanImpl = new StorelessUnivariateStatistic[k]; for (int i = 0; i < k; ++i) { sumImpl[i] = new Sum(); sumSqImpl[i] = new SumOfSquares(); minImpl[i] = new Min(); maxImpl[i] = new Max(); sumLogImpl[i] = new SumOfLogs(); geoMeanImpl[i] = new GeometricMean(); meanImpl[i] = new Mean(); } covarianceImpl = new VectorialCovariance(k, isCovarianceBiasCorrected); }
Example #29
Source File: Mean.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link Mean} for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ @Override public double evaluate(final double[] values,final int begin, final int length) { if (test(values, begin, length)) { Sum sum = new Sum(); double sampleSize = length; // Compute initial estimate using definitional formula double xbar = sum.evaluate(values, begin, length) / sampleSize; // Compute correction factor in second pass double correction = 0; for (int i = begin; i < begin + length; i++) { correction += values[i] - xbar; } return xbar + (correction/sampleSize); } return Double.NaN; }
Example #30
Source File: SummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testSetterIllegalState() throws Exception { SummaryStatistics u = createSummaryStatistics(); u.addValue(1); u.addValue(3); try { u.setMeanImpl(new Sum()); Assert.fail("Expecting IllegalStateException"); } catch (IllegalStateException ex) { // expected } }