當前位置: 首頁>>代碼示例>>Java>>正文


Java StatUtils.mean方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.stat.StatUtils.mean方法的典型用法代碼示例。如果您正苦於以下問題:Java StatUtils.mean方法的具體用法?Java StatUtils.mean怎麽用?Java StatUtils.mean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.stat.StatUtils的用法示例。


在下文中一共展示了StatUtils.mean方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
@Override
public Solutions<V> execute() {
    int nextPercentageReport = 10;
    while ((currentGeneration < maxGenerations) && !stop) {
        step();
        int percentage = Math.round((currentGeneration * 100) / maxGenerations);
        if (percentage == nextPercentageReport) {
            double[][] objs = new double[problem.getNumberOfObjectives()][population.size()];
            String logStr = "";
            for (int i=0; i<objs.length; i++) {
                for (int j=0; j<objs[0].length; j++) {
                    objs[i][j] = population.get(j).getObjective(i);
                }
                logStr += " - Obj. "+i+": Max. "+StatUtils.max(objs[i])+"; Avg. "+StatUtils.mean(objs[i])+"; Min. "+StatUtils.min(objs[i]);
            }
            logger.info(percentage + "% performed ... "+logStr);
            nextPercentageReport += 10;
        }

    }
    return this.getCurrentSolution();       
}
 
開發者ID:hecoding,項目名稱:Pac-Man,代碼行數:23,代碼來源:MultiObjectiveMemeticAlgorithm.java

示例2: testSample

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
@Test
public void testSample() {
    final double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d };
    final int length = values.length;
    final double mean = StatUtils.mean(values); // 6.333...
    final SemiVariance sv = new SemiVariance();  // Default bias correction is true
    final double downsideSemiVariance = sv.evaluate(values); // Downside is the default
    Assert.assertEquals(TestUtils.sumSquareDev(new double[] {-2d, 2d, 4d, -2d, 3d, 5d}, mean) / (length - 1),
            downsideSemiVariance, 1E-14);

    sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE);
    final double upsideSemiVariance = sv.evaluate(values);
    Assert.assertEquals(TestUtils.sumSquareDev(new double[] {22d, 11d, 14d}, mean) / (length - 1),
            upsideSemiVariance, 1E-14);

    // Verify that upper + lower semivariance against the mean sum to variance
    Assert.assertEquals(StatUtils.variance(values), downsideSemiVariance + upsideSemiVariance, 10e-12);
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:19,代碼來源:SemiVarianceTest.java

示例3: getCalls

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
private Sig getCalls(List<double[]> bm, List<double[]> up) {
    double[] tlr1 = new double[bm.size()];
    double[] ti1 = new double[bm.size()];
    double[] tlr2 = new double[up.size()];
    double[] ti2 = new double[up.size()];
    int i = 0;
    for (double[] b : bm) {
        tlr1[i] = b[1];
        ti1[i] = b[2];
        i++;
    }
    i = 0;
    for (double[] u : up) {
        tlr2[i] = u[1];
        ti2[i] = u[2];
        i++;
    }
    i = 0;
    String cn;
    String ti;
    int segs;
    double mean;
    double mean1 = StatUtils.mean(tlr1);
    double mean2 = StatUtils.mean(tlr2);
    if (Math.abs(mean1) > Math.abs(mean2)) {
        cn = mean1 < -0.35 ? "Del" : (Double.compare(mean1, 0.35) > 0 ? "Amp" : "NA");
        segs = tlr1.length;
        mean = mean1;
        ti = joinDouble(ti1, ",");
    } else {
        cn = mean2 < -0.35 ? "Del" : (Double.compare(mean2, 0.35) > 0 ? "Amp" : "NA");
        segs = tlr2.length;
        mean = mean2;
        ti = joinDouble(ti2, ",");
    }
    Sig sig = new Sig(0.0, 0.0, segs, "BP", mean, cn, bm.size() + up.size(), 0.0, ti, 0.0);
    return sig;

}
 
開發者ID:AstraZeneca-NGS,項目名稱:Seq2CJava,代碼行數:40,代碼來源:Lr2gene.java

示例4: computeFlux

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
private double computeFlux(int x, int y, GridValueLayer gvl, Grid<?> grid) {
	
	Set<GridPoint> neigh = NeighbourhoodFunctions.getVonNeumanPoints(new GridPoint(x,y), grid, 1);
	double[] values = new double[neigh.size()];
	
	int i=0;
	for(GridPoint gp: neigh) {
		values[i++] = gvl.get(gp.getX(),gp.getY());
	}
	
	return StatUtils.mean(values);
}
 
