Example usage for org.apache.commons.math.fraction BigFraction BigFraction

List of usage examples for org.apache.commons.math.fraction BigFraction BigFraction

Introduction

In this page you can find the example usage for org.apache.commons.math.fraction BigFraction BigFraction.

Prototype

public BigFraction(final long num, final long den) 

Source Link

Document

Create a BigFraction given the numerator and denominator as simple long.

Usage

From source file:uk.ac.susx.tag.classificationframework.datastructures.CacheManager.java

/**
 * Given some dataset of instances and a pipeline to process them, calculate the fraction of those
 * instances which are already in the specified cache.
 *//*from w ww  . jav  a2 s.  c o m*/
public double fractionCachedOfDataset(String databaseName, String collectionName,
        FeatureExtractionPipeline pipeline, Iterable<Instance> documents) {
    long total = 0;
    long cached = 0;
    DB database = client.getDB(databaseName);
    if (database.collectionExists(collectionName)) {
        DBCollection dataset = database.getCollection(collectionName);
        if (dataset.findOne() == null)
            return 0.0; // No items in collection
        int config = pipeline.getCacheConfiguration();

        for (Instance document : documents) {
            total++;
            if (null != dataset
                    .findOne(new BasicDBObject("pipelineConfig", config).append("instanceID", document.id))) {
                cached++;
            }
        }
        return new BigFraction(cached, total).doubleValue();
    } else {
        return 0.0;
    }
}