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


Java Mean類代碼示例

本文整理匯總了Java中org.apache.commons.math3.stat.descriptive.moment.Mean的典型用法代碼示例。如果您正苦於以下問題:Java Mean類的具體用法?Java Mean怎麽用?Java Mean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Mean類屬於org.apache.commons.math3.stat.descriptive.moment包,在下文中一共展示了Mean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compare

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
@Override
public int compare(ClusterModelStats stats1, ClusterModelStats stats2) {
  double[] stat1 = stats1.utilizationMatrix()[RawAndDerivedResource.LEADER_NW_IN.ordinal()];
  double meanPreLeaderBytesIn = new Mean().evaluate(stat1, 0, stat1.length);
  double threshold = meanPreLeaderBytesIn * _balancingConstraint.balancePercentage(Resource.NW_IN);
  if (Arrays.stream(stat1).noneMatch(v -> v > threshold)) {
    return 1;
  }

  double[] stat2 = stats2.utilizationMatrix()[RawAndDerivedResource.LEADER_NW_IN.ordinal()];
  double variance1 = new Variance().evaluate(stat1);
  double variance2 = new Variance().evaluate(stat2);
  int result = AnalyzerUtils.compare(Math.sqrt(variance2), Math.sqrt(variance1), Resource.NW_IN);
  if (result < 0) {
    _reasonForLastNegativeResult = String.format("Violated leader bytes in balancing. preVariance: %.3f "
                                                     + "postVariance: %.3f.", variance2, variance1);
  }
  return result;
}
 
開發者ID:linkedin,項目名稱:cruise-control,代碼行數:20,代碼來源:LeaderBytesInDistributionGoal.java

示例2: initialize

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
public void initialize() {
    aggregatorSubjectType = SubjectTypeUtils.getSubjectTypeByProviderAndLabel(subject.getProvider(), subject.getSubjectType());

    // Initialise aggregators
    aggregators = new HashMap<>();
    aggregators.put(AggregationFunction.sum, new Sum());
    aggregators.put(AggregationFunction.mean, new Mean());

    try {
        this.aggregator = aggregators.get(this.function);
        this.singleValueField = (SingleValueField) field.toField();
        singleValueField.setFieldCache(fieldCache);
    } catch (Exception e) {
        throw new Error("Field not valid", e);
    }
}
 
開發者ID:FutureCitiesCatapult,項目名稱:TomboloDigitalConnector,代碼行數:17,代碼來源:GeographicAggregationField.java

示例3: runPredictions

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
/**
 * Sagt anhand des Predictors zukünftige Werte der Zeitreihe voraus.
 *
 * @param timeSeries   Die betrachtete Zeitreihe.
 * @param coefficients Die Koeffizeinten der AR-Modellgleichung.
 * @param numPeriods   Die Anzahl an zukünftigen Zeitpunkten, die prognostiziert werden.
 * @return Die prognostizierten Werte der Zeitreihe.
 */
public double[] runPredictions(final double[] timeSeries, final double[] coefficients, final int numPeriods) {
    final double[] result = new double[numPeriods];

    final double avg = new Mean().evaluate(timeSeries);

    // Erzeugt einen SlidingWindow mit den zentrierten Werten der Zeitreihe
    // lastValues enthält immer die Werte, die für die nächste Prognose wichtig sind
    final SlidingWindow lastValues = fillSlidingWindowFromTimeSeries(timeSeries, coefficients.length);

    for (int i = 0; i < numPeriods; i++) {
        result[i] = predictor.predict(lastValues.getData(), coefficients, avg);
        lastValues.put(result[i]);
    }

    return result;
}
 
開發者ID:DHBW-Karlsruhe,項目名稱:businesshorizon2,代碼行數:25,代碼來源:ARPredictorRunner.java

示例4: MultivariateSummaryStatistics

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
/**
 * Construct a MultivariateSummaryStatistics instance
 * @param k dimension of the data
 * @param isCovarianceBiasCorrected if true, the unbiased sample
 * covariance is computed, otherwise the biased population covariance
 * is computed
 */
public MultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
    this.k = k;

    sumImpl     = new StorelessUnivariateStatistic[k];
    sumSqImpl   = new StorelessUnivariateStatistic[k];
    minImpl     = new StorelessUnivariateStatistic[k];
    maxImpl     = new StorelessUnivariateStatistic[k];
    sumLogImpl  = new StorelessUnivariateStatistic[k];
    geoMeanImpl = new StorelessUnivariateStatistic[k];
    meanImpl    = new StorelessUnivariateStatistic[k];

    for (int i = 0; i < k; ++i) {
        sumImpl[i]     = new Sum();
        sumSqImpl[i]   = new SumOfSquares();
        minImpl[i]     = new Min();
        maxImpl[i]     = new Max();
        sumLogImpl[i]  = new SumOfLogs();
        geoMeanImpl[i] = new GeometricMean();
        meanImpl[i]    = new Mean();
    }

    covarianceImpl =
        new VectorialCovariance(k, isCovarianceBiasCorrected);

}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:33,代碼來源:MultivariateSummaryStatistics.java

