Example usage for java.lang Integer doubleValue

List of usage examples for java.lang Integer doubleValue

Introduction

In this page you can find the example usage for java.lang Integer doubleValue.

Prototype

public double doubleValue() 

Source Link

Document

Returns the value of this Integer as a double after a widening primitive conversion.

Usage

From source file:com.joliciel.csvLearner.utils.FScoreCalculator.java

void evaluate() {
    if (updatedSinceLastEval) {
        precisions = new TreeMap<E, Double>();
        recalls = new TreeMap<E, Double>();
        fScores = new TreeMap<E, Double>();

        for (E outcome : outcomeSet) {
            LOG.debug("Outcome: " + outcome);
            Integer truePositiveCountObj = truePositiveCounts.get(outcome);
            Integer falsePositiveCountObj = falsePositiveCounts.get(outcome);
            Integer falseNegativeCountObj = falseNegativeCounts.get(outcome);
            double truePositiveCount = truePositiveCountObj != null ? truePositiveCountObj.doubleValue() : 0.0;
            double falsePositiveCount = falsePositiveCountObj != null ? falsePositiveCountObj.doubleValue()
                    : 0.0;//from  ww  w.jav  a  2 s  .  co  m
            double falseNegativeCount = falseNegativeCountObj != null ? falseNegativeCountObj.doubleValue()
                    : 0.0;
            LOG.debug("truePositiveCount: " + truePositiveCount);
            LOG.debug("falsePositiveCount: " + falsePositiveCount);
            if (LOG.isTraceEnabled()) {
                LOG.debug("False positives: ");
                Map<E, Integer> pairCounts = falsePositives.get(outcome);
                if (pairCounts != null) {
                    for (E guessed : pairCounts.keySet()) {
                        int pairCount = pairCounts.get(guessed);
                        LOG.trace(outcome.toString() + " , " + guessed.toString() + ": " + pairCount);
                    }
                }
            }

            LOG.debug("falseNegativeCount " + falseNegativeCount);
            if (LOG.isTraceEnabled()) {
                LOG.debug("False negatives: ");
                Map<E, Integer> pairCounts = falseNegatives.get(outcome);
                if (pairCounts != null) {
                    for (E expected : pairCounts.keySet()) {
                        int pairCount = pairCounts.get(expected);
                        LOG.trace(outcome.toString() + " , " + expected.toString() + ": " + pairCount);
                    }
                }
            }

            double precision = 0;
            double recall = 0;
            double fScore = 0;

            if (truePositiveCount + falsePositiveCount > 0)
                precision = truePositiveCount / (truePositiveCount + falsePositiveCount);
            if (truePositiveCount + falseNegativeCount > 0)
                recall = truePositiveCount / (truePositiveCount + falseNegativeCount);
            if (precision + recall > 0)
                fScore = (2 * precision * recall) / (precision + recall);
            LOG.debug("Precision: " + precision);
            LOG.debug("Recall: " + recall);
            LOG.debug("F-score " + fScore);

            precisions.put(outcome, precision);
            recalls.put(outcome, recall);
            fScores.put(outcome, fScore);
            totalTruePositiveCount += truePositiveCount;
            totalFalsePositiveCount += falsePositiveCount;
            totalFalseNegativeCount += falseNegativeCount;
        }
        totalPrecision = 0;
        totalRecall = 0;
        totalFScore = 0;
        if (totalTruePositiveCount + totalFalsePositiveCount > 0)
            totalPrecision = totalTruePositiveCount / (totalTruePositiveCount + totalFalsePositiveCount);
        if (totalTruePositiveCount + totalFalseNegativeCount > 0)
            totalRecall = totalTruePositiveCount / (totalTruePositiveCount + totalFalseNegativeCount);
        if (totalPrecision + totalRecall > 0)
            totalFScore = (2 * totalPrecision * totalRecall) / (totalPrecision + totalRecall);
        LOG.info("Total tests: " + testCount);
        LOG.info("Total true positives: " + totalTruePositiveCount);
        LOG.info("Total false positives: " + totalFalsePositiveCount);
        LOG.info("Total false negatives: " + totalFalseNegativeCount);
        LOG.info("Total precision: " + totalPrecision);
        LOG.info("Total recall: " + totalRecall);
        LOG.info("Total f-score: " + totalFScore);

        updatedSinceLastEval = false;
    }
}

From source file:ConversionUtil.java

