当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils类代码示例

本文整理汇总了Java中org.apache.commons.math.util.MathUtils的典型用法代码示例。如果您正苦于以下问题:Java MathUtils类的具体用法?Java MathUtils怎么用?Java MathUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MathUtils类属于org.apache.commons.math.util包,在下文中一共展示了MathUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printFeatureSet

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * Print the Nodes in a Feature set given its Level.
 * @param setLevel
 * @param feature 
 */
public void printFeatureSet(SetLevel setLevel, Feature feature) {
    System.out.println(setLevel + " " + feature +
            " (" +
            "MIN " + feature + ": " +
            MathUtils.round(getFeatureSetMin(setLevel, feature), 2) +
            ", MAX " + feature + ": " +
            MathUtils.round(getFeatureSetMax(setLevel, feature), 2) +
            ", MEAN " + feature + ": " +
            MathUtils.round(getFeatureSetMean(setLevel, feature), 2) +
            ", MIN PRS: " +
            MathUtils.round(getFeatureSetMinPageRankScore(setLevel, feature), 2) +
            ", MAX PRS: " +
            MathUtils.round(getFeatureSetMaxPageRankScore(setLevel, feature), 2) +
            ", MEAN PRS: " +
            MathUtils.round(getFeatureSetMeanPageRankScore(setLevel, feature), 2) +
            ")");
    for (Node Node : getFeatureSet(setLevel, feature)) {
        System.out.println(Node.toString());
    }
    System.out.println();
}
 
开发者ID:gfigueroa,项目名称:clusterrank-graph-clustering,代码行数:27,代码来源:ClusterRankGraph.java

