当前位置: 首页>>代码示例>>Java>>正文


Java Mean类代码示例

本文整理汇总了Java中org.apache.commons.math.stat.descriptive.moment.Mean的典型用法代码示例。如果您正苦于以下问题:Java Mean类的具体用法?Java Mean怎么用?Java Mean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Mean类属于org.apache.commons.math.stat.descriptive.moment包,在下文中一共展示了Mean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addValue

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
/**
 * Add a value to the data
 * 
 * @param value  the value to add
 */
public void addValue(double value) {
    sumImpl.increment(value);
    sumsqImpl.increment(value);
    minImpl.increment(value);
    maxImpl.increment(value);
    sumLogImpl.increment(value);
    secondMoment.increment(value);
    // If mean, variance or geomean have been overridden,
    // need to increment these
    if (!(meanImpl instanceof Mean)) {
            meanImpl.increment(value);
    }
    if (!(varianceImpl instanceof Variance)) {
        varianceImpl.increment(value);
    }
    if (!(geoMeanImpl instanceof GeometricMean)) {
        geoMeanImpl.increment(value);
    }
    n++;
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:SummaryStatistics.java

示例2: MultivariateSummaryStatistics

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
/**
 * 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);

}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:33,代码来源:MultivariateSummaryStatistics.java

示例3: testInteraction

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
public void testInteraction() {
    
    FourthMoment m4 = new FourthMoment();
    Mean m = new Mean(m4);
    Variance v = new Variance(m4);
    Skewness s= new Skewness(m4);
    Kurtosis k = new Kurtosis(m4);

    for (int i = 0; i < testArray.length; i++){
        m4.increment(testArray[i]);
    }
    
    assertEquals(mean,m.getResult(),tolerance);
    assertEquals(var,v.getResult(),tolerance);
    assertEquals(skew ,s.getResult(),tolerance);
    assertEquals(kurt,k.getResult(),tolerance);

}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:InteractionTest.java

示例4: testSetterInjection

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
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
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:17,代码来源:SummaryStatisticsTest.java

示例5: testSetterInjection

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
public void testSetterInjection() throws Exception {
    MultivariateSummaryStatistics u = new MultivariateSummaryStatistics(2, true);
    u.setMeanImpl(new StorelessUnivariateStatistic[] {
                    new sumMean(), new sumMean()
                  });
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    assertEquals(4, u.getMean()[0], 1E-14);
    assertEquals(6, u.getMean()[1], 1E-14);
    u.clear();
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    assertEquals(4, u.getMean()[0], 1E-14);
    assertEquals(6, u.getMean()[1], 1E-14);
    u.clear();
    u.setMeanImpl(new StorelessUnivariateStatistic[] {
                    new Mean(), new Mean()
                  }); // OK after clear
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    assertEquals(2, u.getMean()[0], 1E-14);
    assertEquals(3, u.getMean()[1], 1E-14);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:MultivariateSummaryStatisticsTest.java

示例6: reduce

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
public void reduce(Text key,
                   Iterator<DoubleWritable> values,
                   OutputCollector<AvroWrapper<StockAvg>,
                       NullWritable> output,
                   Reporter reporter) throws IOException {

  Mean mean = new Mean();
  while (values.hasNext()) {
    mean.increment(values.next().get());
  }
  StockAvg avg = new StockAvg();
  avg.setSymbol(key.toString());
  avg.setAvg(mean.getResult());
  output.collect(new AvroWrapper<StockAvg>(avg),
      NullWritable.get());
}
 
开发者ID:Hanmourang,项目名称:hiped2,代码行数:17,代码来源:AvroMixedMapReduce.java

示例7: calculateCentroid

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
/**
 * Calculates the centroid of all given points in a nD space (assumes that
 * all points have n coordinates). Each coordinate of the centroid is a mean
 * of all values of the same coordinate of each point.
 * 
 * @param points all points
 * @return the centroid of all given points
 */
public Vector<Double> calculateCentroid( List<Vector<Double>> points ) {
    List<Mean> coordinateMeans = new ArrayList<Mean>();
    
    for ( int i = 0; i < points.get( 0 ).size(); ++i ) {
        coordinateMeans.add( new Mean() );
    }
    
    for ( Vector<Double> point : points ) {
        for ( int i = 0; i < point.size(); ++i ) {
            coordinateMeans.get( i ).increment( point.get( i ) );
        }
    }
    
    Vector<Double> centroid = new Vector<Double>();
    
    for ( Mean mean : coordinateMeans ) {
        centroid.add( mean.getResult() );
    }
     
    return centroid;
}
 
开发者ID:arrahtech,项目名称:osdq-core,代码行数:30,代码来源:MathCalculator.java

示例8: addValue

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
/**
 * Add a value to the data
 * @param value the value to add
 */
public void addValue(double value) {
    sumImpl.increment(value);
    sumsqImpl.increment(value);
    minImpl.increment(value);
    maxImpl.increment(value);
    sumLogImpl.increment(value);
    secondMoment.increment(value);
    // If mean, variance or geomean have been overridden,
    // need to increment these
    if (!(meanImpl instanceof Mean)) {
        meanImpl.increment(value);
    }
    if (!(varianceImpl instanceof Variance)) {
        varianceImpl.increment(value);
    }
    if (!(geoMeanImpl instanceof GeometricMean)) {
        geoMeanImpl.increment(value);
    }
    n++;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:SummaryStatistics.java

示例9: covariance

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
/**
 * Computes the covariance between the two arrays.
 *
 * <p>Array lengths must match and the common length must be at least 2.</p>
 *
 * @param xArray first data array
 * @param yArray second data array
 * @param biasCorrected if true, returned value will be bias-corrected
 * @return returns the covariance for the two arrays
 * @throws  IllegalArgumentException if the arrays lengths do not match or
 * there is insufficient data
 */
public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected)
    throws IllegalArgumentException {
    Mean mean = new Mean();
    double result = 0d;
    int length = xArray.length;
    if(length == yArray.length && length > 1) {
        double xMean = mean.evaluate(xArray);
        double yMean = mean.evaluate(yArray);
        for (int i = 0; i < length; i++) {
            double xDev = xArray[i] - xMean;
            double yDev = yArray[i] - yMean;
            result += (xDev * yDev - result) / (i + 1);
        }
    }
    else {
        throw MathRuntimeException.createIllegalArgumentException(
           "arrays must have the same length and both must have at " +
           "least two elements. xArray has size {0}, yArray has {1} elements",
                length, yArray.length);
    }
    return biasCorrected ? result * ((double) length / (double)(length - 1)) : result;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:Covariance.java

示例10: testInteraction

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
public void testInteraction() {

        FourthMoment m4 = new FourthMoment();
        Mean m = new Mean(m4);
        Variance v = new Variance(m4);
        Skewness s= new Skewness(m4);
        Kurtosis k = new Kurtosis(m4);

        for (int i = 0; i < testArray.length; i++){
            m4.increment(testArray[i]);
        }

        assertEquals(mean,m.getResult(),tolerance);
        assertEquals(var,v.getResult(),tolerance);
        assertEquals(skew ,s.getResult(),tolerance);
        assertEquals(kurt,k.getResult(),tolerance);

    }
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:InteractionTest.java

示例11: covariance

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
/**
 * Computes the covariance between the two arrays.
 *
 * <p>Array lengths must match and the common length must be at least 2.</p>
 *
 * @param xArray first data array
 * @param yArray second data array
 * @param biasCorrected if true, returned value will be bias-corrected
 * @return returns the covariance for the two arrays
 * @throws  IllegalArgumentException if the arrays lengths do not match or
 * there is insufficient data
 */
public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected)
    throws IllegalArgumentException {
    Mean mean = new Mean();
    double result = 0d;
    int length = xArray.length;
    if (length != yArray.length) {
        throw MathRuntimeException.createIllegalArgumentException(
              LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length);
    } else if (length < 2) {
        throw MathRuntimeException.createIllegalArgumentException(
              LocalizedFormats.INSUFFICIENT_DIMENSION, length, 2);
    } else {
        double xMean = mean.evaluate(xArray);
        double yMean = mean.evaluate(yArray);
        for (int i = 0; i < length; i++) {
            double xDev = xArray[i] - xMean;
            double yDev = yArray[i] - yMean;
            result += (xDev * yDev - result) / (i + 1);
        }
    }
    return biasCorrected ? result * ((double) length / (double)(length - 1)) : result;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:Covariance.java

示例12: testSetterInjection

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
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
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:SummaryStatisticsTest.java

示例13: testSetterInjection

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
@Test
public void testSetterInjection() throws Exception {
    MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(2, true);
    u.setMeanImpl(new StorelessUnivariateStatistic[] {
                    new sumMean(), new sumMean()
                  });
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    Assert.assertEquals(4, u.getMean()[0], 1E-14);
    Assert.assertEquals(6, u.getMean()[1], 1E-14);
    u.clear();
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    Assert.assertEquals(4, u.getMean()[0], 1E-14);
    Assert.assertEquals(6, u.getMean()[1], 1E-14);
    u.clear();
    u.setMeanImpl(new StorelessUnivariateStatistic[] {
                    new Mean(), new Mean()
                  }); // OK after clear
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    Assert.assertEquals(2, u.getMean()[0], 1E-14);
    Assert.assertEquals(3, u.getMean()[1], 1E-14);
    Assert.assertEquals(2, u.getDimension());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:MultivariateSummaryStatisticsTest.java

示例14: testInteraction

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
@Test
public void testInteraction() {

    FourthMoment m4 = new FourthMoment();
    Mean m = new Mean(m4);
    Variance v = new Variance(m4);
    Skewness s= new Skewness(m4);
    Kurtosis k = new Kurtosis(m4);

    for (int i = 0; i < testArray.length; i++){
        m4.increment(testArray[i]);
    }

    Assert.assertEquals(mean,m.getResult(),tolerance);
    Assert.assertEquals(var,v.getResult(),tolerance);
    Assert.assertEquals(skew ,s.getResult(),tolerance);
    Assert.assertEquals(kurt,k.getResult(),tolerance);

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:InteractionTest.java

示例15: testSetterInjection

import org.apache.commons.math.stat.descriptive.moment.Mean; //导入依赖的package包/类
@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
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:SummaryStatisticsTest.java


注:本文中的org.apache.commons.math.stat.descriptive.moment.Mean类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。