public static byte[] convertToByteArray(Object object) throws Exception {

    byte[] returnArray = null;
    Class clazz = object.getClass();
    String clazzName = clazz.getName();

    if (clazz.equals(Integer.class)) {
        Integer aValue = (Integer) object;
        int intValue = aValue.intValue();
        returnArray = convertToByteArray(intValue);
    } else if (clazz.equals(String.class)) {
        String aValue = (String) object;
        returnArray = convertToByteArray(aValue);
    } else if (clazz.equals(Byte.class)) {
        Byte aValue = (Byte) object;
        byte byteValue = aValue.byteValue();
        returnArray = convertToByteArray(byteValue);
    } else if (clazz.equals(Long.class)) {
        Long aValue = (Long) object;
        long longValue = aValue.longValue();
        returnArray = convertToByteArray(longValue);
    } else if (clazz.equals(Short.class)) {
        Short aValue = (Short) object;
        short shortValue = aValue.shortValue();
        returnArray = convertToByteArray(shortValue);
    } else if (clazz.equals(Boolean.class)) {
        Boolean aValue = (Boolean) object;
        boolean booleanValue = aValue.booleanValue();
        returnArray = convertToByteArray(booleanValue);
    } else if (clazz.equals(Character.class)) {
        Character aValue = (Character) object;
        char charValue = aValue.charValue();
        returnArray = convertToByteArray(charValue);
    } else if (clazz.equals(Float.class)) {
        Float aValue = (Float) object;
        float floatValue = aValue.floatValue();
        returnArray = convertToByteArray(floatValue);
    } else if (clazz.equals(Double.class)) {
        Double aValue = (Double) object;
        double doubleValue = aValue.doubleValue();
        returnArray = convertToByteArray(doubleValue);
    } else {/*  w ww .j a v a2  s  .c  o  m*/

        throw new Exception("Cannot convert object of type " + clazzName);
    }

    return returnArray;
}

From source file:com.joliciel.talismane.stats.FScoreCalculator.java

/**
 * Return Cohen's kappa for this confusion matrix.
 * @return/*from   w  w w . j  a  v  a 2 s .c  o m*/
 */
public double getKappa() {
    double totalCount = (double) testCount;
    double totalAccuracy = (double) totalTruePositiveCount / totalCount;

    // random accuracy is the sum of products for marginal accuracies for each label
    double randomAccuracy = 0.0;
    for (E outcome : outcomeSet) {
        Integer truePositiveCountObj = truePositiveCounts.get(outcome);
        Integer falsePositiveCountObj = falsePositiveCounts.get(outcome);
        Integer falseNegativeCountObj = falseNegativeCounts.get(outcome);
        double truePositiveCount = truePositiveCountObj != null ? truePositiveCountObj.doubleValue() : 0.0;
        double falsePositiveCount = falsePositiveCountObj != null ? falsePositiveCountObj.doubleValue() : 0.0;
        double falseNegativeCount = falseNegativeCountObj != null ? falseNegativeCountObj.doubleValue() : 0.0;
        double marginalRandomAccuracy = ((truePositiveCount + falsePositiveCount) / totalCount)
                * ((truePositiveCount + falseNegativeCount) / totalCount);
        randomAccuracy += marginalRandomAccuracy;
    }

    double kappa = (totalAccuracy - randomAccuracy) / (1 - randomAccuracy);
    return kappa;
}

From source file:org.openmrs.logic.result.Result.java

/**
 * Overrides the numeric representation of ths result without changing the default datatype
 * /* www.  j a v  a  2s  .  co  m*/
 * @param valueNumeric
 */
public void setValueNumeric(Integer valueNumeric) {
    this.valueNumeric = valueNumeric.doubleValue();
}

From source file:org.openmrs.logic.result.Result.java

/**
 * Builds a numeric result with a specific result date
 * //from   ww w . jav  a2 s .  c  o m
 * @param resultDate
 * @param valueNumeric
 */
public Result(Date resultDate, Integer valueNumeric, Object obj) {
    this(resultDate, Datatype.NUMERIC, null, null, null, valueNumeric.doubleValue(), null, obj);
}

From source file:com.joliciel.talismane.stats.FScoreCalculator.java

