List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:com.intellectualcrafters.plot.commands.Inbox.java
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) { if (oldComments == null || oldComments.size() == 0) { MainUtil.sendMessage(player, C.INBOX_EMPTY); return;/*from w w w. j av a 2s . co m*/ } PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]); if (page < 0) { page = 0; } // Get the total pages // int totalPages = ((int) Math.ceil(12 * final int totalPages = (int) Math.ceil(comments.length / 12); if (page > totalPages) { page = totalPages; } // Only display 12 per page int max = (page * 12) + 12; if (max > comments.length) { max = comments.length; } final StringBuilder string = new StringBuilder(); string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("plot", "comment").replaceAll("%cur", page + 1 + "") .replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n"); PlotComment c; // This might work xD for (int x = (page * 12); x < max; x++) { c = comments[x]; String color; if (player.getName().equals(c.senderName)) { color = "&a"; } else { color = "&7"; } string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n"); } MainUtil.sendMessage(player, string.toString()); }
From source file:com.linkedin.pinot.core.io.writer.impl.v1.FixedBitMultiValueWriter.java
public FixedBitMultiValueWriter(File file, int numDocs, int totalNumValues, int columnSizeInBits) throws Exception { float averageValuesPerDoc = totalNumValues / numDocs; this.docsPerChunk = (int) (Math.ceil(PREFERRED_NUM_VALUES_PER_CHUNK / averageValuesPerDoc)); this.numChunks = (numDocs + docsPerChunk - 1) / docsPerChunk; chunkOffsetHeaderSize = numChunks * SIZE_OF_INT * NUM_COLS_IN_HEADER; bitsetSize = (totalNumValues + 7) / 8; rawDataSize = ((long) totalNumValues * columnSizeInBits + 7) / 8; totalSize = chunkOffsetHeaderSize + bitsetSize + rawDataSize; raf = new RandomAccessFile(file, "rw"); chunkOffsetsBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, 0, chunkOffsetHeaderSize, file, this.getClass().getSimpleName() + " chunkOffsetsBuffer"); bitsetBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, chunkOffsetHeaderSize, bitsetSize, file, this.getClass().getSimpleName() + " bitsetBuffer"); rawDataBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, chunkOffsetHeaderSize + bitsetSize, rawDataSize, file, this.getClass().getSimpleName() + " rawDataBuffer"); chunkOffsetsWriter = new FixedByteSingleValueMultiColWriter(chunkOffsetsBuffer, numDocs, NUM_COLS_IN_HEADER, new int[] { SIZE_OF_INT }); customBitSet = CustomBitSet.withByteBuffer(bitsetSize, bitsetBuffer); rawDataWriter = new FixedBitSingleValueMultiColWriter(rawDataBuffer, totalNumValues, 1, new int[] { columnSizeInBits }); }
From source file:bb.mcmc.analysis.HeidelbergConvergeStat.java
@Override protected double calculateEachStat(String key) { double[] t = traceValues.get(key); t = Arrays.copyOfRange(t, 0, 48); int length = t.length; System.out.println(length + "\t" + Arrays.toString(t) + "\t" + length); // length=13578; // t = new double[length]; int indexStart = (int) Math.ceil(length / 2.0 - 1); // System.out.println(length +"\t"+ indexStart); double[] Y = Arrays.copyOfRange(t, indexStart, length); double S0 = ConvergeStatUtils.spectrum0(Y); System.out.println(Y.length + "\t" + indexStart + "\t" + S0 + "\t" + Arrays.toString(Y)); final double oneTenthLength = length / 10.0; for (int i = 0; i < 5; i++) { int startVec = (int) Math.ceil(0 + i * oneTenthLength); Y = Arrays.copyOfRange(t, startVec, length); int n = Y.length; double ybar = DiscreteStatistics.mean(Y); double nS0 = n * S0; double[] B = new double[n]; double[] Bsq = new double[n]; B[0] = Y[0] - ybar;//from w w w. ja v a2 s.c o m for (int j = 1; j < B.length; j++) { B[j] = B[j - 1] + Y[j] - ybar; } for (int j = 0; j < Bsq.length; j++) { Bsq[j] = B[j] * B[j] / nS0; } double ind = StatUtils.sum(Bsq) / n; // Bsq <- (B * B)/(n * S0) System.out.println(n + "\t" + S0 + "\t" + StatUtils.sum(B) + "\t" + StatUtils.sum(Bsq) + "\t" + ind); CramerVonMisesDist dist = new CramerVonMisesDist(2); System.out.println(dist.barF(ind)); System.out.println(dist.cdf(ind)); System.out.println(dist.density(ind)); System.out.println(dist.density(ind)); // The Cramer-von Mises Distribution boolean ind2 = pcramer(ind); // TODO: if (ind2) { break; } // int output_list[] = new int[input_list.length]; // long startTime = System.currentTimeMillis(); // for (int i = 1; i < input_list.length; i++) // output_list[i] = output_list[i-1] + input_list[i]; // long endTime = System.currentTimeMillis(); // System.out.println(Y.length +"\t"+ ybar); // for (i in seq(along = start.vec)) { // Y <- window(Y, start = start.vec[i]) // n <- niter(Y) // ybar <- mean(Y) // B <- cumsum(Y) - ybar * (1:n) // Bsq <- (B * B)/(n * S0) // I <- sum(Bsq)/n // if (converged <- !is.na(I) && pcramer(I) < 1 - pvalue) // break // } } double S0ci = ConvergeStatUtils.spectrum0(Y); double halfwidth = 1.96 * Math.sqrt(S0ci / Y.length); // System.out.println(oneTenthLength +"\t"+ Arrays.toString(startVec)); // final double[] t = traceValues.get(key); // final int length = t.length; // final int indexEnd = (int) Math.ceil(length * frac1); // // final double[] dStart = Arrays.copyOfRange(t, 0, indexEnd); // final double[] dEnd = Arrays.copyOfRange(t, indexStart, length); // return 0; }
From source file:de.mat.utils.pdftools.PdfSort4Print.java
public static void sortPdfPages(String pdfSourceFile, String pdfDestinationFile, int perPage) throws Exception { PdfImportedPage page = null;/*from www. j a v a2s . c om*/ if (perPage != 2 && perPage != 4) { throw new IllegalArgumentException( "Sorry, perPage must only be " + "2 or 4. All other is not implemented yet :-("); } // ####### // # fill to odd pagecount // ####### // create reader PdfReader readerOrig = new PdfReader(pdfSourceFile); // calc data int countPage = readerOrig.getNumberOfPages(); int blaetter = new Double(Math.ceil((countPage + 0.0) / perPage / 2)).intValue(); int zielPages = (blaetter * perPage * 2) - countPage; if (LOGGER.isInfoEnabled()) LOGGER.info("CurPages: " + countPage + " Blaetter:" + blaetter + " AddPage:" + zielPages); // add sites String oddFile = pdfDestinationFile + ".filled.pdf"; PdfStamper stamper = new PdfStamper(readerOrig, new FileOutputStream(oddFile)); // add empty pages for (int i = 1; i <= zielPages; i++) { if (LOGGER.isDebugEnabled()) LOGGER.debug("addEmptyPage: " + i); stamper.insertPage(readerOrig.getNumberOfPages() + 1, readerOrig.getPageSizeWithRotation(1)); } stamper.close(); readerOrig.close(); // ######## // # read new odd document and sort pages // ######## // step 1: create new reader PdfReader readerOdd = new PdfReader(oddFile); // create writerSorted String sortedFile = pdfDestinationFile; Document documentSorted = new Document(readerOrig.getPageSizeWithRotation(1)); PdfCopy writerSorted = new PdfCopy(documentSorted, new FileOutputStream(sortedFile)); documentSorted.open(); // add pages in calced order List<Integer> lstPageNr = new ArrayList<Integer>(); int pageCount = readerOdd.getNumberOfPages(); int startseite = 1; for (int i = 1; i <= blaetter; i++) { if (perPage == 2) { startseite = ((i - 1) * perPage) + 1; if (LOGGER.isDebugEnabled()) LOGGER.debug("Blatt:" + i + " Startseite: " + startseite); // front top lstPageNr.add(new Integer(pageCount - startseite + 1)); // front bottom lstPageNr.add(new Integer(startseite)); // back top lstPageNr.add(new Integer(startseite + 1)); // back bottom lstPageNr.add(new Integer(pageCount - startseite + 1 - 1)); } else if (perPage == 4) { startseite = ((i - 1) * perPage) + 1; if (LOGGER.isDebugEnabled()) LOGGER.debug("Blatt:" + i + " Startseite: " + startseite); // front top left lstPageNr.add(new Integer(pageCount - startseite + 1)); // front top right lstPageNr.add(new Integer(startseite)); // front bottom lefts lstPageNr.add(new Integer(pageCount - startseite + 1 - 2)); // front bottom right lstPageNr.add(new Integer(startseite + 2)); // back top left lstPageNr.add(new Integer(startseite + 1)); // back top right lstPageNr.add(new Integer(pageCount - startseite + 1 - 1)); // back bottom left lstPageNr.add(new Integer(startseite + 1 + 2)); // back bottom right lstPageNr.add(new Integer(pageCount - startseite + 1 - 1 - 2)); } else { throw new IllegalArgumentException( "Sorry, perPage must " + "only be 2 or 4. All other is not implemented yet :-("); } } if (LOGGER.isInfoEnabled()) LOGGER.info("Seiten:" + lstPageNr.size()); // copy pages for (Iterator iter = lstPageNr.iterator(); iter.hasNext();) { int pageNum = ((Integer) iter.next()).intValue(); if (LOGGER.isDebugEnabled()) LOGGER.debug("addSortPage: " + pageNum); page = writerSorted.getImportedPage(readerOdd, pageNum); writerSorted.addPage(page); } // close everything documentSorted.close(); writerSorted.close(); readerOdd.close(); // delete Tmp-File File file = new File(oddFile); file.delete(); }
From source file:jext2.DataStructureAccessProvider.java
protected DataStructureAccessProvider(int initialCapacity) { table = new ConcurrentHashMap<KEY, Data>(initialCapacity, 0.75f, (int) (Math.ceil(FuseJExt2.numberOfThreads * 1.5f))); }
From source file:Main.java
/** * Draws a single arrow head//from ww w.java2 s .c o m * * @param aG * the canvas to draw on; * @param aXpos * the X position of the arrow head; * @param aYpos * the (center) Y position of the arrow head; * @param aFactor * +1 to have a left-facing arrow head, -1 to have a right-facing * arrow head; * @param aArrowWidth * the total width of the arrow head; * @param aArrowHeight * the total height of the arrow head. */ public static final void drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor, final int aArrowWidth, final int aArrowHeight) { final double halfHeight = aArrowHeight / 2.0; final int x1 = aXpos + (aFactor * aArrowWidth); final int y1 = (int) Math.ceil(aYpos - halfHeight); final int y2 = (int) Math.floor(aYpos + halfHeight); final Polygon arrowHead = new Polygon(); arrowHead.addPoint(aXpos, aYpos); arrowHead.addPoint(x1, y1); arrowHead.addPoint(x1, y2); aG.fill(arrowHead); }
From source file:com.duy.pascal.interperter.libraries.math.MathLib.java
@PascalMethod(description = "Round to the nearest bigger int64 value") public long Ceil64(double d) { return (long) Math.ceil(d); }
From source file:Thumbnail.java
/** * Reads an image in a file and creates a thumbnail in another file. * largestDimension is the largest dimension of the thumbnail, the other dimension is scaled accordingly. * Utilises weighted stepping method to gradually reduce the image size for better results, * i.e. larger steps to start with then smaller steps to finish with. * Note: always writes a JPEG because GIF is protected or something - so always make your outFilename end in 'jpg'. * PNG's with transparency are given white backgrounds *///from w ww. j a v a 2s .c o m public String createThumbnail(String inFilename, String outFilename, int largestDimension) { try { double scale; int sizeDifference, originalImageLargestDim; if (!inFilename.endsWith(".jpg") && !inFilename.endsWith(".jpeg") && !inFilename.endsWith(".gif") && !inFilename.endsWith(".png")) { return "Error: Unsupported image type, please only either JPG, GIF or PNG"; } else { Image inImage = Toolkit.getDefaultToolkit().getImage(inFilename); if (inImage.getWidth(null) == -1 || inImage.getHeight(null) == -1) { return "Error loading file: \"" + inFilename + "\""; } else { //find biggest dimension if (inImage.getWidth(null) > inImage.getHeight(null)) { scale = (double) largestDimension / (double) inImage.getWidth(null); sizeDifference = inImage.getWidth(null) - largestDimension; originalImageLargestDim = inImage.getWidth(null); } else { scale = (double) largestDimension / (double) inImage.getHeight(null); sizeDifference = inImage.getHeight(null) - largestDimension; originalImageLargestDim = inImage.getHeight(null); } //create an image buffer to draw to BufferedImage outImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); //arbitrary init so code compiles Graphics2D g2d; AffineTransform tx; if (scale < 1.0d) //only scale if desired size is smaller than original { int numSteps = sizeDifference / 100; int stepSize = sizeDifference / numSteps; int stepWeight = stepSize / 2; int heavierStepSize = stepSize + stepWeight; int lighterStepSize = stepSize - stepWeight; int currentStepSize, centerStep; double scaledW = inImage.getWidth(null); double scaledH = inImage.getHeight(null); if (numSteps % 2 == 1) //if there's an odd number of steps centerStep = (int) Math.ceil((double) numSteps / 2d); //find the center step else centerStep = -1; //set it to -1 so it's ignored later Integer intermediateSize = originalImageLargestDim, previousIntermediateSize = originalImageLargestDim; Integer calculatedDim; for (Integer i = 0; i < numSteps; i++) { if (i + 1 != centerStep) //if this isn't the center step { if (i == numSteps - 1) //if this is the last step { //fix the stepsize to account for decimal place errors previously currentStepSize = previousIntermediateSize - largestDimension; } else { if (numSteps - i > numSteps / 2) //if we're in the first half of the reductions currentStepSize = heavierStepSize; else currentStepSize = lighterStepSize; } } else //center step, use natural step size { currentStepSize = stepSize; } intermediateSize = previousIntermediateSize - currentStepSize; scale = (double) intermediateSize / (double) previousIntermediateSize; scaledW = (int) scaledW * scale; scaledH = (int) scaledH * scale; outImage = new BufferedImage((int) scaledW, (int) scaledH, BufferedImage.TYPE_INT_RGB); g2d = outImage.createGraphics(); g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); tx = new AffineTransform(); tx.scale(scale, scale); g2d.drawImage(inImage, tx, null); g2d.dispose(); inImage = new ImageIcon(outImage).getImage(); previousIntermediateSize = intermediateSize; } } else { //just copy the original outImage = new BufferedImage(inImage.getWidth(null), inImage.getHeight(null), BufferedImage.TYPE_INT_RGB); g2d = outImage.createGraphics(); g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); tx = new AffineTransform(); tx.setToIdentity(); //use identity matrix so image is copied exactly g2d.drawImage(inImage, tx, null); g2d.dispose(); } //JPEG-encode the image and write to file. OutputStream os = new FileOutputStream(outFilename); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os); encoder.encode(outImage); os.close(); } } } catch (Exception ex) { String errorMsg = ""; errorMsg += "<br>Exception: " + ex.toString(); errorMsg += "<br>Cause = " + ex.getCause(); errorMsg += "<br>Stack Trace = "; StackTraceElement stackTrace[] = ex.getStackTrace(); for (int traceLine = 0; traceLine < stackTrace.length; traceLine++) { errorMsg += "<br>" + stackTrace[traceLine]; } return errorMsg; } return ""; //success }
From source file:com.yahoo.egads.models.adm.DBScanModel.java
@Override public void tune(DataSequence observedSeries, DataSequence expectedSeries, IntervalSequence anomalySequence) throws Exception { // Compute the time-series of errors. HashMap<String, ArrayList<Float>> allErrors = aes.initAnomalyErrors(observedSeries, expectedSeries); List<IdentifiedDoublePoint> points = new ArrayList<IdentifiedDoublePoint>(); EuclideanDistance ed = new EuclideanDistance(); int n = observedSeries.size(); for (int i = 0; i < n; i++) { double[] d = new double[(aes.getIndexToError().keySet()).size()]; for (int e = 0; e < (aes.getIndexToError().keySet()).size(); e++) { d[e] = allErrors.get(aes.getIndexToError().get(e)).get(i); }//from w ww . j a v a2s . c om points.add(new IdentifiedDoublePoint(d, i)); } double sum = 0.0; double count = 0.0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { sum += ed.compute(points.get(i).getPoint(), points.get(j).getPoint()); count++; } } eps = ((double) this.sDAutoSensitivity) * (sum / count); minPoints = ((int) Math.ceil(((double) this.amntAutoSensitivity) * ((double) n))); dbscan = new DBSCANClusterer<IdentifiedDoublePoint>(eps, minPoints); }