Example usage for java.lang Number doubleValue

List of usage examples for java.lang Number doubleValue

Introduction

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

Prototype

public abstract double doubleValue();

Source Link

Document

Returns the value of the specified number as a double .

Usage

From source file:edu.uci.ics.jung.algorithms.scoring.VoltageScorer.java

/**
 * @see edu.uci.ics.jung.algorithms.scoring.AbstractIterativeScorer#update(Object)
 *//*from   ww w  .j  av a 2 s .co  m*/
@Override
public double update(V v) {
    // if it's a voltage source or sink, we're done
    Number source_volts = source_voltages.get(v);
    if (source_volts != null) {
        setOutputValue(v, source_volts.doubleValue());
        return 0.0;
    }
    if (sinks.contains(v)) {
        setOutputValue(v, 0.0);
        return 0.0;
    }

    Collection<E> edges = graph.getInEdges(v);
    double voltage_sum = 0;
    double weight_sum = 0;
    for (E e : edges) {
        int incident_count = getAdjustedIncidentCount(e);
        for (V w : graph.getIncidentVertices(e)) {
            if (!w.equals(v) || hyperedges_are_self_loops) {
                double weight = getEdgeWeight(w, e).doubleValue() / incident_count;
                voltage_sum += getCurrentValue(w).doubleValue() * weight;
                weight_sum += weight;
            }
        }
        //            V w = graph.getOpposite(v, e);
        //            double weight = getEdgeWeight(w,e).doubleValue();
        //            voltage_sum += getCurrentValue(w).doubleValue() * weight;
        //            weight_sum += weight;
    }

    // if either is 0, new value is 0
    if (voltage_sum == 0 || weight_sum == 0) {
        setOutputValue(v, 0.0);
        return getCurrentValue(v).doubleValue();
    }

    setOutputValue(v, voltage_sum / weight_sum);
    return Math.abs(getCurrentValue(v).doubleValue() - voltage_sum / weight_sum);
}

From source file:de.tudarmstadt.ukp.dkpro.tc.svmhmm.writer.SVMHMMDataWriter.java

@Override
public void write(File aOutputDirectory, FeatureStore featureStore, boolean aUseDenseInstances,
        String aLearningMode, boolean applyWeighting) throws Exception {
    // map features to feature numbers
    BidiMap featureNameToFeatureNumberMapping = SVMHMMUtils
            .mapVocabularyToIntegers(featureStore.getFeatureNames());

    // prepare output file
    File outputFile = new File(aOutputDirectory, new SVMHMMAdapter()
            .getFrameworkFilename(TCMachineLearningAdapter.AdapterNameEntries.featureVectorsFile));

    BufferedWriter bf = new BufferedWriter(new FileWriter(outputFile));
    PrintWriter pw = new PrintWriter(bf);

    log.info("Start writing features to file " + outputFile.getAbsolutePath());

    log.debug("Total instances: " + featureStore.getNumberOfInstances());
    log.debug("Feature vector size: " + featureStore.getFeatureNames().size());

    if (featureStore instanceof SparseFeatureStore) {
        SparseFeatureStore sparseFeatureStore = (SparseFeatureStore) featureStore;
        log.debug("Non-null feature sparsity ratio: " + sparseFeatureStore.getFeatureSparsityRatio());
    }/*w  w w .ja  v a2s .  c  o m*/

    for (int i = 0; i < featureStore.getNumberOfInstances(); i++) {
        Instance instance;

        // getInstance() is time-consuming for dense features
        // check whether can we use only sparse features
        if (featureStore instanceof SparseFeatureStore) {
            instance = ((SparseFeatureStore) featureStore).getInstanceSparseFeatures(i);
        } else {
            instance = featureStore.getInstance(i);
        }

        // placeholder for original token
        String originalToken = null;

        // other "features" - meta data features that will be stored in the comment
        SortedMap<String, String> metaDataFeatures = new TreeMap<>();

        // feature values
        SortedMap<Integer, Number> featureValues = new TreeMap<>();
        for (Feature f : instance.getFeatures()) {
            String featureName = f.getName();
            Object featureValue = f.getValue();

            // we ignore null feature values
            if (featureValue == null) {
                continue;
            }

            // get original token stored in OriginalToken feature
            if (OriginalTextHolderFeatureExtractor.ORIGINAL_TEXT.equals(featureName)) {
                // if original token/text was multi line, join it to a single line
                //                    originalToken = ((String) featureValue).replaceAll("\\n", " ");
                originalToken = (String) featureValue;
                continue;
            }

            // handle other possible features as metadata?
            if (isMetaDataFeature(featureName)) {
                metaDataFeatures.put(featureName, (String) featureValue);
                continue;
            }

            // not allow other non-number features
            if (!(featureValue instanceof Number)) {
                log.debug("Only features with number values are allowed, but was " + f);
                continue;
            }

            // in case the feature store produced dense feature vector with zeros for
            // non-present features, we ignore zero value features here
            Number featureValueNumber = (Number) featureValue;
            if (Math.abs(featureValueNumber.doubleValue() - 0d) < EPS) {
                continue;
            }

            // get number and int value of the feature
            Integer featureNumber = (Integer) featureNameToFeatureNumberMapping.get(featureName);

            featureValues.put(featureNumber, featureValueNumber);
        }

        // print formatted output: label name and sequence id
        pw.printf(Locale.ENGLISH, "%s qid:%d ", instance.getOutcome(), instance.getSequenceId());

        // print sorted features
        for (Map.Entry<Integer, Number> entry : featureValues.entrySet()) {
            if (entry.getValue() instanceof Double) {
                // format double on 8 decimal places
                pw.printf(Locale.ENGLISH, "%d:%.8f ", entry.getKey(), entry.getValue().doubleValue());
            } else {
                // format as integer
                pw.printf(Locale.ENGLISH, "%d:%d ", entry.getKey(), entry.getValue().intValue());
            }
        }

        // print original token and label as comment
        pw.printf(Locale.ENGLISH, "# %s %d %s ", instance.getOutcome(), instance.getSequenceId(),
                (originalToken != null) ? (URLEncoder.encode(originalToken, "utf-8")) : "");

        // print meta-data features at the end
        for (Map.Entry<String, String> entry : metaDataFeatures.entrySet()) {
            pw.printf(" %s:%s", URLEncoder.encode(entry.getKey(), "utf-8"),
                    URLEncoder.encode(entry.getValue(), "utf-8"));
        }
        // new line at the end
        pw.println();
    }

    IOUtils.closeQuietly(pw);

    // writing feature mapping
    File mappingFile = new File(aOutputDirectory, "featuresIntToNames_forDebug.txt");
    SVMHMMUtils.saveMappingTextFormat(featureNameToFeatureNumberMapping, mappingFile);

    log.info("Finished writing features to file " + outputFile.getAbsolutePath());
}

