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


Java ArithmeticUtils.pow方法代码示例

本文整理汇总了Java中org.apache.commons.math3.util.ArithmeticUtils.pow方法的典型用法代码示例。如果您正苦于以下问题:Java ArithmeticUtils.pow方法的具体用法?Java ArithmeticUtils.pow怎么用?Java ArithmeticUtils.pow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.util.ArithmeticUtils的用法示例。


在下文中一共展示了ArithmeticUtils.pow方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

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

示例8: 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) * ArithmeticUtils.factorial(i) /
                              FastMath.pow(x, i + 1);
            Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:13,代码来源:DerivativeStructureTest.java

示例9: 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 new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
                               ArithmeticUtils.pow(numerator,   -exponent));
    }
    return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
                           ArithmeticUtils.pow(denominator, exponent));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:BigFraction.java


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