void evaluate() {
    if (updatedSinceLastEval) {
        LOG.info("###F-score calculations " + (label == null ? "" : " for " + label.toString()));
        precisions = new HashMap<E, Double>();
        recalls = new HashMap<E, Double>();
        fScores = new HashMap<E, Double>();

        for (E outcome : outcomeSet) {
            LOG.debug("Outcome: " + outcome);
            Integer truePositiveCountObj = truePositiveCounts.get(outcome);
            Integer falsePositiveCountObj = falsePositiveCounts.get(outcome);
            Integer falseNegativeCountObj = falseNegativeCounts.get(outcome);
            double truePositiveCount = truePositiveCountObj != null ? truePositiveCountObj.doubleValue() : 0.0;
            double falsePositiveCount = falsePositiveCountObj != null ? falsePositiveCountObj.doubleValue()
                    : 0.0;//from w ww.j  av a 2  s. c  o  m
            double falseNegativeCount = falseNegativeCountObj != null ? falseNegativeCountObj.doubleValue()
                    : 0.0;
            LOG.debug("truePositiveCount: " + truePositiveCount);
            LOG.debug("falsePositiveCount: " + falsePositiveCount);
            if (LOG.isTraceEnabled()) {
                LOG.debug("False positives: ");
                Map<E, Integer> pairCounts = falsePositives.get(outcome);
                if (pairCounts != null) {
                    for (E guessed : pairCounts.keySet()) {
                        int pairCount = pairCounts.get(guessed);
                        LOG.trace(outcome.toString() + " , " + guessed.toString() + ": " + pairCount);
                    }
                }
            }

            LOG.debug("falseNegativeCount " + falseNegativeCount);
            if (LOG.isTraceEnabled()) {
                LOG.debug("False negatives: ");
                Map<E, Integer> pairCounts = falseNegatives.get(outcome);
                if (pairCounts != null) {
                    for (E expected : pairCounts.keySet()) {
                        int pairCount = pairCounts.get(expected);
                        LOG.trace(outcome.toString() + " , " + expected.toString() + ": " + pairCount);
                    }
                }
            }

            double precision = 0;
            double recall = 0;
            double fScore = 0;

            if (truePositiveCount + falsePositiveCount > 0)
                precision = truePositiveCount / (truePositiveCount + falsePositiveCount);
            if (truePositiveCount + falseNegativeCount > 0)
                recall = truePositiveCount / (truePositiveCount + falseNegativeCount);
            if (precision + recall > 0)
                fScore = (2 * precision * recall) / (precision + recall);
            LOG.debug("Precision: " + precision);
            LOG.debug("Recall: " + recall);
            LOG.debug("F-score " + fScore);

            precisions.put(outcome, precision);
            recalls.put(outcome, recall);
            fScores.put(outcome, fScore);
            totalTruePositiveCount += truePositiveCount;
            totalFalsePositiveCount += falsePositiveCount;
            totalFalseNegativeCount += falseNegativeCount;
        }
        totalPrecision = (double) totalTruePositiveCount
                / ((double) totalTruePositiveCount + (double) totalFalsePositiveCount);
        totalRecall = (double) totalTruePositiveCount
                / ((double) totalTruePositiveCount + (double) totalFalseNegativeCount);
        totalFScore = (2 * totalPrecision * totalRecall) / (totalPrecision + totalRecall);
        LOG.info("Total tests: " + testCount);
        LOG.info("Total true positives: " + totalTruePositiveCount);
        LOG.info("Total false positives: " + totalFalsePositiveCount);
        LOG.info("Total false negatives: " + totalFalseNegativeCount);
        LOG.info("Total precision: " + totalPrecision);
        LOG.info("Total recall: " + totalRecall);
        LOG.info("Total f-score: " + totalFScore);

        updatedSinceLastEval = false;
    }
}

From source file:ubic.gemma.analysis.expression.coexpression.links.LinkAnalysis.java

/**
 * Writes two flies: one the actual probe degrees, and the other a histogram (dist)
 *///from w ww  .j a v a  2  s.  c o  m
