本文整理汇总了Java中org.apache.commons.math3.util.ArithmeticUtils类的典型用法代码示例。如果您正苦于以下问题:Java ArithmeticUtils类的具体用法?Java ArithmeticUtils怎么用?Java ArithmeticUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArithmeticUtils类属于org.apache.commons.math3.util包,在下文中一共展示了ArithmeticUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: configureSinks
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的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
: ArithmeticUtils.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:naver,项目名称:hadoop,代码行数:25,代码来源:MetricsSystemImpl.java
示例2: pow
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/**
* <p>
* Returns a <code>BigFraction</code> whose value is
* <tt>(this<sup>exponent</sup>)</tt>, returning the result in reduced form.
* </p>
*
* @param exponent
* exponent to which this <code>BigFraction</code> is to be raised.
* @return <tt>this<sup>exponent</sup></tt> as a <code>BigFraction</code>.
*/
public BigFraction pow(final long exponent) {
if (exponent == 0) {
return ONE;
}
if (numerator.signum() == 0) {
return this;
}
if (exponent < 0) {
return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
ArithmeticUtils.pow(numerator, -exponent));
}
return new BigFraction(ArithmeticUtils.pow(numerator, exponent),
ArithmeticUtils.pow(denominator, exponent));
}
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:BigFraction.java
示例3: multiply
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的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}
* @return a {@code Fraction} instance with the resulting values
* @throws NullArgumentException if the fraction is {@code null}
* @throws MathArithmeticException if the resulting numerator or denominator exceeds
* {@code Integer.MAX_VALUE}
*/
public Fraction multiply(Fraction fraction) {
if (fraction == null) {
throw new NullArgumentException(LocalizedFormats.FRACTION);
}
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 = ArithmeticUtils.gcd(numerator, fraction.denominator);
int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator);
return getReducedFraction
(ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
}
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:Fraction.java
示例4: toBaseK
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/**
* Converts an integer into its base-k representation.
*
* @param number the integer to convert
* @param k the base
* @param length the length of the resulting base-k representation
* @return the base-k representation of the given number
* @throws Exception
*/
private static int[] toBaseK(int number, int k, int length) throws Exception {
int value = length-1;
int[] kary = new int[length];
int i = 0;
if (number >= ArithmeticUtils.pow(k, length)) {
throw new Exception("number can not be represented in " +
"base-k with specified number of digits");
}
while (number != 0) {
if (number >= ArithmeticUtils.pow(k, value)) {
kary[i]++;
number -= ArithmeticUtils.pow(k, value);
} else {
value--;
i++;
}
}
return kary;
}
开发者ID:UM-LPM,项目名称:EARS,代码行数:32,代码来源:RIndicator.java
示例5: findIndex
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/**
* Returns the index of the specified solution in this adaptive grid
* archive, or {@code -1} if the solution is not within the current lower
* and upper bounds.
*
* @param solution the specified solution
* @return the index of the specified solution in this adaptive grid
* archive, or {@code -1} if the solution is not within the current
* lower and upper bounds
*/
public int findIndex(MOSolutionBase<Type> solution) {
int index = 0;
for (int i = 0; i < num_obj; i++) {
double value = solution.getObjective(i);
if ((value < minimum[i]) || (value > maximum[i])) {
return -1;
} else {
int tempIndex = (int)(numberOfDivisions *
((value - minimum[i]) / (maximum[i] - minimum[i])));
// handle special case where value = maximum[i]
if (tempIndex == numberOfDivisions) {
tempIndex--;
}
index += tempIndex * ArithmeticUtils.pow(numberOfDivisions, i);
}
}
return index;
}
开发者ID:UM-LPM,项目名称:EARS,代码行数:34,代码来源:AdaptiveGridArchive.java
示例6: howManyPossibleConstraints
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
@Override
public long howManyPossibleConstraints() {
int realBranchingLimit =
(this.branchingLimit < this.taskCharArchive.size()
? this.branchingLimit
: this.taskCharArchive.size() - 1);
long numberOfPossibleConstraintsPerActivity = 0;
for (int i = 1; i <= realBranchingLimit; i++) {
numberOfPossibleConstraintsPerActivity +=
ArithmeticUtils
.binomialCoefficient(
this.taskCharArchive.size(), // n
i); // k
}
return
( MetaConstraintUtils.getAllDiscoverableForwardRelationConstraintTemplates().size() -1 + // out-branching
MetaConstraintUtils.getAllDiscoverableBackwardRelationConstraintTemplates().size() -1 // in branching
)
* tasksToQueryFor.size()
* numberOfPossibleConstraintsPerActivity;
}
开发者ID:cdc08x,项目名称:MINERful,代码行数:25,代码来源:ProbabilisticRelationBranchedConstraintsMiner.java
示例7: testMany
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
@Test
public void testMany()
{
int choose = 5;
List<String> items = new ArrayList<String>();
for (int i = 0; i < 30; i++)
{
items.add(String.format("%s", i));
}
long count = 0;
for (List<String> strList : new CombinationIterator<String>(items, choose))
{
count++;
}
assertEquals(ArithmeticUtils.binomialCoefficient(items.size(), choose), count);
}
开发者ID:jeheydorn,项目名称:smodelkit,代码行数:17,代码来源:CombinationIteratorTest.java
示例8: testOne
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
@Test
public void testOne()
{
int choose = 1;
List<String> items = new ArrayList<String>();
for (int i = 0; i < 30; i++)
{
items.add(String.format("%s", i));
}
CombinationIterator<String> iter = new CombinationIterator<String>(items, choose);
long count = 0;
for (List<String> strList : iter)
{
count++;
}
assertEquals(ArithmeticUtils.binomialCoefficient(items.size(), choose), count);
}
开发者ID:jeheydorn,项目名称:smodelkit,代码行数:18,代码来源:CombinationIteratorTest.java
示例9: testChooseAll
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
@Test
public void testChooseAll()
{
int choose = 30;
List<String> items = new ArrayList<String>();
for (int i = 0; i < 30; i++)
{
items.add(String.format("%s", i));
}
CombinationIterator<String> iter = new CombinationIterator<String>(items, choose);
long count = 0;
for (List<String> strList : iter)
{
count++;
}
assertEquals(ArithmeticUtils.binomialCoefficient(items.size(), choose), count);
}
开发者ID:jeheydorn,项目名称:smodelkit,代码行数:18,代码来源:CombinationIteratorTest.java
示例10: testMany
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
@Test
public void testMany()
{
for (int n = 1; n < 8; n++)
{
List<String> items = Collections.nCopies(n, "");
int count = 0;
PermutationIterator<String> iter = new PermutationIterator<String>(items);
while(iter.hasNext())
{
iter.next();
count++;
}
assertEquals(ArithmeticUtils.factorial(items.size()), count);
}
}
开发者ID:jeheydorn,项目名称:smodelkit,代码行数:17,代码来源:PermutationIteratorTest.java
示例11: taylor
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/** Evaluate Taylor expansion of a derivative structure.
* @param ds array holding the derivative structure
* @param dsOffset offset of the derivative structure in its array
* @param delta parameters offsets (Δx, Δy, ...)
* @return value of the Taylor expansion at x + Δx, y + Δy, ...
* @throws MathArithmeticException if factorials becomes too large
*/
public double taylor(final double[] ds, final int dsOffset, final double ... delta)
throws MathArithmeticException {
double value = 0;
for (int i = getSize() - 1; i >= 0; --i) {
final int[] orders = getPartialDerivativeOrders(i);
double term = ds[dsOffset + i];
for (int k = 0; k < orders.length; ++k) {
if (orders[k] > 0) {
try {
term *= FastMath.pow(delta[k], orders[k]) /
ArithmeticUtils.factorial(orders[k]);
} catch (NotPositiveException e) {
// this cannot happen
throw new MathInternalError(e);
}
}
}
value += term;
}
return value;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:DSCompiler.java
示例12: configureSinks
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
private synchronized void configureSinks() {
sinkConfigs = config.getInstanceConfigs(SINK_KEY);
long confPeriodMillis = 0;
for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) {
MetricsConfig conf = entry.getValue();
int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT);
// Support configuring periodMillis for testing.
long sinkPeriodMillis =
conf.getLong(PERIOD_MILLIS_KEY, sinkPeriod * 1000);
confPeriodMillis = confPeriodMillis == 0 ? sinkPeriodMillis
: ArithmeticUtils.gcd(confPeriodMillis, sinkPeriodMillis);
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);
}
}
long periodSec = config.getInt(PERIOD_KEY, PERIOD_DEFAULT);
period = confPeriodMillis > 0 ? confPeriodMillis
: config.getLong(PERIOD_MILLIS_KEY, periodSec * 1000);
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:MetricsSystemImpl.java
示例13: Fraction
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/**
* Create a fraction given the numerator and denominator. The fraction is
* reduced to lowest terms.
* @param num the numerator.
* @param den the denominator.
* @throws MathArithmeticException if the denominator is {@code zero}
*/
public Fraction(int num, int den) {
if (den == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION,
num, den);
}
if (den < 0) {
if (num == Integer.MIN_VALUE ||
den == Integer.MIN_VALUE) {
throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION,
num, den);
}
num = -num;
den = -den;
}
// reduce numerator and denominator by greatest common denominator.
final int d = ArithmeticUtils.gcd(num, den);
if (d > 1) {
num /= d;
den /= d;
}
// move sign to numerator.
if (den < 0) {
num = -num;
den = -den;
}
this.numerator = num;
this.denominator = den;
}
开发者ID:biocompibens,项目名称:SME,代码行数:37,代码来源:Fraction.java
示例14: getReducedFraction
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/**
* <p>Creates a {@code Fraction} 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 MathArithmeticException if the denominator is {@code zero}
*/
public static Fraction getReducedFraction(int numerator, int denominator) {
if (denominator == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION,
numerator, denominator);
}
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 MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION,
numerator, denominator);
}
numerator = -numerator;
denominator = -denominator;
}
// simplify fraction.
int gcd = ArithmeticUtils.gcd(numerator, denominator);
numerator /= gcd;
denominator /= gcd;
return new Fraction(numerator, denominator);
}
开发者ID:biocompibens,项目名称:SME,代码行数:39,代码来源:Fraction.java
示例15: AbstractAlignedProcessingTimeWindowOperator
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
protected AbstractAlignedProcessingTimeWindowOperator(
F function,
KeySelector<IN, KEY> keySelector,
TypeSerializer<KEY> keySerializer,
TypeSerializer<STATE> stateTypeSerializer,
long windowLength,
long windowSlide) {
super(function);
if (windowLength < MIN_SLIDE_TIME) {
throw new IllegalArgumentException("Window length must be at least " + MIN_SLIDE_TIME + " msecs");
}
if (windowSlide < MIN_SLIDE_TIME) {
throw new IllegalArgumentException("Window slide must be at least " + MIN_SLIDE_TIME + " msecs");
}
if (windowLength < windowSlide) {
throw new IllegalArgumentException("The window size must be larger than the window slide");
}
final long paneSlide = ArithmeticUtils.gcd(windowLength, windowSlide);
if (paneSlide < MIN_SLIDE_TIME) {
throw new IllegalArgumentException(String.format(
"Cannot compute window of size %d msecs sliding by %d msecs. " +
"The unit of grouping is too small: %d msecs", windowLength, windowSlide, paneSlide));
}
this.function = requireNonNull(function);
this.keySelector = requireNonNull(keySelector);
this.keySerializer = requireNonNull(keySerializer);
this.stateTypeSerializer = requireNonNull(stateTypeSerializer);
this.windowSize = windowLength;
this.windowSlide = windowSlide;
this.paneSize = paneSlide;
this.numPanesPerWindow = MathUtils.checkedDownCast(windowLength / paneSlide);
}
开发者ID:axbaretto,项目名称:flink,代码行数:36,代码来源:AbstractAlignedProcessingTimeWindowOperator.java
示例16: generateUniformWeights
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/**
* Generates uniformly-distributed weights.
*
* @param s the number of subdivisions along each objective
* @param k the number of objectives
* @return the uniformly-distributed weights
* @throws Exception
*/
protected static double[][] generateUniformWeights(int s, int k) throws Exception {
int counter = 0;
int N = ArithmeticUtils.pow(s+1, k);
double[][] weights = new double[
(int)CombinatoricsUtils.binomialCoefficient(s+k-1, k-1)][k];
for (int i = 0; i < N; i++) {
int sum = 0;
int[] kary = toBaseK(i, s+1, k);
for (int j = 0; j < k; j++) {
sum += kary[j];
}
if (sum == s) {
for (int j = 0; j < k; j++) {
weights[counter][j] = kary[j] / (double)s;
}
counter++;
}
}
return weights;
}
开发者ID:UM-LPM,项目名称:EARS,代码行数:35,代码来源:RIndicator.java
示例17: AdaptiveGridArchive
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/**
* Constructs an adaptive grid archive with the specified capacity with the
* specified number of divisions along each objective.
*
* @param capacity the capacity of this archive
* @param problem the problem for which this archive is used
* @param numberOfDivisions the number of divisions this archive uses to
* split each objective
*/
public AdaptiveGridArchive(int capacity, int num_obj,
int numberOfDivisions) {
super(new DominanceComparator<Type>());
this.capacity = capacity;
this.numberOfDivisions = numberOfDivisions;
this.num_obj = num_obj;
minimum = new double[num_obj];
maximum = new double[num_obj];
density = new int[ArithmeticUtils.pow(numberOfDivisions, num_obj)];
adaptGrid();
}
开发者ID:UM-LPM,项目名称:EARS,代码行数:23,代码来源:AdaptiveGridArchive.java
示例18: init
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
@Override
protected void init() {
if(optimalParam)
{
switch(num_obj){
case 1:
{
populationSize = 100;
archiveSize = 100;
break;
}
case 2:
{
populationSize = 100;
archiveSize = 100;
break;
}
case 3:
{
populationSize = 300;
archiveSize = 300;
break;
}
default:
{
populationSize = 500;
archiveSize = 500;
break;
}
}
}
ai.addParameter(EnumAlgorithmParameters.POP_SIZE, populationSize+"");
ai.addParameter(EnumAlgorithmParameters.ARCHIVE_SIZE, archiveSize+"");
archive = new AdaptiveGridArchive<Type>(archiveSize, num_obj, ArithmeticUtils.pow(2, bisections));
population = new ParetoSolution<Type>(populationSize);
}
开发者ID:UM-LPM,项目名称:EARS,代码行数:40,代码来源:PESA2.java
示例19: testReciprocal
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
@Test
public void testReciprocal() {
for (double x = 0.1; x < 1.2; x += 0.1) {
DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
for (int i = 1; i < r.getOrder(); ++i) {
double expected = ArithmeticUtils.pow(-1, i) * CombinatoricsUtils.factorial(i) /
FastMath.pow(x, i + 1);
Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
}
}
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:13,代码来源:DerivativeStructureTest.java
示例20: getEntry
import org.apache.commons.math3.util.ArithmeticUtils; //导入依赖的package包/类
/**
* Returns the {@code (i, j)} entry of the inverse Hilbert matrix. Exact
* arithmetic is used; in case of overflow, an exception is thrown.
*
* @param i Row index (starts at 0).
* @param j Column index (starts at 0).
* @return The coefficient of the inverse Hilbert matrix.
*/
public long getEntry(final int i, final int j) {
long val = i + j + 1;
long aux = CombinatoricsUtils.binomialCoefficient(n + i, n - j - 1);
val = ArithmeticUtils.mulAndCheck(val, aux);
aux = CombinatoricsUtils.binomialCoefficient(n + j, n - i - 1);
val = ArithmeticUtils.mulAndCheck(val, aux);
aux = CombinatoricsUtils.binomialCoefficient(i + j, i);
val = ArithmeticUtils.mulAndCheck(val, aux);
val = ArithmeticUtils.mulAndCheck(val, aux);
return ((i + j) & 1) == 0 ? val : -val;
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:InverseHilbertMatrix.java
注:本文中的org.apache.commons.math3.util.ArithmeticUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论