當前位置: 首頁>>代碼示例>>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, 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 0, 1, 1, 1, 1, 0, 0, 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;未經允許,請勿轉載。