Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

In this page you can find the example usage for java.lang Math ceil.

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:de.cebitec.readXplorer.util.GeneralUtils.java

/**
 * Calculates the percentage increase of value 1 to value 2. In case value1 is 0, 
 * the percentage is set to 1.5 times the absolute difference as a weight factor.
 * @param value1 smaller value/*from  ww w  .  ja  v a  2  s . c o m*/
 * @param value2 larger value
 * @return the percentage increase 
 */
public static int calculatePercentageIncrease(int value1, int value2) {
    int percentDiff;
    if (value1 == 0) {
        int absoluteDiff = value2 - value1;
        percentDiff = (int) (absoluteDiff * 1.5); //weight factor
    } else {
        percentDiff = (int) Math.ceil(((double) value2 / (double) value1) * 100.0) - 100;
    }
    return percentDiff;
}

From source file:edu.northwestern.bioinformatics.studycalendar.web.template.StudySegmentTemplate.java

public StudySegmentTemplate(StudySegment studySegment) {
    this.studySegment = studySegment;
    DayRange range = studySegment.getDayRange();
    int monthCount = (int) Math.ceil(((double) range.getDayCount()) / MONTH_LENGTH);
    months = new ArrayList<Month>(monthCount);
    while (months.size() < monthCount) {
        months.add(new Month(range.getStartDay() + MONTH_LENGTH * months.size()));
    }//from   w ww . java2  s.c o m
}

From source file:Main.java

private static Rect getBitmapRectCenterInsideHelper(int bitmapWidth, int bitmapHeight, int viewWidth,
        int viewHeight) {
    double viewToBitmapWidthRatio = 1.0D / 0.0;
    double viewToBitmapHeightRatio = 1.0D / 0.0;
    if (viewWidth < bitmapWidth) {
        viewToBitmapWidthRatio = (double) viewWidth / (double) bitmapWidth;
    }//from w  w w.j  a va2s . c  o m

    if (viewHeight < bitmapHeight) {
        viewToBitmapHeightRatio = (double) viewHeight / (double) bitmapHeight;
    }

    double resultWidth;
    double resultHeight;
    if (viewToBitmapWidthRatio == 1.0D / 0.0 && viewToBitmapHeightRatio == 1.0D / 0.0) {
        resultHeight = (double) bitmapHeight;
        resultWidth = (double) bitmapWidth;
    } else if (viewToBitmapWidthRatio <= viewToBitmapHeightRatio) {
        resultWidth = (double) viewWidth;
        resultHeight = (double) bitmapHeight * resultWidth / (double) bitmapWidth;
    } else {
        resultHeight = (double) viewHeight;
        resultWidth = (double) bitmapWidth * resultHeight / (double) bitmapHeight;
    }

    int resultX;
    int resultY;
    if (resultWidth == (double) viewWidth) {
        resultX = 0;
        resultY = (int) Math.round(((double) viewHeight - resultHeight) / 2.0D);
    } else if (resultHeight == (double) viewHeight) {
        resultX = (int) Math.round(((double) viewWidth - resultWidth) / 2.0D);
        resultY = 0;
    } else {
        resultX = (int) Math.round(((double) viewWidth - resultWidth) / 2.0D);
        resultY = (int) Math.round(((double) viewHeight - resultHeight) / 2.0D);
    }

    Rect result = new Rect(resultX, resultY, resultX + (int) Math.ceil(resultWidth),
            resultY + (int) Math.ceil(resultHeight));
    return result;
}

From source file:de.iew.framework.security.access.RequestMapbuilder.java

/**
 * Builds a spring security compatibly request map ({@link java.util.LinkedHashMap} data structure.
 *
 * @param requestMapEntries the request map entries
 * @return the request map//from  www. java 2s .c om
 */
public static LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> buildRequestConfigAttributeMap(
        Collection<RequestMapEntry> requestMapEntries) {
    // Calculate the initial capacity for our LinkedHashMap
    float requestmapEntrySize = (float) requestMapEntries.size();
    int mapInitialCapacity = (int) Math.ceil(requestmapEntrySize / REQUEST_MAP_LOAD_FACTOR);

    if (log.isDebugEnabled()) {
        log.debug("Initialisiere die LinkedHashMap mit einer Kapazitt von " + mapInitialCapacity
                + " Eintrgen.");
    }

    LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>(
            mapInitialCapacity);

    for (RequestMapEntry requestMapEntry : requestMapEntries) {
        requestMap.put(requestMapEntry.getRequestMatcher(), requestMapEntry.getConfigAttributes());
    }

    return requestMap;
}

From source file:brickhouse.udf.bloom.BloomFactory.java

public static Filter NewBloomInstance(double c, int n, int k) {
    LOG.info("Creating new Bloom filter C = " + c + " N =  " + n + " K = " + k);
    BloomFilter dbf = new BloomFilter((int) Math.ceil(c * n), k, DEFAULT_HASH_TYPE);
    return dbf;/*  w w w  .  j a v a  2s .c o m*/
}

From source file:info.ajaxplorer.client.http.AjxpFileBody.java

