List of usage examples for org.apache.commons.math3.util FastMath ceil
public static double ceil(double x)
From source file:gamlss.utilities.ArithmeticSeries.java
public static double[] getSeries(final double start, final double end, final double step) { int length = (int) FastMath.ceil((end - start) / (step)); double[] x = new double[length]; for (int i = 0; i < length; i++) { x[i] = start + step * i;//from ww w . j a v a2s .co m } return x; }
From source file:jmb.jcortex.strategies.batchingstrategies.BatchedDataSet.java
public BatchedDataSet(DataSet dataSet, int instancesPerBatch) { DataSet shuffledDataSet = dataSet.shuffleRows(); int numBatches = (int) FastMath.round((double) shuffledDataSet.numRows() / (double) instancesPerBatch); int numPerBatch = (int) FastMath.ceil(shuffledDataSet.numRows() / numBatches); for (int i = 0; i < numBatches; i++) { int start = i * numPerBatch; int end = start + numPerBatch; if (end > shuffledDataSet.numRows()) { end = shuffledDataSet.numRows(); }/* w w w .j a v a 2s.c o m*/ batches.add(shuffledDataSet.sliceRows(start, end)); } batchIterator = batches.iterator(); }
From source file:cloudnet.pm.PmSpecPower.java
@Override public double getPower(double utilization) throws IllegalArgumentException { Ensure.BetweenInclusive(utilization, 0.0, 1.0, "utilization"); if (utilization % 0.1 == 0) { return getPowerData((int) (utilization * 10)); }// ww w . java2 s. c om int utilization1 = (int) FastMath.floor(utilization * 10); int utilization2 = (int) FastMath.ceil(utilization * 10); double power1 = getPowerData(utilization1); double power2 = getPowerData(utilization2); double delta = (power2 - power1) / 10; double power = power1 + delta * (utilization - (double) utilization1 / 10) * 100; return power; }
From source file:com.cloudera.oryx.rdf.computation.build.DistributeExampleFn.java
@Override public void initialize() { super.initialize(); numReducers = getContext().getNumReduceTasks(); log.info("{} reducers", numReducers); Config config = ConfigUtils.getDefaultConfig(); int numTrees = config.getInt("model.num-trees"); // Bump this up to as least 2x reducers numTrees = FastMath.max(numTrees, 2 * numReducers); // Make it a multiple of # reducers while ((numTrees % numReducers) != 0) { numTrees++;/*w w w.j av a 2 s. co m*/ } log.info("Building {} trees", numTrees); double sampleRate = config.getDouble("model.sample-rate"); Preconditions.checkArgument(sampleRate > 0.0 && sampleRate <= 1.0); reducersPerDatum = FastMath.max(1, (int) FastMath.ceil(numReducers * sampleRate)); Preconditions.checkArgument(reducersPerDatum >= 1 && reducersPerDatum <= numReducers); log.info("{} reducers per datum", reducersPerDatum); }
From source file:com.facebook.LinkBench.distributions.GeometricDistribution.java
@Override public long quantile(double r) { /*/* www . j a va 2 s . com*/ * Quantile function for geometric distribution over * range [0, inf) where 0 < r < 1 * quantile(r) = ceiling(ln(1 - r) / ln (1 - p)) * Source: http://www.math.uah.edu/stat/bernoulli/Geometric.html */ if (r == 0.0) return min; // 0.0 must be handled specially long x = min + (long) FastMath.ceil(FastMath.log(1 - r) / FastMath.log(1 - p)); // truncate over max return Math.min(x, max - 1); }
From source file:lirmm.inria.fr.math.OpenLongToDoubleHashMap.java
/** * Compute the capacity needed for a given size. * * @param expectedSize expected size of the map * @return capacity to use for the specified size *///from w w w. jav a 2s .com private static int computeCapacity(final int expectedSize) { if (expectedSize == 0) { return 1; } final int capacity = (int) FastMath.ceil(expectedSize / LOAD_FACTOR); final int powerOfTwo = Integer.highestOneBit(capacity); if (powerOfTwo == capacity) { return capacity; } return nextPowerOfTwo(capacity); }
From source file:cc.mallet.types.PolyaUrnDirichlet.java
protected long nextPoisson(double meanPoisson) { final double pivot = 40.0d; if (meanPoisson < pivot) { double p = FastMath.exp(-meanPoisson); long n = 0; double r = 1.0d; double rnd = 1.0d; while (n < 1000 * meanPoisson) { rnd = ThreadLocalRandom.current().nextDouble(); r *= rnd;//from w w w . ja v a2 s .c om if (r >= p) { n++; } else { return n; } } return n; } else { final double lambda = FastMath.floor(meanPoisson); final double lambdaFractional = meanPoisson - lambda; final double logLambda = FastMath.log(lambda); final double logLambdaFactorial = CombinatoricsUtils.factorialLog((int) lambda); final long y2 = lambdaFractional < Double.MIN_VALUE ? 0 : nextPoisson(lambdaFractional); final double delta = FastMath.sqrt(lambda * FastMath.log(32 * lambda / FastMath.PI + 1)); final double halfDelta = delta / 2; final double twolpd = 2 * lambda + delta; final double a1 = FastMath.sqrt(FastMath.PI * twolpd) * FastMath.exp(1 / (8 * lambda)); final double a2 = (twolpd / delta) * FastMath.exp(-delta * (1 + delta) / twolpd); final double aSum = a1 + a2 + 1; final double p1 = a1 / aSum; final double p2 = a2 / aSum; final double c1 = 1 / (8 * lambda); double x = 0; double y = 0; double v = 0; int a = 0; double t = 0; double qr = 0; double qa = 0; for (;;) { final double u = ThreadLocalRandom.current().nextDouble(); if (u <= p1) { final double n = ThreadLocalRandom.current().nextGaussian(); x = n * FastMath.sqrt(lambda + halfDelta) - 0.5d; if (x > delta || x < -lambda) { continue; } y = x < 0 ? FastMath.floor(x) : FastMath.ceil(x); final double e = nextStandardExponential(); v = -e - (n * n / 2) + c1; } else { if (u > p1 + p2) { y = lambda; break; } else { x = delta + (twolpd / delta) * nextStandardExponential(); y = FastMath.ceil(x); v = -nextStandardExponential() - delta * (x + 1) / twolpd; } } a = x < 0 ? 1 : 0; t = y * (y + 1) / (2 * lambda); if (v < -t && a == 0) { y = lambda + y; break; } qr = t * ((2 * y + 1) / (6 * lambda) - 1); qa = qr - (t * t) / (3 * (lambda + a * (y + 1))); if (v < qa) { y = lambda + y; break; } if (v > qr) { continue; } if (v < y * logLambda - CombinatoricsUtils.factorialLog((int) (y + lambda)) + logLambdaFactorial) { y = lambda + y; break; } } return y2 + (long) y; } }
From source file:cloudnet.examples.elasticity.bn.DistrHelper.java
/** * Returns upper bound of migration time in seconds. * * @param vmSize/*from w w w .j a v a2 s .c o m*/ * @param bw * @param dirtyPageRate * @return */ public static long getMigrationTimeUB(long vmSize, long bw, int dirtyPageRate) { return (long) FastMath.ceil(1000 * dirtyPageRate * vmSize / (double) bw); }
From source file:it.unibo.alchemist.modelchecker.AlchemistASMC.java
private static int computeMinimum(final double interval, final double confidence) { final UnivariateFunction f = new UnivariateFunction() { @Override//from w ww.java 2s . com public double value(final double n) { double t; if (Math.ceil(n) == FastMath.floor(n)) { t = new TDistribution((int) n).inverseCumulativeProbability(1 - confidence / 2); } else { double t1 = new TDistribution((int) FastMath.ceil(n)) .inverseCumulativeProbability((1 - confidence / 2)) * (n - Math.floor(n)); double t2 = new TDistribution((int) FastMath.floor(n)) .inverseCumulativeProbability((1 - confidence / 2)) * (Math.ceil(n) - n); t = t1 + t2; } double value = 2 * t / n; return value - interval; } }; final BisectionSolver bs = new BisectionSolver(); return (int) Math.ceil(bs.solve(Integer.MAX_VALUE, f, 1, Integer.MAX_VALUE)); }
From source file:net.myrrix.online.som.SelfOrganizingMaps.java
/** * Completes the update step after assigning an input vector tentatively to a {@link Node}. The assignment * causes nearby nodes (including the assigned one) to move their centers towards the vector. *//*from w w w . j av a2s.co m*/ private void updateNeighborhood(Node[][] map, float[] V, int bmuI, int bmuJ, double decayFactor) { int mapSize = map.length; double neighborhoodRadius = mapSize * decayFactor; int minI = FastMath.max(0, (int) FastMath.floor(bmuI - neighborhoodRadius)); int maxI = FastMath.min(mapSize, (int) FastMath.ceil(bmuI + neighborhoodRadius)); int minJ = FastMath.max(0, (int) FastMath.floor(bmuJ - neighborhoodRadius)); int maxJ = FastMath.min(mapSize, (int) FastMath.ceil(bmuJ + neighborhoodRadius)); for (int i = minI; i < maxI; i++) { Node[] mapRow = map[i]; for (int j = minJ; j < maxJ; j++) { double learningRate = initLearningRate * decayFactor; double currentDistance = distance(i, j, bmuI, bmuJ); double theta = FastMath.exp( -(currentDistance * currentDistance) / (2.0 * neighborhoodRadius * neighborhoodRadius)); double learningTheta = learningRate * theta; float[] center = mapRow[j].getCenter(); int length = center.length; // Don't synchronize, for performance. Colliding updates once in a while does little. for (int k = 0; k < length; k++) { center[k] += (float) (learningTheta * (V[k] - center[k])); } } } }