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:org.rimudb.util.LRUCache2.java

 /**
 * Creates a new LRU cache./*from  w  ww  .j  a va2 s  .  co m*/
 * 
 * @param cacheSize The maximum number of entries that will be kept in this cache.
 */
public LRUCache2(int cacheSize) {
   this.cacheSize = cacheSize;
   int hashTableCapacity = (int) Math.ceil(cacheSize / hashTableLoadFactor) + 1;
      
   map = new LinkedHashMap<K, V>(hashTableCapacity, hashTableLoadFactor, true) {
      private static final long serialVersionUID = 1;

      @Override
      protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
         return size() > LRUCache2.this.cacheSize;
      }
   };
}

From source file:juicebox.tools.utils.juicer.arrowhead.BlockBuster.java

/**
 * Actual Arrowhead algorithm - should be called separately for each chromosome
 *
 * @return contact domain list and scores for given list/control
 *///w  w w  . j  a v  a  2  s  .  c om
public static void run(int chrIndex, String chrName, int chrLength, int resolution, int matrixWidth,
        MatrixZoomData zd, NormalizationType norm, ArrowheadScoreList list, ArrowheadScoreList control,
        Feature2DList contactDomainsGenomeWide, Feature2DList contactDomainListScoresGenomeWide,
        Feature2DList contactDomainControlScoresGenomeWide) {

    // used for sliding window across diagonal
    int increment = matrixWidth / 2;
    int maxDataLengthAtResolution = (int) Math.ceil(((double) chrLength) / resolution);

    try {
        // get large number of blocks (lower confidence)
        CumulativeBlockResults results = null;
        for (double signThreshold = 0.4; signThreshold >= 0; signThreshold -= 0.1) {
            results = callSubBlockbuster(zd, maxDataLengthAtResolution, Double.NaN, signThreshold, matrixWidth,
                    increment, list, control, norm, resolution);
            if (results.getCumulativeResults().size() > 0) {
                break;
            }
        }

        // high variance threshold, fewer blocks, high confidence
        CumulativeBlockResults highConfidenceResults = callSubBlockbuster(zd, maxDataLengthAtResolution, 0.2f,
                0.5f, matrixWidth, increment, new ArrowheadScoreList(resolution),
                new ArrowheadScoreList(resolution), norm, resolution);

        List<HighScore> uniqueBlocks = orderedSetDifference(results.getCumulativeResults(),
                highConfidenceResults.getCumulativeResults());

        // remove the blocks that are small
        List<HighScore> filteredUniqueBlocks = filterBlocksBySize(uniqueBlocks, 60);
        appendNonConflictingBlocks(highConfidenceResults.getCumulativeResults(), filteredUniqueBlocks);

        // merge the high/low confidence results
        results.setCumulativeResults(highConfidenceResults.getCumulativeResults());
        results.mergeScores();

        // prior to this point, everything should be in terms of i,j indices in a binned matrix
        results.scaleIndicesByResolution(resolution);

        // if any contact domains are found
        if (results.getCumulativeResults().size() > 0) {
            if (HiCGlobals.printVerboseComments) {
                System.out.println("Initial # of contact domains: " + results.getCumulativeResults().size());
            }

            // merge/bin domains in very close proximity
            List<HighScore> binnedScores = binScoresByDistance(results.getCumulativeResults(), 5 * resolution);
            binnedScores = binScoresByDistance(binnedScores, 10 * resolution);
            Collections.sort(binnedScores, Collections.reverseOrder());

            // convert to Feature2DList format
            Feature2DList blockResults = Feature2DParser.parseHighScoreList(chrIndex, chrName, resolution,
                    binnedScores);
            Feature2DList blockResultListScores = Feature2DParser.parseArrowheadScoreList(chrIndex, chrName,
                    results.getCumulativeInternalList());
            Feature2DList blockResultControlScores = Feature2DParser.parseArrowheadScoreList(chrIndex, chrName,
                    results.getCumulativeInternalControl());

            // add results to genome-wide accumulator
            contactDomainsGenomeWide.add(blockResults);
            contactDomainListScoresGenomeWide.add(blockResultListScores);
            contactDomainControlScoresGenomeWide.add(blockResultControlScores);
        } else {
            if (HiCGlobals.printVerboseComments) {
                System.out.println("No contact domains found for chromosome " + chrName);
            }
        }
    } catch (IOException e) {
        System.err.println("Data not available for this chromosome.");
    }
}

From source file:ImageProc.java