示例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  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;
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:35,代碼來源:Covariance.java

示例6: testSetterInjection

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
@Test
public void testSetterInjection() {
    SummaryStatistics u = createSummaryStatistics();
    u.setMeanImpl(new Sum());
    u.setSumLogImpl(new Sum());
    u.addValue(1);
    u.addValue(3);
    Assert.assertEquals(4, u.getMean(), 1E-14);
    Assert.assertEquals(4, u.getSumOfLogs(), 1E-14);
    Assert.assertEquals(FastMath.exp(2), u.getGeometricMean(), 1E-14);
    u.clear();
    u.addValue(1);
    u.addValue(2);
    Assert.assertEquals(3, u.getMean(), 1E-14);
    u.clear();
    u.setMeanImpl(new Mean()); // OK after clear
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:18,代碼來源:SummaryStatisticsTest.java

示例7: testSetterInjection

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
@Test
public void testSetterInjection() {
    MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(2, true);
    u.setMeanImpl(new StorelessUnivariateStatistic[] {
                    new sumMean(), new sumMean()
                  });
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    Assert.assertEquals(4, u.getMean()[0], 1E-14);
    Assert.assertEquals(6, u.getMean()[1], 1E-14);
    u.clear();
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    Assert.assertEquals(4, u.getMean()[0], 1E-14);
    Assert.assertEquals(6, u.getMean()[1], 1E-14);
    u.clear();
    u.setMeanImpl(new StorelessUnivariateStatistic[] {
                    new Mean(), new Mean()
                  }); // OK after clear
    u.addValue(new double[] { 1, 2 });
    u.addValue(new double[] { 3, 4 });
    Assert.assertEquals(2, u.getMean()[0], 1E-14);
    Assert.assertEquals(3, u.getMean()[1], 1E-14);
    Assert.assertEquals(2, u.getDimension());
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:26,代碼來源:MultivariateSummaryStatisticsTest.java

示例8: calculateParamMean

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
/**
 * @param numberOfUtterances number of utterances
 * @param fileNumber file number
 * @param audioParams audio parameters
 * @param meanParam old mean value of audio parameter
 * @return meanParam new mean value of audio parameter
 */
private static double[][] calculateParamMean( int numberOfUtterances, int fileNumber, String[][] audioParams, double[][] meanParam) {

	for	(int cols=0; cols<HEADER_COLUMNS; cols++)	{
		meanParam[fileNumber][cols] = 0;
	}
	
	for	(int cols=HEADER_COLUMNS; cols<PARAMS_NUM; cols++)	{
		double[] colValues = new double[numberOfUtterances];	
		for	(int rows =0; rows< numberOfUtterances; rows++)	{
			if	(!audioParams[rows][cols].equals(""))	{
				colValues[rows] = Double.parseDouble(audioParams[rows][cols].replace("%",""));
			}
			else
				colValues[rows] = 0;
		}
		meanParam[fileNumber][cols] = new Mean().evaluate(colValues);
	}
	return meanParam;
	
}
 
開發者ID:UKPLab,項目名稱:jlcl2015-pythagoras,代碼行數:28,代碼來源:FindOutliers.java

示例9: 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;
}
 
開發者ID:jiach,項目名稱:MetaDiff,代碼行數:26,代碼來源:ArrFPKM.java

示例10: calculateT

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
private static double calculateT(final ReadCountCollection tangentNormalizedCoverage, final List<ModeledSegment> segments) {

        //Get the segments that are likely copy neutral.
        // Math.abs removed to mimic python...
        final List<ModeledSegment> copyNeutralSegments = segments.stream().filter(s -> s.getSegmentMean() < COPY_NEUTRAL_CUTOFF).collect(Collectors.toList());

        // Get the targets that correspond to the copyNeutralSegments... note that individual targets, due to noise,
        //  can be far away from copy neutral
        final TargetCollection<ReadCountRecord.SingleSampleRecord> targetsWithCoverage =
                new HashedListTargetCollection<>(tangentNormalizedCoverage.records().stream().map(ReadCountRecord::asSingleSampleRecord).collect(Collectors.toList()));
        final double[] copyNeutralTargetsCopyRatio = copyNeutralSegments.stream()
                .flatMap(s -> targetsWithCoverage.targets(s).stream())
                .mapToDouble(ReadCountRecord.SingleSampleRecord::getCount).toArray();

        final double meanCopyNeutralTargets = new Mean().evaluate(copyNeutralTargetsCopyRatio);
        final double sigmaCopyNeutralTargets = new StandardDeviation().evaluate(copyNeutralTargetsCopyRatio);

        // Now we filter outliers by only including those w/in 2 standard deviations.
        final double [] filteredCopyNeutralTargetsCopyRatio = Arrays.stream(copyNeutralTargetsCopyRatio)
                .filter(c -> Math.abs(c - meanCopyNeutralTargets) < sigmaCopyNeutralTargets * Z_THRESHOLD).toArray();

        return new StandardDeviation().evaluate(filteredCopyNeutralTargetsCopyRatio);
    }
 
開發者ID:broadinstitute,項目名稱:gatk-protected,代碼行數:24,代碼來源:ReCapSegCaller.java

示例11: testSliceSamplingOfNormalDistribution

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
/**
 * Test slice sampling of a normal distribution.  Checks that input mean and standard deviation are recovered
 * by 10000 samples to a relative error of 0.5% and 2%, respectively.
 */
@Test
public void testSliceSamplingOfNormalDistribution() {
    rng.setSeed(RANDOM_SEED);

    final double mean = 5.;
    final double standardDeviation = 0.75;
    final NormalDistribution normalDistribution = new NormalDistribution(mean, standardDeviation);
    final Function<Double, Double> normalLogPDF = normalDistribution::logDensity;

    final double xInitial = 1.;
    final double xMin = Double.NEGATIVE_INFINITY;
    final double xMax = Double.POSITIVE_INFINITY;
    final double width = 0.5;
    final int numSamples = 10000;
    final SliceSampler normalSampler = new SliceSampler(rng, normalLogPDF, xMin, xMax, width);
    final double[] samples = Doubles.toArray(normalSampler.sample(xInitial, numSamples));

    final double sampleMean = new Mean().evaluate(samples);
    final double sampleStandardDeviation = new StandardDeviation().evaluate(samples);
    Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005);
    Assert.assertEquals(relativeError(sampleStandardDeviation, standardDeviation), 0., 0.02);
}
 
