本文整理匯總了Java中org.apache.commons.math3.stat.descriptive.moment.Mean.evaluate方法的典型用法代碼示例。如果您正苦於以下問題:Java Mean.evaluate方法的具體用法?Java Mean.evaluate怎麽用?Java Mean.evaluate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.stat.descriptive.moment.Mean
的用法示例。
在下文中一共展示了Mean.evaluate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: covariance
import org.apache.commons.math3.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 MathIllegalArgumentException if the arrays lengths do not match or
* there is insufficient data
*/
public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected)
throws MathIllegalArgumentException {
Mean mean = new Mean();
double result = 0d;
int length = xArray.length;
if (length != yArray.length) {
throw new MathIllegalArgumentException(
LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length);
} else if (length < 2) {
throw new MathIllegalArgumentException(
LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, 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;
}
示例2: get_cv
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
public Map<String, Double> get_cv(String[] group_var, String[] uniq_group){
Map<String, Double> group_to_cv_map = new TreeMap<String, Double>();
Map<String, ArrayList<Double> > grouped_y = new TreeMap<String, ArrayList<Double>>();
for (String aUniq_group : uniq_group){
grouped_y.put(aUniq_group, new ArrayList<Double>());
for (int i = 0; i < group_var.length; i++) {
if (group_var[i].equals(aUniq_group)){
grouped_y.get(aUniq_group).add(this.y_list.get(i));
}
}
}
StandardDeviation std_stat = new StandardDeviation(true);
Mean mean_stat = new Mean();
for(Iterator<Map.Entry<String, ArrayList<Double>>> it = grouped_y.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, ArrayList<Double>> entry = it.next();
double[] cur_y_arr = ArrayUtils.toPrimitive(entry.getValue().toArray(new Double[entry.getValue().size()]));
double std = std_stat.evaluate(cur_y_arr);
double mean = mean_stat.evaluate(cur_y_arr);
group_to_cv_map.put(entry.getKey(), std/mean);
}
this.cv = group_to_cv_map;
return group_to_cv_map;
}
示例3: testCalculateReducedPanelAndPInversesUsingJollifesRule
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
@Test(dataProvider = "readCountOnlyWithDiverseShapeData")
public void testCalculateReducedPanelAndPInversesUsingJollifesRule(final ReadCountCollection readCounts) {
final JavaSparkContext ctx = SparkContextFactory.getTestSparkContext();
final ReductionResult result = HDF5PCACoveragePoNCreationUtils.calculateReducedPanelAndPInverses(readCounts, OptionalInt.empty(), NULL_LOGGER, ctx);
final RealMatrix counts = readCounts.counts();
Assert.assertNotNull(result);
Assert.assertNotNull(result.getPseudoInverse());
Assert.assertNotNull(result.getReducedCounts());
Assert.assertNotNull(result.getReducedPseudoInverse());
Assert.assertNotNull(result.getAllSingularValues());
Assert.assertEquals(counts.getColumnDimension(), result.getAllSingularValues().length);
Assert.assertEquals(result.getReducedCounts().getRowDimension(), counts.getRowDimension());
final int eigensamples = result.getReducedCounts().getColumnDimension();
final Mean mean = new Mean();
final double meanSingularValue = mean.evaluate(result.getAllSingularValues());
final double threshold = HDF5PCACoveragePoNCreationUtils.JOLLIFES_RULE_MEAN_FACTOR * meanSingularValue;
final int expectedEigensamples = (int) DoubleStream.of(result.getAllSingularValues()).filter(d -> d >= threshold).count();
Assert.assertTrue(eigensamples <= counts.getColumnDimension());
Assert.assertEquals(eigensamples, expectedEigensamples);
assertPseudoInverse(counts, result.getPseudoInverse());
assertPseudoInverse(result.getReducedCounts(), result.getReducedPseudoInverse());
}
示例4: evaluate
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
@Override
/**
* @return [0] Mean distance [1] SD distance
*/
public double[] evaluate() {
splinefit = new TrajectorySplineFit(t,nSegments);
splinefit.calculateSpline();
if(!splinefit.wasSuccessfull()){
return new double[] {Double.NaN,Double.NaN};
}
double[] data = new double[t.size()];
for(int i = 0; i < t.size(); i++){
Point2D.Double help = new Point2D.Double(splinefit.getRotatedTrajectory().get(i).x, splinefit.getRotatedTrajectory().get(i).y);
data[i] = help.distance(splinefit.minDistancePointSpline(new Point2D.Double(splinefit.getRotatedTrajectory().get(i).x, splinefit.getRotatedTrajectory().get(i).y), 50));
}
Mean m = new Mean();
StandardDeviation sd = new StandardDeviation();
result = new double[] {m.evaluate(data),sd.evaluate(data)};
return result;
}
示例5: covariance
import org.apache.commons.math3.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 new MathIllegalArgumentException(
LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length);
} else if (length < 2) {
throw new MathIllegalArgumentException(
LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, 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;
}
示例6: usingApacheCommons
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
public void usingApacheCommons() {
// Using Apache Commons to find mean
Mean mean = new Mean();
double average = mean.evaluate(testData);
out.println("The mean is " + average);
DescriptiveStatistics statTest
= new SynchronizedDescriptiveStatistics();
for (double num : testData) {
statTest.addValue(num);
}
out.println("The mean is " + statTest.getMean());
}
開發者ID:PacktPublishing,項目名稱:Machine-Learning-End-to-Endguide-for-Java-developers,代碼行數:15,代碼來源:Main.java
示例7: calMean
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
private static double calMean(double[] values) {
List<Double> nonNa = new ArrayList<>();
for (int i = 0; i<values.length; i++) {
if (!Double.isNaN(values[i])) {
nonNa.add(values[i]);
}
}
int nonNaCount = nonNa.size();
double[] nonNaValues = Stream.of(nonNa.toArray(new Double[nonNaCount])).
mapToDouble(Double::doubleValue).toArray();
Mean mean = new Mean();
return mean.evaluate(nonNaValues,0,nonNaValues.length);
}
示例8: estBetaDist
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
public static double[] estBetaDist(double[] betaValues) {
Mean mean = new Mean();
double mu = mean.evaluate(betaValues,0,betaValues.length);
Variance variance = new Variance();
double var = variance.evaluate(betaValues, mu);
double alpha = -mu*(var+mu*mu-mu)/var;
double beta = (mu-1)*(var+mu*mu-mu)/var;
return new double[] {alpha, beta, mu, FastMath.sqrt(var)};
}
示例9: meanAbsoluteSteplength
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
public static double meanAbsoluteSteplength(Trajectory t){
double[] v = new double[t.size()-1];
for(int i = 1; i < t.size(); i++){
v[i-1] = Math.abs(t.get(i).distance(t.get(i-1)));
}
Mean m = new Mean();
return m.evaluate(v);
}
示例10: calculateNthMoment
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
public double calculateNthMoment(int n){
Array2DRowRealMatrix gyr = RadiusGyrationTensor2D.getRadiusOfGyrationTensor(t);
EigenDecomposition eigdec = new EigenDecomposition(gyr);
Vector2d eigv = new Vector2d(eigdec.getEigenvector(0).getEntry(0),eigdec.getEigenvector(0).getEntry(1));
double[] projected = new double[t.size()];
for(int i = 0; i < t.size(); i++){
Vector2d pos = new Vector2d(t.get(i).x,t.get(i).y);
double v = eigv.dot(pos);
projected[i] = v;
}
Mean m = new Mean();
StandardDeviation s = new StandardDeviation();
double mean = m.evaluate(projected);
double sd = s.evaluate(projected);
double sumPowN=0;
for(int i = 0; i < projected.length; i++){
sumPowN += Math.pow( (projected[i]-mean)/sd, n);
}
double nThMoment = sumPowN/projected.length;
return nThMoment;
}
示例11: getMeanRunTime
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
/**
* Returns the mean for the warmup time.
*
* @return the warmup time.
*/
public double getMeanRunTime() {
final Mean median = new Mean();
final double[] res = convertIntoArray(benchTimes);
return median.evaluate(res);
}
示例12: getMeanWarmupTime
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
/**
* Returns the mean for the bench time.
*
* @return the warmup time.
*/
public double getMeanWarmupTime() {
final Mean median = new Mean();
final double[] res = convertIntoArray(warmupTimes);
return median.evaluate(res);
}
示例13: getMean
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
/** Compute artihmetic mean of the samples.
*
* @return Arithmetic mean of the data in the original benchmark run.
*/
public synchronized double getMean() {
if (cacheMean == null) {
Mean mean = new Mean();
cacheMean = mean.evaluate(data);
}
return cacheMean;
}
示例14: stop
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
protected Result stop(boolean interarrival) {
double cpu = ((double)(mxbean.getCurrentThreadCpuTime()-cputime))/idx;
if (interarrival) {
for(int i = idx-1; i>0; i--)
times[i]-=times[i-1];
begin = 1;
}
Mean mean = new Mean();
double m = mean.evaluate(times, begin, idx-begin);
Variance var = new Variance();
double v = var.evaluate(times, m, begin, idx-begin);
return new Result(m, v, cpu);
}
示例15: calculate_average_of_array_apache
import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入方法依賴的package包/類
@Test
public void calculate_average_of_array_apache () {
Mean mean = new Mean();
double average = mean.evaluate(NUMBERS);
assertEquals(35.36363636363637, average, 0);
}