private void writeProbeDegreeDistribution() {

    File outputDir = getOutputDir();

    if (outputDir == null)
        return;

    String distPath = outputDir + File.separator + expressionExperiment.getShortName() + ".degreeDist.txt";
    String path = outputDir + File.separator + expressionExperiment.getShortName() + ".degrees.txt";

    File outputFile = new File(path);
    if (outputFile.exists()) {
        outputFile.delete();
    }

    File outputDistFile = new File(distPath);
    if (outputDistFile.exists()) {
        outputDistFile.delete();
    }

    try {
        FileWriter out = new FileWriter(outputFile);

        out.write("# Probe degree statistics (before filtering by probeDegreeThreshold)\n");
        out.write("# date=" + (new Date()) + "\n");
        out.write("# exp=" + expressionExperiment + " " + expressionExperiment.getShortName() + "\n");
        out.write("ProbeID\tProbeName\tNumLinks\n");

        for (Integer i : probeDegreeMap.keySet()) {
            CompositeSequence probe = this.getProbe(i);
            out.write(probe.getId() + "\t" + probe.getName() + "\t" + probeDegreeMap.get(i) + "\n");
        }

        out.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    Histogram hist = new Histogram("foo", 100, 0, 1000);
    for (Integer i : probeDegreeMap.values()) {
        hist.fill(i.doubleValue());
    }

    double[] counts = hist.getArray();
    try {
        FileWriter out = new FileWriter(outputDistFile);

        int d = (int) hist.min();
        int step = (int) hist.stepSize();

        out.write("# Probe degree histogram (before filtering by probeDegreeThreshold)\n");
        out.write("# date=" + (new Date()) + "\n");
        out.write("# exp=" + expressionExperiment + " " + expressionExperiment.getShortName() + "\n");
        out.write("Bin\tCount\n");

        for (int i = 0; i < counts.length; i++) {
            Double v = counts[i];
            out.write(d + "\t" + v.intValue() + "\n");
            d += step;
        }

        out.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.exporter.ExportWorkbook.java

/**
 * Sets given value and style of the given cell.
 * /*w w  w.  ja  v  a  2 s  . c o  m*/
 * @param cell
 *          the cell in question
 * @param value
 *          the value to be set
 * @param style
 *          if <code>null</code> the default style is taken
 */
private void setCellValue(Cell cell, Integer value, CellStyle style) {
    if (value != null) {
        this.setCellValue(cell, value.doubleValue(), style);
    }
}

From source file:dk.dma.msiproxy.provider.dkmsi.service.DkMsiProviderService.java

/**
 * Reads the location for the legacy firing exercise.
 *
 * @param message the message to read the location for
 * @return the updated message/*from  ww w.  j  a va2 s  .  co m*/
 */
private Message readFiringExerciseLocationData(Message message) {
    // Inject the id into the SQL
    String sql = firingExerciseLocationDataSql.replace(":id", message.getId().toString());

    // Execute the DB query
    @SuppressWarnings("unchecked")
    List<Object[]> feData = em.createNativeQuery(sql).getResultList();

    // If there are no points, remove the location
    if (feData.size() == 0) {
        return message;
    }

    // Add the points to the message location
    Location location = new Location();
    message.checkCreateLocations().add(location);
    location.setType(LocationType.POLYGON);

    for (Object[] row : feData) {

        // Read the location point data from the DB
        int col = 0;
        Integer latDeg = getInt(row, col++);
        Double latMin = getDouble(row, col++);
        Integer lonDeg = getInt(row, col++);
        Double lonMin = getDouble(row, col);

        double lat = latDeg.doubleValue() + latMin / 60.0;
        double lon = lonDeg.doubleValue() + lonMin / 60.0;

        // Create the current point
        Point pt = new Point();
        pt.setIndex(location.checkCreatePoints().size() + 1);
        pt.setLat(lat);
        pt.setLon(lon);
        location.checkCreatePoints().add(pt);
    }

    return message;
}

From source file:net.sourceforge.subsonic.controller.StreamController.java

protected Dimension getSuitableVideoSize(Integer existingWidth, Integer existingHeight, Integer maxBitRate) {
    if (maxBitRate == null) {
        return new Dimension(320, 240);
    }//from  ww  w  . j a  v a 2  s.c  om

    int w, h;
    if (maxBitRate <= 600) {
        w = 320;
        h = 240;
    } else if (maxBitRate <= 1000) {
        w = 480;
        h = 360;
    } else {
        w = 640;
        h = 480;
    }

    if (existingWidth == null || existingHeight == null) {
        return new Dimension(w, h);
    }

    if (existingWidth < w || existingHeight < h) {
        return new Dimension(even(existingWidth), even(existingHeight));
    }

    double aspectRate = existingWidth.doubleValue() / existingHeight.doubleValue();
    w = (int) Math.round(h * aspectRate);

    return new Dimension(even(w), even(h));
}