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


Java StatUtils.variance方法代码示例

本文整理汇总了Java中org.apache.commons.math3.stat.StatUtils.variance方法的典型用法代码示例。如果您正苦于以下问题:Java StatUtils.variance方法的具体用法?Java StatUtils.variance怎么用?Java StatUtils.variance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.stat.StatUtils的用法示例。


在下文中一共展示了StatUtils.variance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testVarianceDecompMeanCutoff

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
/**
 * Check that the lower + upper semivariance against the mean sum to the
 * variance.
 */
@Test
public void testVarianceDecompMeanCutoff() {
    double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d };
    double variance = StatUtils.variance(values);
    SemiVariance sv = new SemiVariance(true); // Bias corrected
    sv.setVarianceDirection(SemiVariance.DOWNSIDE_VARIANCE);
    final double lower = sv.evaluate(values);
    sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE);
    final double upper = sv.evaluate(values);
    Assert.assertEquals(variance, lower + upper, 10e-12);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:16,代码来源:SemiVarianceTest.java

示例2: DefaultFTest

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
DefaultFTest(final double[] sample1, final double[] sample2) {
    final double variance1 = StatUtils.variance(sample1);
    final double variance2 = StatUtils.variance(sample2);

    this.numeratorDegreesOfFreedom = sample1.length - 1;
    this.denominatorDegreesOfFreedom = sample2.length - 1;
    final FDistribution fDistribution = new FDistribution(numeratorDegreesOfFreedom, denominatorDegreesOfFreedom);
    this.ratio = variance2 / variance1;
    this.p = 2 * (1 - fDistribution.probability(ratio));
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:11,代码来源:DefaultFTest.java

示例3: calculateStats

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
/**
 * 
 * @param dataActiveMap
 * @param sample
 */
public void calculateStats ( boolean[] dataActiveMap, double[] sample ) {
    ArrayList<Double> liveSample = new ArrayList<>();
    sampleMean = 0.0;

    if ( sample.length > 0 ) {

        for (int i = 0; i < sample.length; i ++) {
            if ( dataActiveMap[i] ) {
                sampleMean += sample[i];
                liveSample.add( sample[i] );
            }
        }

        sampleMean /= liveSample.size();
    }
    
    double[] liveSampleArray = new double[liveSample.size()];
    for (int i = 0; i < liveSampleArray.length; i ++){
        liveSampleArray[i] = (double)liveSample.get( i );
    }
    
           
    sampleMean = StatUtils.mean( liveSampleArray );
    variance = StatUtils.variance( liveSampleArray );

    stdErrSampleMean = Math.sqrt(variance) / Math.sqrt( liveSampleArray.length );

}
 
开发者ID:CIRDLES,项目名称:ET_Redux,代码行数:34,代码来源:NonParametricStats.java

示例4: testSmooth

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
@Test
public void testSmooth() throws Exception {
    final double[] arr = new double[] {0, 1, 3, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 4, 1, 0, 0, 1, 0, 0, 1, 0, 0, 2, 1, 0, 0, 1, 2, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 2, 1, 1, 0, 0, 0, 0, 0, 1, 1, 2, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 2, 0, 0, 1, 3, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 1, 1, 1, 0, 0, 2, 2, 3, 0, 2, 0, 0, 1, 0,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, 4, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1, 2, 1, 1, 1, 0, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 2, 1, 0, 0, 0, 0, 2, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 2, 1, 1, 2, 3, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 2, 2, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1};
    final double[] t = Doubles.constantArray(arr.length, 1.0);
    final double largeT = 10.0;

    final double mean = StatUtils.mean(arr);
    final double var = StatUtils.variance(arr);
    final double mom_alpha = (mean * mean) / (var - mean),
                 mom_beta = mean / (var - mean);

    final double[] result = TLambdaPoissonSmoother.estimateAlphaBeta(arr, t).getPointRef();
    final double[] resultBl = TLambdaPoissonSmoother.estimateAlphaBeta(arr, Doubles.constantArray(t.length, largeT)).getPointRef();

    // Larger branch length just changes Beta
    Assert.assertEquals(result[0], resultBl[0], 1e-2);
    Assert.assertEquals(result[1], resultBl[1] / largeT, 1e-2);

    // Actual results are close to MOM result
    Assert.assertEquals(mom_alpha, result[0], TOL);
    Assert.assertEquals(mom_beta, result[1], TOL);

    final double[] tlSmoothed = TLambdaPoissonSmoother.smooth(arr, t);
    final double[] tlSmoothedBl = TLambdaPoissonSmoother.smooth(arr, Doubles.constantArray(t.length, largeT));
    Assert.assertArrayEquals(tlSmoothed, Doubles.scalarMultiply(tlSmoothedBl, largeT), 1e2);
    final double[] origSmoothed = EmpiricalBayesPoissonSmoother.smooth(arr);

    // this is a pretty loose tolerance...
    Assert.assertArrayEquals(origSmoothed, tlSmoothed, 0.1);
}
 
开发者ID:cmccoy,项目名称:startreerenaissance,代码行数:31,代码来源:TLambdaPoissonSmootherTestCase.java

示例5: variance

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
/**
 * 
 * @return 
 */
public synchronized double variance() 
{
    if(this.variance == 0.0 && (this.nextSample == this.nrSamples))
        this.variance = StatUtils.variance(this.timeRecords);
     return this.variance;
}
 
开发者ID:hailpam,项目名称:dobef,代码行数:11,代码来源:Probe.java

示例6: stdDeviation

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
/**
 * 
 * @return 
 */
public synchronized double stdDeviation() 
{
    if(this.variance == 0.0 && (this.nextSample == this.nrSamples))
        this.variance = StatUtils.variance(this.timeRecords);
    return Math.sqrt(this.variance);
}
 
开发者ID:hailpam,项目名称:dobef,代码行数:11,代码来源:Probe.java

示例7: calculateVariance

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
private double calculateVariance(double[] values, double average) {

		if (values == null || values.length == 0)
			return 0.0;

		double variance = StatUtils.variance(values, average);
		return variance;
	}
 
开发者ID:rwth-acis,项目名称:REST-OCD-Services,代码行数:9,代码来源:Evaluation.java

示例8: columnVariance

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
public static DoubleMatrix columnVariance(DoubleMatrix input)
{
	DoubleMatrix columnMeans = input.columnMeans();
	DoubleMatrix ret = new DoubleMatrix(1, columnMeans.columns);
	for (int i = 0; i < ret.columns; i++)
	{
		DoubleMatrix column = input.getColumn(i);
		double variance = StatUtils.variance(column.toArray(), columnMeans.get(i));
		if (variance == 0)
			variance = 1e-6;
		ret.put(i, variance);
	}
	return ret;
}
 
开发者ID:liulhdarks,项目名称:darks-learning,代码行数:15,代码来源:MatrixHelper.java

示例9: agg

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
@Override
public double agg(double[] data) {
    return StatUtils.variance(data);
}
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:5,代码来源:AggregateFunctions.java

示例10: estimateAlphaBeta

import org.apache.commons.math3.stat.StatUtils; //导入方法依赖的package包/类
/**
     * Estimate alpha, beta given c, t
     *
     * @param c Counts
     * @param t Branch lengths
     * @return Point, containing (alpha, beta), and associated log-likelihood
     */
    @VisibleForTesting
    static PointValuePair estimateAlphaBeta(final double[] c, final double[] t) {
        // Optimize. point[0] = alpha, point[1] = beta
        final int dim = 2;
        BOBYQAOptimizer optimizer = new BOBYQAOptimizer(2 * dim + ADDL_INTERPOLATION_PTS);

        final MultivariateFunction fn = new MultivariateFunction() {
            @Override
            public double value(double[] point) {
                Preconditions.checkArgument(point.length == 2,
                        "Invalid data size: %s", point.length);
                return logLikelihood(point[0], point[1], c, t);
            }
        };

        // Start with method-of-moments
        final double mean = StatUtils.mean(c),
                var = StatUtils.variance(c);

        double mom_alpha, mom_beta;
        if (var > mean) {
            mom_alpha = (mean * mean) / (var - mean);
            mom_beta = mean / (var - mean);
        } else {
            mom_alpha = 1;
            mom_beta = 1;
        }

        // Bounds - both must be positive
        final double lowerBounds[] = new double[]{1e-7, 1e-7};
        final double upperBounds[] = new double[]{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY};
        final double initial[] = new double[]{mom_alpha, mom_beta};
        try {
            PointValuePair result = optimizer.optimize(
                    new MaxEval(2000),
                    new InitialGuess(initial),
                    GoalType.MAXIMIZE,
                    new ObjectiveFunction(fn),
                    new SimpleBounds(lowerBounds, upperBounds));
            logger.log(Level.FINE, "BOBYQA finished in {0} iterations", optimizer.getIterations());
            return result;
        } catch (Exception e) {
//            logger.log(Level.SEVERE,
//                    "Optimization failed [mom_alpha: {0}, mom_beta: {1}]\nc={2}\nt={3}",
//                    new Object[]{mom_alpha, mom_beta,
//                            java.util.Arrays.toString(c),
//                            java.util.Arrays.toString(t)});
            throw e;
        }
    }
 
开发者ID:cmccoy,项目名称:startreerenaissance,代码行数:58,代码来源:TLambdaPoissonSmoother.java


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