List of usage examples for org.apache.commons.math3.util ArithmeticUtils pow
public static BigInteger pow(final BigInteger k, BigInteger e) throws NotPositiveException
From source file:org.moeaframework.core.operator.AdaptiveMultimethodVariationTest.java
/** * Tests if the number of invocations between probability updates matches * the UPDATE_WINDOW./*w ww .j av a 2 s. com*/ */ @Test public void testProbabilityUpdateInvocationCount() { AdaptiveMultimethodVariationCounter variation = new AdaptiveMultimethodVariationCounter(population); variation.addOperator(new DummyVariation(2)); variation.addOperator(new DummyVariation(2)); UniformSelection selection = new UniformSelection(); //ensure sufficient number of samples to trigger off-by-one error int numberOfSamples = ArithmeticUtils.pow(variation.getUpdateWindow(), 3); for (int i = 0; i < numberOfSamples; i++) { variation.evolve(selection.select(variation.getArity(), population)); } Assert.assertEquals(numberOfSamples / variation.getUpdateWindow(), variation.getCount()); }
From source file:org.um.feri.ears.algorithms.moo.pesa2MOEA.AdaptiveGridArchive.java
/** * Constructs an adaptive grid archive with the specified capacity with the * specified number of divisions along each objective. * //from w ww . j ava2 s . co m * @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(); }
From source file:org.um.feri.ears.algorithms.moo.pesa2MOEA.AdaptiveGridArchive.java
/** * 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./*ww w .j a v a 2 s.c om*/ * * @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; }
From source file:org.um.feri.ears.algorithms.moo.pesa2MOEA.PESA2.java
@Override protected void init() { if (optimalParam) { switch (num_obj) { case 1: { populationSize = 100;/*from w ww. j a v a2 s. c o m*/ 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); }
From source file:org.um.feri.ears.qualityIndicator.RIndicator.java
/** * Generates uniformly-distributed weights. * //from w ww .java2 s . c o m * @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; }
From source file:org.um.feri.ears.qualityIndicator.RIndicator.java
/** * Converts an integer into its base-k representation. * //ww w . j a v a 2s. c o m * @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; }