開發者ID:broadinstitute,項目名稱:gatk-protected,代碼行數:27,代碼來源:SliceSamplerUnitTest.java

示例12: testSliceSamplingOfMonotonicBetaDistribution

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
/**
 * Test slice sampling of a monotonic beta distribution as an example of sampling of a bounded random variable.
 * Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%,
 * respectively.
 */
@Test
public void testSliceSamplingOfMonotonicBetaDistribution() {
    rng.setSeed(RANDOM_SEED);

    final double alpha = 10.;
    final double beta = 1.;
    final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta);
    final Function<Double, Double> betaLogPDF = betaDistribution::logDensity;

    final double xInitial = 0.5;
    final double xMin = 0.;
    final double xMax = 1.;
    final double width = 0.1;
    final int numSamples = 10000;
    final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width);
    final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples));

    final double mean = betaDistribution.getNumericalMean();
    final double variance = betaDistribution.getNumericalVariance();
    final double sampleMean = new Mean().evaluate(samples);
    final double sampleVariance = new Variance().evaluate(samples);
    Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005);
    Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02);
}
 
開發者ID:broadinstitute,項目名稱:gatk-protected,代碼行數:30,代碼來源:SliceSamplerUnitTest.java

示例13: testSliceSamplingOfPeakedBetaDistribution

import org.apache.commons.math3.stat.descriptive.moment.Mean; //導入依賴的package包/類
/**
 * Test slice sampling of a peaked beta distribution as an example of sampling of a bounded random variable.
 * Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%,
 * respectively.
 */
@Test
public void testSliceSamplingOfPeakedBetaDistribution() {
    rng.setSeed(RANDOM_SEED);

    final double alpha = 10.;
    final double beta = 4.;
    final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta);
    final Function<Double, Double> betaLogPDF = betaDistribution::logDensity;

    final double xInitial = 0.5;
    final double xMin = 0.;
    final double xMax = 1.;
    final double width = 0.1;
    final int numSamples = 10000;
    final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width);
    final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples));

    final double mean = betaDistribution.getNumericalMean();
    final double variance = betaDistribution.getNumericalVariance();
    final double sampleMean = new Mean().evaluate(samples);
    final double sampleVariance = new Variance().evaluate(samples);
    Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005);
    Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02);
}
 
開發者ID:broadinstitute,項目名稱:gatk-protected,代碼行數:30,代碼來源:SliceSamplerUnitTest.java

示例14: 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());
}
 
開發者ID:broadinstitute,項目名稱:gatk-protected,代碼行數:23,代碼來源:HDF5PCACoveragePoNCreationUtilsUnitTest.java

示例15: 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;

	 
}
 
開發者ID:thorstenwagner,項目名稱:TraJ,代碼行數:24,代碼來源:SplineCurveSpatialFeature.java


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