From source file:it.unibo.alchemist.model.implementations.positions.LatLongPosition.java

/**
 * @param lat//from   w w  w  .  ja  va  2  s.c o m
 *            latitude
 * @param lon
 *            longitude
 */
public LatLongPosition(final Number lat, final Number lon) {
    this(lat.doubleValue(), lon.doubleValue());
}

From source file:com.tibbo.linkserver.plugin.device.file.item.NumericItem.java

private int toInt(Number value) {
    if (value instanceof Double) {
        return (new BigDecimal(value.doubleValue())).setScale(0, RoundingMode.HALF_UP).intValue();
    }/*from w  ww.ja va2s.  co  m*/
    if (value instanceof Float) {
        return (new BigDecimal(value.floatValue())).setScale(0, RoundingMode.HALF_UP).intValue();
    }
    if (value instanceof BigDecimal) {
        return ((BigDecimal) value).setScale(0, RoundingMode.HALF_UP).intValue();
    } else {
        return value.intValue();
    }
}

From source file:com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype.java

protected Number requestedType(Number number) {
    if (type.equals(Integer.class))
        return number.intValue();
    if (type.equals(Long.class))
        return number.longValue();
    if (type.equals(Double.class))
        return number.doubleValue();
    if (type.equals(Float.class))
        return number.floatValue();
    return number;
}

From source file:fr.ens.transcriptome.aozan.util.StatisticsUtils.java

/**
 * Add values in dataset./*from   ww  w  . ja  v a 2s .  co m*/
 * @param number new values to put in dataset
 */
public void addValues(final Number number) {
    final Double val = number.doubleValue();

    if (val != null) {
        if (!val.isInfinite()) {
            this.ds.addValue(val);
        }
    }
}

From source file:org.kalypso.ogc.sensor.diagview.jfreechart.CurveDataset.java

/**
 * @see org.jfree.data.xy.XYDataset#getXValue(int, int)
 *///from   w  w w.j  a  v  a2  s. com
@Override
public double getXValue(final int series, final int item) {
    final Number x = getX(series, item);

    return x == null ? Double.NaN : x.doubleValue();
}

From source file:org.kalypso.ogc.sensor.diagview.jfreechart.CurveDataset.java

/**
 * @see org.jfree.data.xy.XYDataset#getYValue(int, int)
 *//*from www .  j a  va 2s  .c o m*/
@Override
public double getYValue(final int series, final int item) {
    final Number y = getY(series, item);

    return y == null ? Double.NaN : y.doubleValue();
}

From source file:com.github.brandtg.StlDecomposition.java

public StlResult decompose(List<Long> times, List<Number> series) {
    double[] timesArray = new double[times.size()];
    double[] seriesArray = new double[series.size()];

    int idx = 0;/*from w ww.j  a v a2s .co m*/
    for (Long time : times) {
        timesArray[idx++] = time;
    }

    idx = 0;
    for (Number value : series) {
        seriesArray[idx++] = value.doubleValue();
    }

    return decompose(timesArray, seriesArray);
}

From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.PercentageGroupedCategoryDataset.java

@Override
public Number getValue(int row, int column) {
    double total = 0;
    String group1 = StringUtils.substringBefore((String) getRowKey(row),
            GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
    for (int i = 0; i < getRowCount(); i++) {
        Number value = dataset.getValue(i, column);
        if (value != null) {
            String group2 = StringUtils.substringBefore((String) getRowKey(i),
                    GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
            if (group1.equals(group2)) {
                total += value.doubleValue();
            }//from w w  w. j a va 2s  .  co m
        }
    }
    Number value = dataset.getValue(row, column);
    if (value == null) {
        return 0;
    }
    double actual = value.doubleValue();
    if (total > 0) {
        return actual / total * 100;
    }
    return 0;
}