public static float[][] colormapJet(int nClass) {
    int n;//from www . java  2s  . c o m
    n = (int) Math.ceil((float) nClass / 4);
    ArrayRealVector u, r, g, b;
    RealVector R, G, B;

    u = new ArrayRealVector(3 * n - 1);
    for (int i = 0; i < n; i++) {
        u.setEntry(i, (i + 1.0) / n);
        u.setEntry(u.getDimension() - i - 1, (i + 1.0) / n);
    }
    u.setSubVector(n, new ArrayRealVector(n, 1));

    g = new ArrayRealVector(u.getDimension());

    float m;
    m = (float) Math.ceil((float) n / 2);
    if (nClass % 4 == 1)
        m = m - 1;

    for (int i = 0; i < g.getDimension(); i++) {
        g.setEntry(i, (i + 1 + m));
    }

    r = g.add(new ArrayRealVector(g.getDimension(), n));
    b = g.subtract(new ArrayRealVector(g.getDimension(), n));

    R = new ArrayRealVector();
    G = new ArrayRealVector();
    B = new ArrayRealVector();

    for (int i = 0; i < r.getDimension(); i++) {
        if (r.getEntry(i) <= nClass)
            R = R.append(r.getEntry(i));
    }

    for (int i = 0; i < g.getDimension(); i++) {
        if (g.getEntry(i) <= nClass)
            G = G.append(g.getEntry(i));
    }

    for (int i = 0; i < b.getDimension(); i++) {
        if (b.getEntry(i) >= 1)
            B = B.append(b.getEntry(i));
    }

    float[][] J = new float[nClass][3];
    int index;
    for (int i = 0; i < R.getDimension(); i++) {
        index = (int) R.getEntry(i);
        J[index - 1][0] = (float) u.getEntry(i);
    }

    for (int i = 0; i < G.getDimension(); i++) {
        index = (int) G.getEntry(i);
        J[index - 1][1] = (float) u.getEntry(i);
    }

    for (int i = u.getDimension() - B.getDimension(), j = 0; i < u.getDimension(); i++, j++) {
        index = (int) B.getEntry(j);
        J[index - 1][2] = (float) u.getEntry(i);
    }

    /*
    System.out.println("\nRGB Matrix:");
    for(int i=0;i<nClass;i++){
    for(int j=0;j<3;j++){
        System.out.print(J[i][j]+"\t");
    }
    System.out.println();
    }
    */
    return J;
}

From source file:Util.java

public static double median(double[] values) {
    double[] v = new double[values.length];
    double median = Double.NaN;
    if (v == null || v.length == 0) {
        throw new IllegalArgumentException("The data array either is null or does not contain any data.");
    } else if (v.length == 1) {
        median = v[0];/*from   w w w.j a  v a  2  s .  co  m*/
    } else {
        System.arraycopy(values, 0, v, 0, values.length);
        Arrays.sort(v);
        if (isEven(v.length)) {
            int i = (int) Math.ceil(v.length / 2D);
            double n1 = v[i];
            double n0 = v[i - 1];
            median = (n0 + n1) / 2;
        } else {
            median = v[v.length / 2];
        }
    }

    return median;

}

From source file:com.wuliu.biz.util.WuliuWholeOrderDetailUtil.java

public static WuliuWholeOrderDetailModel builduliuWholeDetailModel(
        WuliuOrderDetailModel wuliuOrderDetailModel) {
    WuliuWholeOrderDetailModel ret = new WuliuWholeOrderDetailModel();
    ret.setCount(wuliuOrderDetailModel.getCount());
    ret.setHeight(wuliuOrderDetailModel.getHeight());
    ret.setId(wuliuOrderDetailModel.getId());
    ret.setLength(wuliuOrderDetailModel.getLength());
    ret.setMainOrderId(wuliuOrderDetailModel.getMainOrderId());
    ret.setStatus(wuliuOrderDetailModel.getStatus());
    ret.setWeight(wuliuOrderDetailModel.getWeight());
    ret.setWidth(wuliuOrderDetailModel.getWidth());
    ret.setTotalVolumn(wuliuOrderDetailModel.getHeight() * wuliuOrderDetailModel.getLength()
            * wuliuOrderDetailModel.getWidth() * wuliuOrderDetailModel.getCount());
    ret.setTotalWeight(wuliuOrderDetailModel.getWeight() * wuliuOrderDetailModel.getCount());

    DecimalFormat df = new DecimalFormat("0.#");
    if (ret.getLength() != null) {
        ret.setLengthForDisplay(df.format(ret.getLength() / 10.0));
    }/*from ww w. j a va  2s. co m*/

    if (ret.getWidth() != null) {
        ret.setWidthForDisplay(df.format(ret.getWidth() / 10.0));
    }

    if (ret.getHeight() != null) {
        ret.setHeightForDisplay(df.format(ret.getHeight() / 10.0));
    }

    if (ret.getWeight() != null) {
        ret.setWeightForDisplay(df.format(ret.getWeight() / 1000.0));
    }

    df.applyPattern("0.###");
    if (ret.getTotalVolumn() != null) {
        if (ret.getTotalVolumn() % 1000000 == 0) {
            ret.setTotalVolumnForDisplay(df.format((ret.getTotalVolumn() / 1000000) / 1000.0));
        } else {
            ret.setTotalVolumnForDisplay(df.format(Math.ceil(ret.getTotalVolumn() / 1000000.0f) / 1000.0));
        }
    }

    df.applyPattern("0.#");
    if (ret.getTotalWeight() != null) {
        if (ret.getTotalWeight() % 1000 == 0) {
            ret.setTotalWeightForDisplay(String.valueOf(ret.getTotalWeight() / 1000));
        } else {
            ret.setTotalWeightForDisplay(df.format((ret.getTotalWeight() / 1000.0)));
        }
    }

    return ret;
}

