本文整理匯總了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();
}
示例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);
}
示例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;
}
示例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);
}
示例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 );
}
示例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, 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, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 6, 1, 0, 3, 1, 1, 3, 0, 2, 0, 1, 0, 0, 0, 2, 1, 4, 1, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 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 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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例11: agg
import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
@Override
public double agg(double[] data) {
return StatUtils.mean(data);
}
示例12: currentMean
import org.apache.commons.math3.stat.StatUtils; //導入方法依賴的package包/類
public double currentMean() {
return StatUtils.mean(values);
}
示例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;
}
}
示例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);
}
示例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;
}