public void chunkIntoPieces(int chunkSize) {
    this.chunkSize = chunkSize;
    totalChunks = (int) Math.ceil((float) this.getFile().length() / (float) this.chunkSize);
    if (((float) this.getFile().length() % (float) this.chunkSize) == 0) {
        lastChunkSize = chunkSize;//  w w  w  .j a v a 2 s  . c  o m
    } else {
        lastChunkSize = (int) getFile().length() - (this.chunkSize * (totalChunks - 1));
    }
}

From source file:br.unicamp.ic.recod.gpsi.applications.gpsiOVOClassifierFromFiles.java

public gpsiOVOClassifierFromFiles(String datasetPath, gpsiDatasetReader datasetReader, Byte[] classLabels,
        String outputPath, String programsPath, double errorScore) throws Exception {
    super(datasetPath, datasetReader, classLabels, outputPath, errorScore);

    int nClasses, i, j;
    gpsiClassifier[][] classifiers;/*from w ww . j a  v  a  2s.  co m*/
    File dir = new File(programsPath + "5/");

    BufferedReader reader;
    File[] files = dir.listFiles((File dir1, String name) -> name.toLowerCase().endsWith(".program"));

    nClasses = (int) Math.ceil(Math.sqrt(2 * files.length));
    classifiers = new gpsiClassifier[nClasses - 1][];

    String[] labels;

    for (i = 0; i < classifiers.length; i++)
        classifiers[i] = new gpsiClassifier[classifiers.length - i];

    for (File program : files) {
        reader = new BufferedReader(new FileReader(program));
        labels = program.getName().split("[_.]");
        i = Integer.parseInt(labels[0]) - 1;
        j = Integer.parseInt(labels[1]) - i - 2;
        classifiers[i][j] = new gpsiClassifier(
                new gpsiScalarSpectralIndexDescriptor(
                        new gpsiStringParserVoxelCombiner(null, reader.readLine())),
                new gpsi1NNToMomentScalarClassificationAlgorithm(new Mean()));
        reader.close();
    }

    ensemble = new gpsiOVOEnsembleMethod(classifiers);

}

From source file:arena.utils.Base64.java

/**
 * Encodes a string into base 64 format equals-terminated
 *//*  w ww.  j a va2s. c  om*/
public static String encodeBase64(byte[] inBytes) {
    char[] outChars = new char[(int) Math.ceil(inBytes.length / 3f) * 4];
    LogFactory.getLog(Base64.class)
            .debug("Base64 encoding: in=" + inBytes.length + " bytes, out=" + outChars.length + " chars");
    encodeBase64(inBytes, outChars);

    return new String(outChars);
}

From source file:Main.java

private 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;
    }//from   w w  w  .ja v a2  s . c  o m

    if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
        return 1;
    } else if (minSideLength == -1) {
        return lowerBound;
    } else {
        return upperBound;
    }
}

From source file:eu.amidst.core.inference.MAPInferenceExperiments.java

private static Assignment randomEvidence(long seed, double evidenceRatio, BayesianNetwork bn)
        throws UnsupportedOperationException {

    if (evidenceRatio <= 0 || evidenceRatio >= 1) {
        throw new UnsupportedOperationException("Error: invalid ratio");
    }//from   w w  w  .j  ava  2  s .  co  m

    int numVariables = bn.getVariables().getNumberOfVars();

    Random random = new Random(seed); //1823716125
    int numVarEvidence = (int) Math.ceil(numVariables * evidenceRatio); // Evidence on 20% of variables
    //numVarEvidence = 0;
    //List<Variable> varEvidence = new ArrayList<>(numVarEvidence);
    double[] evidence = new double[numVarEvidence];
    Variable aux;
    HashMapAssignment assignment = new HashMapAssignment(numVarEvidence);

    int[] indexesEvidence = new int[numVarEvidence];
    //indexesEvidence[0]=varInterest.getVarID();
    //if (Main.VERBOSE) System.out.println(variable.getVarID());

    if (Main.VERBOSE)
        System.out.println("Evidence:");
    for (int k = 0; k < numVarEvidence; k++) {
        int varIndex = -1;
        do {
            varIndex = random.nextInt(bn.getNumberOfVars());
            //if (Main.VERBOSE) System.out.println(varIndex);
            aux = bn.getVariables().getVariableById(varIndex);

            double thisEvidence;
            if (aux.isMultinomial()) {
                thisEvidence = random.nextInt(aux.getNumberOfStates());
            } else {
                thisEvidence = random.nextGaussian();
            }
            evidence[k] = thisEvidence;

        } while (ArrayUtils.contains(indexesEvidence, varIndex));

        indexesEvidence[k] = varIndex;
        //if (Main.VERBOSE) System.out.println(Arrays.toString(indexesEvidence));
        if (Main.VERBOSE)
            System.out.println("Variable " + aux.getName() + " = " + evidence[k]);

        assignment.setValue(aux, evidence[k]);
    }
    if (Main.VERBOSE)
        System.out.println();
    return assignment;
}