開發者ID:dkremmydas,項目名稱:SugarScape2,代碼行數:13,代碼來源:PollutionDiffusionRule_p50.java

示例5: 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

示例6: 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, 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 0, 1, 0, 0, 2, 0, 1, 1, 0, 0, 0, 3, 0, 2, 2, 1, 0, 0, 0, 1, 0, 2, 0, 0, 0, 2, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 2, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 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

示例7: mean

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
/**
 * 
 * @return 
 */
public synchronized double mean() 
{
    if(this.mean == 0.0 && (this.nextSample == this.nrSamples)) {
        this.mean = StatUtils.mean(this.timeRecords);
        return this.mean;
    }else 
        return this.max;
}
 
開發者ID:hailpam,項目名稱:dobef,代碼行數:13,代碼來源:Probe.java

示例8: mean

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
static float mean(List<? extends Number> values) {
    double[] dValues = values.stream().mapToDouble(v -> v.floatValue()).toArray();
    return (float) StatUtils.mean(dValues);
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:5,代碼來源:Metric.java

示例9: execute

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
@Override
public Solutions<V> execute() {
    logger.fine("@ # Gen.;Min Fit.;Max Fit.;Med Fit.");

    int nextPercentageReport = 10;
    HashMap<String,String> obsData = new HashMap<>();
    // For observers:
    obsData.put("MaxGenerations", String.valueOf(maxGenerations));
    stop = false;
    while ((currentGeneration < maxGenerations) && !stop){
        step();
        int percentage = Math.round((currentGeneration * 100) / maxGenerations);
        Double bestObj = leaders.get(0).getObjectives().get(0);
        
        // For observers:
        obsData.put("CurrentGeneration", String.valueOf(currentGeneration));
        obsData.put("BestObjective", String.valueOf(bestObj));
        this.setChanged();
        this.notifyObservers(obsData);
        
        if (percentage == nextPercentageReport) {
            // Compute more stats:
            fitnessValues = new double[population.size()];
            for (int i = 0; i < fitnessValues.length; i++) {
                fitnessValues[i] = population.get(i).getObjective(0);
            }
            double avg = StatUtils.mean(fitnessValues);
            double stdDev = Math.sqrt(StatUtils.variance(fitnessValues));
            logger.info(percentage + "% performed ..." + " -- Fitness info -->> Best: " + bestObj + " -->> Avg.: " + avg + " -->> Std. Dev.: " + stdDev );
            nextPercentageReport += 10;
        }
        if (stopWhenSolved) {
            if (bestObj <= 0) {
                logger.info("Optimal solution found in " + currentGeneration + " generations.");
                break;
            }
        }
    }
    if (stop) {
        logger.info("Execution stopped at generation "+ currentGeneration);
        logger.info("Best objective value: "+leaders.get(0).getObjectives().get(0));
    }
    
    return leaders;
}
 
開發者ID:hecoding,項目名稱:Pac-Man,代碼行數:46,代碼來源:SimpleGeneticAlgorithm.java

示例10: sharpe

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
public static double sharpe(double[] dailyReturns) {
    return StatUtils.mean(dailyReturns) / Math.sqrt(StatUtils.variance(dailyReturns)) * Math.sqrt(250);
}
 
開發者ID:lukstei,項目名稱:trading-backtest,代碼行數:4,代碼來源:Statistics.java

示例11: agg

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
@Override
public double agg(double[] data) {
    return StatUtils.mean(data);
}
 
開發者ID:jtablesaw,項目名稱:tablesaw,代碼行數:5,代碼來源:AggregateFunctions.java

示例12: currentMean

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
public double currentMean() {
    return StatUtils.mean(values);
}
 
開發者ID:FastAndFurious,項目名稱:fnf.clientapi,代碼行數:4,代碼來源:FloatingHistory.java

示例13: 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

示例14: getAverage

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
protected double getAverage(List<Double> list, int rounds) {
	
	double[] values = getArray(list, rounds);
	return StatUtils.mean(values);	
}
 
開發者ID:rwth-acis,項目名稱:REST-OCD-Services,代碼行數:6,代碼來源:DataRecorder.java

示例15: calculateAverageValue

import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
private double calculateAverageValue(double[] values) {

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

		double average = StatUtils.mean(values);
		return average;

	}
 
開發者ID:rwth-acis,項目名稱:REST-OCD-Services,代碼行數:10,代碼來源:Evaluation.java


注:本文中的org.apache.commons.math3.stat.StatUtils.mean方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。