From source file:pydio.sdk.java.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;/*from ww w.j a v  a2 s.c om*/
    } else {
        lastChunkSize = (int) getFile().length() - (this.chunkSize * (totalChunks - 1));
    }

    if (totalChunks > 1 && bufsize > chunkSize) {
        bufsize = chunkSize;
        //maybe publish message to alert
        System.out.println(
                "ATTENTION : la taille du buffer est suprieur au max upload!\nFINAL BUFFER SIZE USED: "
                        + bufsize);
    }
}

From source file:com.epam.catgenome.util.HistogramUtils.java

/**
 * Creates histogram block intervals for a histogram of specified size
 *
 * @param trackStart start index of histogram track
 * @param trackEnd end index of histogram track
 * @return list of intervals, representing histogram blocks
 *//*ww  w  . j a v  a2  s. c  om*/
public static List<Pair<Integer, Integer>> createIntervals(final int trackStart, final int trackEnd) {
    // limit to 1000!!!
    final int histogramSize = Math.min((int) Math.ceil(trackEnd * HISTOGAM_BLOCK_SIZE_PART),
            HISTOGRAM_SIZE_LIMIT);
    final int intervalLength = (trackEnd - trackStart) / histogramSize;
    final List<Pair<Integer, Integer>> intervals = new ArrayList<>(histogramSize);
    for (int i = 0; i < histogramSize; i++) {
        final int startIndex = trackStart + intervalLength * i;
        int endIndex = trackStart + intervalLength * (i + 1);
        if (endIndex > trackEnd) {
            endIndex = trackEnd;
        }

        intervals.add(new ImmutablePair<>(startIndex, endIndex));
    }
    return intervals;
}

From source file:com.uber.hoodie.common.BloomFilter.java

/**
 * Create a new Bloom filter with the given configurations.
 *//*  w w  w.j ava 2  s  .co m*/
public BloomFilter(int numEntries, double errorRate, int hashType) {
    // Bit size
    int bitSize = (int) Math.ceil(numEntries * (-Math.log(errorRate) / LOG2_SQUARED));
    // Number of the hash functions
    int numHashs = (int) Math.ceil(Math.log(2) * bitSize / numEntries);
    // The filter
    this.filter = new org.apache.hadoop.util.bloom.BloomFilter(bitSize, numHashs, hashType);
}

From source file:coral.PolypVsetServable.java

@Override
public void init(Properties properties, BlockingQueue<Message> loopQueue, Linker linker) {

    shell = (Shell) properties.get("shell");

    res = new File(properties.getProperty("coral.polyp.res", "res/"));

    robotfilename = properties.getProperty("coral.polyp.robot");
    mainfilename = properties.getProperty("coral.polyp.main", "main.html");

    setup();// w ww  . ja v  a2  s.  c  o  m

    int noclients = Integer.parseInt(properties.getProperty("coral.polyp.number", "1"));

    int perrow = (int) Math.round(Math.ceil(Math.sqrt(noclients)));

    if (noclients > 1) {
        GridData gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.grabExcessVerticalSpace = true;
        gd.widthHint = shell.getSize().x / perrow;
        gd.heightHint = shell.getSize().y / perrow;
        gd.horizontalAlignment = GridData.FILL;
        gd.verticalAlignment = GridData.FILL;

        browser.setLayoutData(gd);
        browser.setSize(shell.getSize().x / perrow, shell.getSize().y / perrow);

        logger.debug("set client to size with x:" + shell.getSize().x + " y:" + shell.getSize().y + " perrow:"
                + perrow + "");
        logger.debug("layout " + browser.getLayout());
        logger.debug("layout " + shell.getLayout());

    }
}

From source file:com.rogoman.easyauth.Base32Encoding.java

/**
 * Converts a byte array to a BASE32 string.
 *
 * @param input byte array/*from www  .  j a v a2s. com*/
 * @return BASE32 string
 */
static String toString(final byte[] input) {
    if (input == null || input.length == 0) {
        throw new IllegalArgumentException("input");
    }

    int charCount = (int) Math.ceil(input.length / 5d) * 8;
    char[] returnArray = new char[charCount];

    byte nextChar = 0, bitsRemaining = 5;
    int arrayIndex = 0;

    for (byte b : input) {
        nextChar = (byte) (nextChar | (b >> (8 - bitsRemaining)));
        returnArray[arrayIndex++] = valueToChar(nextChar);

        if (bitsRemaining < 4) {
            nextChar = (byte) ((b >> (3 - bitsRemaining)) & 31);
            returnArray[arrayIndex++] = valueToChar(nextChar);
            bitsRemaining += 5;
        }

        bitsRemaining -= 3;
        nextChar = (byte) ((b << bitsRemaining) & 31);
    }

    //if we didn't end with a full char
    if (arrayIndex != charCount) {
        returnArray[arrayIndex++] = valueToChar(nextChar);
        while (arrayIndex != charCount) {
            returnArray[arrayIndex++] = '='; //padding
        }
    }

    return new String(returnArray);
}