List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:co.mcme.animations.triggers.BlockInteractTrigger.java
@Override public boolean check(Location location) { // SamplePlugin.WEPlugin.getServer().getLogger().info("--------------------"); // SamplePlugin.WEPlugin.getServer().getLogger().info("Checking block trigger... "); // SamplePlugin.WEPlugin.getServer().getLogger().info("frame:" + frame); // SamplePlugin.WEPlugin.getServer().getLogger().info("X:" + triggerLocation.getX()); // SamplePlugin.WEPlugin.getServer().getLogger().info("Y:" + triggerLocation.getY()); // SamplePlugin.WEPlugin.getServer().getLogger().info("Z:" + triggerLocation.getZ()); for (Vector v : triggerLocation) { if ((parent.getCurrentFrame() == frame) && (Math.floor(v.getX()) == Math.floor(location.getX())) && (Math.floor(v.getY()) == Math.floor(location.getY())) && (Math.floor(v.getZ()) == Math.floor(location.getZ()))) { return true; }//ww w . ja v a 2 s. c om } return false; }
From source file:it.polimi.diceH2020.SPACE4Cloud.shared.solution.SolutionPerJob.java
public SolutionPerJob setNumberVM(int numberVM) { if (this.numberVM == null || this.numberVM.intValue() != numberVM) { changed = true;//from w w w . ja va 2s . co m } this.numberVM = numberVM; if (typeVMselected != null && typeVMselected.getEta() >= 0) { this.numSpotVM = (int) Math.floor(typeVMselected.getEta() * this.numberVM); this.numReservedVM = (int) Math.min(typeVMselected.getR(), (this.numberVM - numSpotVM)); this.numOnDemandVM = Math.max(0, this.numberVM - numSpotVM - numReservedVM); } // update num of containers if (this.numCores != null) { if (xi > 0.0) { this.numberContainers = (int) Math.floor((double) numberVM * xi); } else { this.numberContainers = (int) (numberVM * numCores); } } return this; }
From source file:Main.java
public static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/* ww w. ja v a 2 s.c om*/ if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:net.sf.jtmt.clustering.GeneticClusterer.java
/** * Cluster./*w ww. j a v a 2 s . co m*/ * * @param collection the collection * @return the list */ public List<Cluster> cluster(DocumentCollection collection) { // get initial clusters int k = (int) Math.floor(Math.sqrt(collection.size())); List<Cluster> clusters = new ArrayList<Cluster>(); for (int i = 0; i < k; i++) { Cluster cluster = new Cluster("C" + i); clusters.add(cluster); } if (randomizeData) { collection.shuffle(); } // load it up using mod partitioning, this is P(0) int docId = 0; for (String documentName : collection.getDocumentNames()) { int clusterId = docId % k; clusters.get(clusterId).addDocument(documentName, collection.getDocument(documentName)); docId++; } log.debug("Initial clusters = " + clusters.toString()); // holds previous cluster in the compute loop List<Cluster> prevClusters = new ArrayList<Cluster>(); double prevFitness = 0.0D; int generations = 0; for (;;) { // compute fitness for P(t) double fitness = computeFitness(clusters); // if termination condition achieved, break and return clusters if (prevFitness > fitness) { clusters.clear(); clusters.addAll(prevClusters); break; } // even if termination condition not met, terminate after the // maximum number of generations if (generations > maxGenerations) { break; } // do specified number of crossover operations for this generation for (int i = 0; i < numCrossoversPerMutation; i++) { crossover(clusters, collection, i); generations++; } // followed by a single mutation per generation mutate(clusters, collection); generations++; log.debug("..Intermediate clusters (" + generations + "): " + clusters.toString()); // hold on to previous solution prevClusters.clear(); prevClusters.addAll(clusters); prevFitness = computeFitness(prevClusters); } return clusters; }
From source file:Main.java
public static <T> List<T>[] split(Collection<T> set, int n) { if (set.size() >= n) { @SuppressWarnings("unchecked") List<T>[] arrays = new List[n]; int minSegmentSize = (int) Math.floor(set.size() / (double) n); int start = 0; int stop = minSegmentSize; Iterator<T> it = set.iterator(); for (int i = 0; i < n - 1; i++) { int segmentSize = stop - start; List<T> segment = new ArrayList<>(segmentSize); for (int k = 0; k < segmentSize; k++) { segment.add(it.next());/*from ww w . ja v a 2 s . com*/ } arrays[i] = segment; start = stop; stop += segmentSize; } int segmentSize = set.size() - start; List<T> segment = new ArrayList<>(segmentSize); for (int k = 0; k < segmentSize; k++) { segment.add(it.next()); } arrays[n - 1] = segment; return arrays; } else { throw new IllegalArgumentException("n must not be smaller set size!"); } }
From source file:edu.byu.nlp.stats.RandomGenerators.java
/** * This routine generates a random number between 0 and n inclusive, following * the binomial distribution with probability p and n trials. The routine is * based on the BTPE algorithm, described in: * //from w w w . jav a 2 s.c o m * Voratas Kachitvichyanukul and Bruce W. Schmeiser: * Binomial Random Variate Generation * Communications of the ACM, Volume 31, Number 2, February 1988, pages 216-222. * * Snagged on March 19, 2009 from: * * http://chianti.ucsd.edu/svn/csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/kmeans/KCluster.java * * by Robbie who also converted the uniform() calls to RandomGenerator.nextDouble() * * @param p The probability of a single event. This should be less than or equal to 0.5. * @param n The number of trials * @return An integer drawn from a binomial distribution with parameters (p, n). */ public static int nextBinom(RandomGenerator rnd, int n, double p) { // rah67 March 19, 2007; didn't properly handle the degenerate case if (p == 1.0) return n; double q = 1 - p; if (n * p < 30.0) /* Algorithm BINV */ { double s = p / q; double a = (n + 1) * s; // double r = Math.exp(n*Math.log(q)); /* pow() causes a crash on AIX */ double r = Math.pow(q, n); /* rah67 March 19, 2007 */ int x = 0; double u = rnd.nextDouble(); while (true) { if (u < r) return x; u -= r; x++; r *= (a / x) - s; } } else /* Algorithm BTPE */ { /* Step 0 */ double fm = n * p + p; int m = (int) fm; double p1 = Math.floor(2.195 * Math.sqrt(n * p * q) - 4.6 * q) + 0.5; double xm = m + 0.5; double xl = xm - p1; double xr = xm + p1; double c = 0.134 + 20.5 / (15.3 + m); double a = (fm - xl) / (fm - xl * p); double b = (xr - fm) / (xr * q); double lambdal = a * (1.0 + 0.5 * a); double lambdar = b * (1.0 + 0.5 * b); double p2 = p1 * (1 + 2 * c); double p3 = p2 + c / lambdal; double p4 = p3 + c / lambdar; while (true) { /* Step 1 */ int y; int k; double u = rnd.nextDouble(); double v = rnd.nextDouble(); u *= p4; if (u <= p1) return (int) (xm - p1 * v + u); /* Step 2 */ if (u > p2) { /* Step 3 */ if (u > p3) { /* Step 4 */ y = (int) (xr - Math.log(v) / lambdar); if (y > n) continue; /* Go to step 5 */ v = v * (u - p3) * lambdar; } else { y = (int) (xl + Math.log(v) / lambdal); if (y < 0) continue; /* Go to step 5 */ v = v * (u - p2) * lambdal; } } else { double x = xl + (u - p1) / c; v = v * c + 1.0 - Math.abs(m - x + 0.5) / p1; if (v > 1) continue; /* Go to step 5 */ y = (int) x; } /* Step 5 */ /* Step 5.0 */ k = Math.abs(y - m); if (k > 20 && k < 0.5 * n * p * q - 1.0) { /* Step 5.2 */ double rho = (k / (n * p * q)) * ((k * (k / 3.0 + 0.625) + 0.1666666666666) / (n * p * q) + 0.5); double t = -k * k / (2 * n * p * q); double A = Math.log(v); if (A < t - rho) return y; else if (A > t + rho) continue; else { /* Step 5.3 */ double x1 = y + 1; double f1 = m + 1; double z = n + 1 - m; double w = n - y + 1; double x2 = x1 * x1; double f2 = f1 * f1; double z2 = z * z; double w2 = w * w; if (A > xm * Math.log(f1 / x1) + (n - m + 0.5) * Math.log(z / w) + (y - m) * Math.log(w * p / (x1 * q)) + (13860. - (462. - (132. - (99. - 140. / f2) / f2) / f2) / f2) / f1 / 166320. + (13860. - (462. - (132. - (99. - 140. / z2) / z2) / z2) / z2) / z / 166320. + (13860. - (462. - (132. - (99. - 140. / x2) / x2) / x2) / x2) / x1 / 166320. + (13860. - (462. - (132. - (99. - 140. / w2) / w2) / w2) / w2) / w / 166320.) continue; return y; } } else { /* Step 5.1 */ int i; double s = p / q; double aa = s * (n + 1); double f = 1.0; for (i = m; i < y; f *= (aa / (++i) - s)) ; for (i = y; i < m; f /= (aa / (++i) - s)) ; if (v > f) continue; return y; } } } }
From source file:com.exzogeni.dk.graphics.Bitmaps.java
public static int calculateInSampleSize(BitmapFactory.Options ops, int hwSize) { final int outHeight = ops.outHeight; final int outWidth = ops.outWidth; if (outWidth > hwSize || outHeight > hwSize) { final double ratio = Math.max(Math.round((double) outWidth / (double) hwSize), Math.round((double) outHeight / (double) hwSize)); return ratio > 0 ? (int) Math.pow(2, Math.floor(Math.log(ratio) / LN_2)) : 1; }// w w w. j a va 2s . c o m return 1; }
From source file:GeMSE.GS.Analysis.Clustering.DistanceMatrix.java
public double[][] GetDistanceMatrix(double[][] space, Metrics metric, ClusteringDomains clusteringDomain) { euclideanDistance = new EuclideanDistance(); manhattanDistance = new ManhattanDistance(); earthMoversDistance = new EarthMoversDistance(); chebyshevDistance = new ChebyshevDistance(); canberraDistance = new CanberraDistance(); double[][] rtv = null; int rowCount = space.length; int colCount = space[0].length; int rtvIndex = 0; switch (clusteringDomain) { case Rows://from www .ja va 2s . co m rtv = new double[1][(int) Math.floor((Math.pow(rowCount, 2) - rowCount) / 2f)]; for (int i = 0; i < rowCount - 1; i++) for (int j = i + 1; j < rowCount; j++) // TODO: replace the following mess with the factory method. switch (metric) { case EuclideanDistance: rtv[0][rtvIndex++] = euclideanDistance.compute(space[i], space[j]); break; case ManhattanDistance: rtv[0][rtvIndex++] = manhattanDistance.compute(space[i], space[j]); break; case EarthMoversDistance: rtv[0][rtvIndex++] = earthMoversDistance.compute(space[i], space[j]); break; case ChebyshevDistance: rtv[0][rtvIndex++] = chebyshevDistance.compute(space[i], space[j]); break; case CanberraDistance: rtv[0][rtvIndex++] = canberraDistance.compute(space[i], space[j]); break; case PearsonCorrelationCoefficient: rtv[0][rtvIndex++] = ComputePCC(space[i], space[j]); break; } break; case Columns: rtv = new double[1][(int) Math.floor((Math.pow(colCount, 2) - colCount) / 2f)]; double[] col_i = new double[rowCount]; double[] col_j = new double[rowCount]; for (int i = 0; i < colCount - 1; i++) { for (int j = i + 1; j < colCount; j++) { for (int row = 0; row < rowCount; row++) { col_i[row] = space[row][i]; col_j[row] = space[row][j]; } // TODO: Replace the following mess with the factory pattern. switch (metric) { case EuclideanDistance: rtv[0][rtvIndex++] = euclideanDistance.compute(col_i, col_j); break; case ManhattanDistance: rtv[0][rtvIndex++] = manhattanDistance.compute(col_i, col_j); break; case EarthMoversDistance: rtv[0][rtvIndex++] = earthMoversDistance.compute(col_i, col_j); break; case ChebyshevDistance: rtv[0][rtvIndex++] = chebyshevDistance.compute(col_i, col_j); break; case CanberraDistance: rtv[0][rtvIndex++] = canberraDistance.compute(col_i, col_j); break; case PearsonCorrelationCoefficient: rtv[0][rtvIndex++] = ComputePCC(col_i, col_j); break; } } } break; } return rtv; }
From source file:com.garethahealy.quotalimitsgenerator.cli.parsers.CLIOptions.java
public QuotaLimitModel calculate() { Pair<Integer, Integer> instanceTypeLine = lines.get(instanceType); Integer instanceCoreInMillis = instanceTypeLine.getLeft() * 1000; Integer instanceMemoryInMb = instanceTypeLine.getRight() * 1000; QuotaLimitModel quotaLimitModel = new QuotaLimitModel(); quotaLimitModel.setInstanceType(instanceType); quotaLimitModel.setQualityOfService(qualityOfService); quotaLimitModel.setAllocatableNodeCores(instanceCoreInMillis); quotaLimitModel.setAllocatableNodeMemory(instanceMemoryInMb); quotaLimitModel/* w w w . j a v a2 s. co m*/ .setMaxPods(Double.valueOf(Math.floor((instanceMemoryInMb / 500) * nodeWorkerCount)).intValue()); quotaLimitModel.setTerminatingPodCPU(Double.valueOf(Math.floor(instanceCoreInMillis * 0.5)).intValue()); quotaLimitModel.setTerminatingPodMemory(Double.valueOf(Math.floor(instanceMemoryInMb * 0.5)).intValue()); quotaLimitModel.setMaxOrNotTerminatingPodLimitCPU(instanceCoreInMillis * requestRatio); quotaLimitModel.setMaxOrNotTerminatingPodLimitMemory(instanceMemoryInMb * requestRatio); quotaLimitModel.setMaxOrNotTerminatingPodRequestCPU(instanceCoreInMillis); quotaLimitModel.setMaxOrNotTerminatingPodRequestMemory(instanceMemoryInMb); quotaLimitModel.setIsTeamNamespace(isTeamNamespace); quotaLimitModel.setCpuRequestRatio(requestRatio); quotaLimitModel.setMemoryRequestRatio(requestRatio); quotaLimitModel.setOutputPath(outputPath); return quotaLimitModel; }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java
protected double b_flat(double y, double A, double B, double C) { double tmp1 = min_double(0.0, Math.floor(y - B)) * A * (B - y) / B; double tmp2 = min_double(0.0, Math.floor(C - y)) * (1.0 - A) * (y - C) / (1.0 - C); return correct_to_01(A + tmp1 - tmp2, EPSILON); }