示例2: generate

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public GaussianQuadratureData generate(final int n) {
  Validate.isTrue(n > 0, "n > 0");
  final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = JACOBI.getPolynomialsAndFirstDerivative(n, _alpha, _beta);
  final Pair<DoubleFunction1D, DoubleFunction1D> pair = polynomials[n];
  final DoubleFunction1D previous = polynomials[n - 1].getFirst();
  final DoubleFunction1D function = pair.getFirst();
  final DoubleFunction1D derivative = pair.getSecond();
  final double[] x = new double[n];
  final double[] w = new double[n];
  double root = 0;
  for (int i = 0; i < n; i++) {
    final double d = 2 * n + _c;
    root = getInitialRootGuess(root, i, n, x);
    root = ROOT_FINDER.getRoot(function, derivative, root);
    x[i] = root;
    w[i] = GAMMA_FUNCTION.evaluate(_alpha + n) * GAMMA_FUNCTION.evaluate(_beta + n) / MathUtils.factorialDouble(n) / GAMMA_FUNCTION.evaluate(n + _c + 1) * d * Math.pow(2, _c)
        / (derivative.evaluate(root) * previous.evaluate(root));
  }
  return new GaussianQuadratureData(x, w);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:25,代码来源:GaussJacobiWeightAndAbscissaFunction.java

示例3: generate

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public GaussianQuadratureData generate(final int n) {
  Validate.isTrue(n > 0);
  final Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = LAGUERRE.getPolynomialsAndFirstDerivative(n, _alpha);
  final Pair<DoubleFunction1D, DoubleFunction1D> pair = polynomials[n];
  final DoubleFunction1D p1 = polynomials[n - 1].getFirst();
  final DoubleFunction1D function = pair.getFirst();
  final DoubleFunction1D derivative = pair.getSecond();
  final double[] x = new double[n];
  final double[] w = new double[n];
  double root = 0;
  for (int i = 0; i < n; i++) {
    root = ROOT_FINDER.getRoot(function, derivative, getInitialRootGuess(root, i, n, x));
    x[i] = root;
    w[i] = -GAMMA_FUNCTION.evaluate(_alpha + n) / MathUtils.factorialDouble(n) / (derivative.evaluate(root) * p1.evaluate(root));
  }
  return new GaussianQuadratureData(x, w);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:GaussLaguerreWeightAndAbscissaFunction.java

示例4: getMultiplier

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
public static double getMultiplier(final Underlying underlying) {
  Validate.notNull(underlying, "underlying");
  if (underlying instanceof NthOrderUnderlying) {
    final NthOrderUnderlying nthOrder = (NthOrderUnderlying) underlying;
    final int n = nthOrder.getOrder();
    if (n == 0) {
      return 1;
    }
    return 1. / MathUtils.factorial(n);
  } else if (underlying instanceof MixedOrderUnderlying) {
    final MixedOrderUnderlying mixedOrder = (MixedOrderUnderlying) underlying;
    double result = 1;
    for (final NthOrderUnderlying underlyingOrder : mixedOrder.getUnderlyingOrders()) {
      result *= getMultiplier(underlyingOrder);
    }
    return result;
  }
  throw new IllegalArgumentException("Order was neither NthOrderUnderlying nor MixedOrderUnderlying: have " + underlying.getClass());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:20,代码来源:TaylorExpansionMultiplierCalculator.java

示例5: equals

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * Returns true iff <code>object</code> is a 
 * <code>StatisticalSummaryValues</code> instance and all statistics have
 *  the same values as this.
 * 
 * @param object the object to test equality against.
 * @return true if object equals this
 */
public boolean equals(Object object) {
    if (object == this ) {
        return true;
    }
    if (object instanceof StatisticalSummaryValues == false) {
        return false;
    }
    StatisticalSummaryValues stat = (StatisticalSummaryValues) object;
    return (MathUtils.equals(stat.getMax(), this.getMax()) && 
            MathUtils.equals(stat.getMean(),this.getMean()) &&
            MathUtils.equals(stat.getMin(),this.getMin()) &&
            MathUtils.equals(stat.getN(), this.getN()) &&
            MathUtils.equals(stat.getSum(), this.getSum()) &&
            MathUtils.equals(stat.getVariance(),this.getVariance()));
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:StatisticalSummaryValues.java

示例6: equals

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * Returns true iff <code>object</code> is a <code>SummaryStatistics</code>
 * instance and all statistics have the same values as this.
 * @param object the object to test equality against.
 * @return true if object equals this
 */
public boolean equals(Object object) {
    if (object == this ) {
        return true;
    }
    if (object instanceof SummaryStatistics == false) {
        return false;
    }
    SummaryStatistics stat = (SummaryStatistics) object;
    return (MathUtils.equals(stat.getGeometricMean(), 
            this.getGeometricMean()) &&
            MathUtils.equals(stat.getMax(), this.getMax()) && 
            MathUtils.equals(stat.getMean(),this.getMean()) &&
            MathUtils.equals(stat.getMin(),this.getMin()) &&
            MathUtils.equals(stat.getN(), this.getN()) &&
            MathUtils.equals(stat.getSum(), this.getSum()) &&
            MathUtils.equals(stat.getSumsq(),this.getSumsq()) &&
            MathUtils.equals(stat.getVariance(),this.getVariance()));
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:25,代码来源:SummaryStatistics.java

示例7: equals

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * Returns true iff <code>object</code> is a <code>SummaryStatistics</code>
 * instance and all statistics have the same values as this.
 * @param object the object to test equality against.
 * @return true if object equals this
 */
public boolean equals(Object object) {
    if (object == this ) {
        return true;
    }
    if (object instanceof MultivariateSummaryStatistics == false) {
        return false;
    }
    MultivariateSummaryStatistics stat = (MultivariateSummaryStatistics) object;
    return (MathUtils.equals(stat.getGeometricMean(), 
            this.getGeometricMean()) &&
            MathUtils.equals(stat.getMax(), this.getMax()) && 
            MathUtils.equals(stat.getMean(),this.getMean()) &&
            MathUtils.equals(stat.getMin(),this.getMin()) &&
            MathUtils.equals(stat.getN(), this.getN()) &&
            MathUtils.equals(stat.getSum(), this.getSum()) &&
            MathUtils.equals(stat.getSumSq(),this.getSumSq()) &&
            MathUtils.equals(stat.getSumLog(),this.getSumLog()) &&
            stat.getCovariance().equals(this.getCovariance()));
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:MultivariateSummaryStatistics.java

示例8: multiply

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * <p>Multiplies the value of this fraction by another, returning the 
 * result in reduced form.</p>
 *
 * @param fraction  the fraction to multiply by, must not be <code>null</code>
 * @return a <code>Fraction</code> instance with the resulting values
 * @throws IllegalArgumentException if the fraction is <code>null</code>
 * @throws ArithmeticException if the resulting numerator or denominator exceeds
 *  <code>Integer.MAX_VALUE</code>
 */
public Fraction multiply(Fraction fraction) {
    if (fraction == null) {
        throw new IllegalArgumentException("The fraction must not be null");
    }
    if (numerator == 0 || fraction.numerator == 0) {
        return ZERO;
    }
    // knuth 4.5.1
    // make sure we don't overflow unless the result *must* overflow.
    int d1 = MathUtils.gcd(numerator, fraction.denominator);
    int d2 = MathUtils.gcd(fraction.numerator, denominator);
    return getReducedFraction
    (MathUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
            MathUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:Fraction.java

示例9: getReducedFraction

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * <p>Creates a <code>Fraction</code> instance with the 2 parts
 * of a fraction Y/Z.</p>
 *
 * <p>Any negative signs are resolved to be on the numerator.</p>
 *
 * @param numerator  the numerator, for example the three in 'three sevenths'
 * @param denominator  the denominator, for example the seven in 'three sevenths'
 * @return a new fraction instance, with the numerator and denominator reduced
 * @throws ArithmeticException if the denominator is <code>zero</code>
 */
public static Fraction getReducedFraction(int numerator, int denominator) {
    if (denominator == 0) {
        throw new ArithmeticException("The denominator must not be zero");
    }
    if (numerator==0) {
        return ZERO; // normalize zero.
    }
    // allow 2^k/-2^31 as a valid fraction (where k>0)
    if (denominator==Integer.MIN_VALUE && (numerator&1)==0) {
        numerator/=2; denominator/=2;
    }
    if (denominator < 0) {
        if (numerator==Integer.MIN_VALUE ||
                denominator==Integer.MIN_VALUE) {
            throw new ArithmeticException("overflow: can't negate");
        }
        numerator = -numerator;
        denominator = -denominator;
    }
    // simplify fraction.
    int gcd = MathUtils.gcd(numerator, denominator);
    numerator /= gcd;
    denominator /= gcd;
    return new Fraction(numerator, denominator);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:37,代码来源:Fraction.java

示例10: configureSinks

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
private synchronized void configureSinks() {
  sinkConfigs = config.getInstanceConfigs(SINK_KEY);
  int confPeriod = 0;
  for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) {
    MetricsConfig conf = entry.getValue();
    int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT);
    confPeriod = confPeriod == 0 ? sinkPeriod
                                 : MathUtils.gcd(confPeriod, sinkPeriod);
    String clsName = conf.getClassName("");
    if (clsName == null) continue;  // sink can be registered later on
    String sinkName = entry.getKey();
    try {
      MetricsSinkAdapter sa = newSink(sinkName,
          conf.getString(DESC_KEY, sinkName), conf);
      sa.start();
      sinks.put(sinkName, sa);
    }
    catch (Exception e) {
      LOG.warn("Error creating sink '"+ sinkName +"'", e);
    }
  }
  period = confPeriod > 0 ? confPeriod
                          : config.getInt(PERIOD_KEY, PERIOD_DEFAULT);
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:25,代码来源:MetricsSystemImpl.java

示例11: testExample1

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * Tests the first example contained within the README.
 */
@Test
public void testExample1() throws Exception {

  update(TEST_RESOURCES + "/config/zookeeper/readme-example-1");

  // start the topology and write test messages to kafka
  fluxComponent.submitTopology();
  kafkaComponent.writeMessages(inputTopic, input);

  // verify - ensure the profile is being persisted
  waitOrTimeout(() -> profilerTable.getPutLog().size() > 0,
          timeout(seconds(90)));

  // verify - only 10.0.0.2 sends 'HTTP', thus there should be only 1 value
  List<Double> actuals = read(profilerTable.getPutLog(), columnFamily, columnBuilder.getColumnQualifier("value"), Double.class);

  // verify - there are 5 'HTTP' each with 390 bytes
  Assert.assertTrue(actuals.stream().anyMatch(val ->
          MathUtils.equals(390.0 * 5, val, epsilon)
  ));
}
 
开发者ID:apache,项目名称:metron,代码行数:25,代码来源:ProfilerIntegrationTest.java

示例12: testExample3

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * Tests the third example contained within the README.
 */
@Test
public void testExample3() throws Exception {

  update(TEST_RESOURCES + "/config/zookeeper/readme-example-3");

  // start the topology and write test messages to kafka
  fluxComponent.submitTopology();
  kafkaComponent.writeMessages(inputTopic, input);

  // verify - ensure the profile is being persisted
  waitOrTimeout(() -> profilerTable.getPutLog().size() > 0,
          timeout(seconds(90)));

  // verify - only 10.0.0.2 sends 'HTTP', thus there should be only 1 value
  List<Double> actuals = read(profilerTable.getPutLog(), columnFamily, columnBuilder.getColumnQualifier("value"), Double.class);

  // verify - there are 5 'HTTP' messages each with a length of 20, thus the average should be 20
  Assert.assertTrue("Could not find a value near 20. Actual values read are are: " + Joiner.on(",").join(actuals)
                   , actuals.stream().anyMatch(val -> MathUtils.equals(val, 20.0, epsilon)
  ));
}
 
开发者ID:apache,项目名称:metron,代码行数:25,代码来源:ProfilerIntegrationTest.java

示例13: testExample4

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
/**
 * Tests the fourth example contained within the README.
 */
@Test
public void testExample4() throws Exception {

  update(TEST_RESOURCES + "/config/zookeeper/readme-example-4");

  // start the topology and write test messages to kafka
  fluxComponent.submitTopology();
  kafkaComponent.writeMessages(inputTopic, input);

  // verify - ensure the profile is being persisted
  waitOrTimeout(() -> profilerTable.getPutLog().size() > 0,
          timeout(seconds(90)));

  // verify - only 10.0.0.2 sends 'HTTP', thus there should be only 1 value
  byte[] column = columnBuilder.getColumnQualifier("value");
  List<OnlineStatisticsProvider> actuals = read(profilerTable.getPutLog(), columnFamily, column, OnlineStatisticsProvider.class);

  // verify - there are 5 'HTTP' messages each with a length of 20, thus the average should be 20
  Assert.assertTrue("Could not find a value near 20. Actual values read are are: " + Joiner.on(",").join(actuals)
                   , actuals.stream().anyMatch(val -> MathUtils.equals(val.getMean(), 20.0, epsilon)
  ));
}
 
开发者ID:apache,项目名称:metron,代码行数:26,代码来源:ProfilerIntegrationTest.java

示例14: testPercentiles

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
@Test
public void testPercentiles() throws Exception {

  update(TEST_RESOURCES + "/config/zookeeper/percentiles");


  // start the topology and write test messages to kafka
  fluxComponent.submitTopology();
  kafkaComponent.writeMessages(inputTopic, input);

  // verify - ensure the profile is being persisted
  waitOrTimeout(() -> profilerTable.getPutLog().size() > 0,
          timeout(seconds(90)));

  List<Double> actuals = read(profilerTable.getPutLog(), columnFamily, columnBuilder.getColumnQualifier("value"), Double.class);

  // verify - the 70th percentile of 5 x 20s = 20.0
  Assert.assertTrue("Could not find a value near 20. Actual values read are are: " + Joiner.on(",").join(actuals)
                   , actuals.stream().anyMatch(val -> MathUtils.equals(val, 20.0, epsilon)));
}
 
开发者ID:apache,项目名称:metron,代码行数:21,代码来源:ProfilerIntegrationTest.java

示例15: mstep

import org.apache.commons.math.util.MathUtils; //导入依赖的package包/类
@Override
	protected void mstep(EMGMM gmm, GaussianMixtureModelEM learner, Matrix X, Matrix responsibilities,
			Matrix weightedXsum,
			double[] norm)
{
		// Eq. 12 from K. Murphy,
		// "Fitting a Conditional Linear Gaussian Distribution"
		final int nfeatures = X.getColumnDimension();
		for (int c = 0; c < learner.nComponents; c++) {
			final Matrix post = responsibilities.getMatrix(0, X.getRowDimension() - 1, c, c).transpose();

			final double factor = 1.0 / (ArrayUtils.sumValues(post.getArray()) + 10 * MathUtils.EPSILON);

			final Matrix pXt = X.transpose();
			for (int i = 0; i < pXt.getRowDimension(); i++)
				for (int j = 0; j < pXt.getColumnDimension(); j++)
					pXt.set(i, j, pXt.get(i, j) * post.get(0, j));

			final Matrix argcv = pXt.times(X).times(factor);
			final Matrix mu = ((FullMultivariateGaussian) gmm.gaussians[c]).mean;

			((FullMultivariateGaussian) gmm.gaussians[c]).covar = argcv.minusEquals(mu.transpose().times(mu))
					.plusEquals(Matrix.identity(nfeatures, nfeatures).times(learner.minCovar));
		}
	}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:26,代码来源:GaussianMixtureModelEM.java


注:本文中的org.apache.commons.math.util.MathUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。