Example usage for java.lang Double NEGATIVE_INFINITY

List of usage examples for java.lang Double NEGATIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Double NEGATIVE_INFINITY.

Prototype

double NEGATIVE_INFINITY

To view the source code for java.lang Double NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type double .

Usage

From source file:ch.epfl.leb.sass.models.fluorophores.commands.internal.FluorophoreReceiverIT.java

/**
 * Test of generateFluorophoresRandom2D method, of class FluorophoreReceiver.
 *//*w  w w  .  j a  v  a 2  s.c o m*/
@Test
public void testGenerateFluorophoresRandom2D() {
    GenerateFluorophoresRandom2D.Builder fluorBuilder = new GenerateFluorophoresRandom2D.Builder();
    fluorBuilder.numFluors(25); // Number of fluorophores

    // Create the set of fluorophores.
    fluorBuilder.camera(camera).psfBuilder(psfBuilder).fluorDynamics(fluorDynamics).illumination(illumination);
    FluorophoreCommand fluorCommand = fluorBuilder.build();
    List<Fluorophore> fluorophores = fluorCommand.generateFluorophores();
    assertEquals(25, fluorophores.size());

    double minX = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double maxY = Double.NEGATIVE_INFINITY;
    for (Fluorophore f : fluorophores) {
        if (f.getX() < minX)
            minX = f.getX();

        if (f.getX() > maxX)
            maxX = f.getX();

        if (f.getY() < minY)
            minY = f.getY();

        if (f.getY() > maxY)
            maxY = f.getY();
    }

    assertTrue(maxX <= 32);
    assertTrue(minX >= 0.0);
    assertTrue(maxY <= 32);
    assertTrue(minY >= 0.0);
}

From source file:org.jfree.data.RangeTest.java

/**
 * Tests the constrain() method for various values.
 *//*from   w  w w  .  j a  v  a  2  s.c o  m*/
@Test
public void testConstrain() {
    Range r1 = new Range(0.0, 1.0);

    double d = r1.constrain(0.5);
    assertEquals(0.5, d, 0.0000001);

    d = r1.constrain(0.0);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(1.0);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(-1.0);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(2.0);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(Double.POSITIVE_INFINITY);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(Double.NEGATIVE_INFINITY);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(Double.NaN);
    assertTrue(Double.isNaN(d));
}

From source file:bb.mcmc.analysis.GewekeConvergeStat.java

@Override
protected double calculateEachStat(String key) {

    final double[] t = traceValues.get(key);

    final int length = t.length;
    final int indexStart = (int) Math.floor(length * (1 - frac2));
    final int indexEnd = (int) Math.ceil(length * frac1);
    final double[] dStart = Arrays.copyOfRange(t, 0, indexEnd);
    final double[] dEnd = Arrays.copyOfRange(t, indexStart, length);
    final double meanStart = DiscreteStatistics.mean(dStart);
    final double meanEnd = DiscreteStatistics.mean(dEnd);
    final double varStart = ConvergeStatUtils.spectrum0(dStart) / dStart.length;
    final double varEnd = ConvergeStatUtils.spectrum0(dEnd) / dEnd.length;
    final double bothVar = varStart + varEnd;

    double stat = (meanStart - meanEnd) / Math.sqrt(bothVar);

    if (Double.isNaN(stat)) { //Use two separate if to handle other NaN cases later
        if (Double.isNaN(bothVar)) {
            stat = Double.NEGATIVE_INFINITY;
            System.err.println(STATISTIC_NAME + " could not be calculated for variable with id " + key
                    + ". This is due to logged values being unchanged during the run");//. Check log file for details. ");
        }/*ww w  .j  a v a 2s  . co  m*/
    }
    return stat;

}

From source file:org.jfree.data.general.DefaultHeatMapDatasetTest.java

/**
 * Some tests for the equals() method./*from   w ww. ja v a  2  s  .c o  m*/
 */
@Test
public void testEquals() {
    DefaultHeatMapDataset d1 = new DefaultHeatMapDataset(5, 10, 1.0, 2.0, 3.0, 4.0);
    DefaultHeatMapDataset d2 = new DefaultHeatMapDataset(5, 10, 1.0, 2.0, 3.0, 4.0);
    assertEquals(d1, d2);

    d1 = new DefaultHeatMapDataset(6, 10, 1.0, 2.0, 3.0, 4.0);
    assertFalse(d1.equals(d2));
    d2 = new DefaultHeatMapDataset(6, 10, 1.0, 2.0, 3.0, 4.0);
    assertTrue(d1.equals(d2));

    d1 = new DefaultHeatMapDataset(6, 11, 1.0, 2.0, 3.0, 4.0);
    assertFalse(d1.equals(d2));
    d2 = new DefaultHeatMapDataset(6, 11, 1.0, 2.0, 3.0, 4.0);
    assertTrue(d1.equals(d2));

    d1 = new DefaultHeatMapDataset(6, 11, 2.0, 2.0, 3.0, 4.0);
    assertFalse(d1.equals(d2));
    d2 = new DefaultHeatMapDataset(6, 11, 2.0, 2.0, 3.0, 4.0);
    assertTrue(d1.equals(d2));

    d1 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 3.0, 4.0);
    assertFalse(d1.equals(d2));
    d2 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 3.0, 4.0);
    assertTrue(d1.equals(d2));

    d1 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 4.0, 4.0);
    assertFalse(d1.equals(d2));
    d2 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 4.0, 4.0);
    assertTrue(d1.equals(d2));

    d1 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 4.0, 5.0);
    assertFalse(d1.equals(d2));
    d2 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 4.0, 5.0);
    assertTrue(d1.equals(d2));

    d1.setZValue(1, 2, 3.0);
    assertFalse(d1.equals(d2));
    d2.setZValue(1, 2, 3.0);
    assertTrue(d1.equals(d2));

    d1.setZValue(0, 0, Double.NEGATIVE_INFINITY);
    assertFalse(d1.equals(d2));
    d2.setZValue(0, 0, Double.NEGATIVE_INFINITY);
    assertTrue(d1.equals(d2));

    d1.setZValue(0, 1, Double.POSITIVE_INFINITY);
    assertFalse(d1.equals(d2));
    d2.setZValue(0, 1, Double.POSITIVE_INFINITY);
    assertTrue(d1.equals(d2));

    d1.setZValue(0, 2, Double.NaN);
    assertFalse(d1.equals(d2));
    d2.setZValue(0, 2, Double.NaN);
    assertTrue(d1.equals(d2));
}

From source file:org.matsim.pt.analysis.RouteTimeDiagram.java

public void createGraph(final String filename, final TransitRoute route) {

    HashMap<Id, Integer> stopIndex = new HashMap<Id, Integer>();
    int idx = 0;//from ww  w  .jav  a  2 s. com
    for (TransitRouteStop stop : route.getStops()) {
        stopIndex.put(stop.getStopFacility().getId(), idx);
        idx++;
    }

    HashSet<Id> vehicles = new HashSet<Id>();
    for (Departure dep : route.getDepartures().values()) {
        vehicles.add(dep.getVehicleId());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    int numSeries = 0;
    double earliestTime = Double.POSITIVE_INFINITY;
    double latestTime = Double.NEGATIVE_INFINITY;

    for (Map.Entry<Id, List<Tuple<Id, Double>>> entry : this.positions.entrySet()) {
        if (vehicles.contains(entry.getKey())) {
            XYSeries series = new XYSeries("t", false, true);
            for (Tuple<Id, Double> pos : entry.getValue()) {
                Integer stopIdx = stopIndex.get(pos.getFirst());
                if (stopIdx != null) {
                    double time = pos.getSecond().doubleValue();
                    series.add(stopIdx.intValue(), time);
                    if (time < earliestTime) {
                        earliestTime = time;
                    }
                    if (time > latestTime) {
                        latestTime = time;
                    }
                }
            }
            dataset.addSeries(series);
            numSeries++;

        }
    }

    JFreeChart c = ChartFactory.createXYLineChart("Route-Time Diagram, Route = " + route.getId(), "stops",
            "time", dataset, PlotOrientation.VERTICAL, false, // legend?
            false, // tooltips?
            false // URLs?
    );
    c.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f));

    XYPlot p = (XYPlot) c.getPlot();

    p.getRangeAxis().setInverted(true);
    p.getRangeAxis().setRange(earliestTime, latestTime);
    XYItemRenderer renderer = p.getRenderer();
    for (int i = 0; i < numSeries; i++) {
        renderer.setSeriesPaint(i, Color.black);
    }

    try {
        ChartUtilities.saveChartAsPNG(new File(filename), c, 1024, 768, null, true, 9);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:biz.itcons.wsdm.hw2_2.NaiveBayes.java

/**
 * A classification for document. Based on the train data, an attempt to 
 * classify a document.//  ww  w . j a v a 2 s  .com
 * @param document A document to be classfied.
 * @return Most probable classification for given document.
 */
public String classifyDocument(String document) {
    Map<String, Integer> docTokens = StringTokenization.getTokensWithMultiplicity(document);

    double totalProbability = Double.NEGATIVE_INFINITY;
    String totalClassification = "";
    for (Map.Entry<String, ClassificationItem> e : parsedEntries.entrySet()) {
        double priorProb = ((double) e.getValue().getDocumentCount()) / globalTrainingCount;
        double currentClassProb = Math.log10(priorProb)
                + e.getValue().calcCondProbDoc(docTokens, vocabulary.size());
        if (currentClassProb > totalProbability) {
            totalProbability = currentClassProb;
            totalClassification = e.getKey();
        }
    }
    return totalClassification;
}

From source file:org.gvsig.symbology.fmap.symbols.BarChart3DSymbol.java

protected Plot getOutlinePlot() {
    outlinePlot = null; // <- delete this
    if (outlinePlot == null) {
        CategoryPlot myOutlinePlot;/*  ww w .j a  v a  2 s.c om*/
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        dataset.addValue(23D, "Series 1", "London");
        // dataset.addValue(14D, "Series 1", "New York");
        // dataset.addValue(14D, "Series 1", "Istanbul");
        // dataset.addValue(14D, "Series 1", "Cairo");
        dataset.addValue(13D, "Series 2", "London");
        // dataset.addValue(19D, "Series 2", "New York");
        // dataset.addValue(19D, "Series 2", "Istanbul");
        // dataset.addValue(19D, "Series 2", "Cairo");
        dataset.addValue(7D, "Series 3", "London");
        // dataset.addValue(9D, "Series 3", "New York");
        // dataset.addValue(9D, "Series 3", "Istanbul");
        // dataset.addValue(9D, "Series 3", "Cairo");

        CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
        ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

        BarRenderer3D renderer = new BarRenderer3D();
        myOutlinePlot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
        double min = Double.POSITIVE_INFINITY;
        double max = Double.NEGATIVE_INFINITY;
        // for (int i = 0; values != null && i < values.length; i++) {
        // min = Math.min(min, values[i]);
        // max = Math.min(max, values[i]);
        // dataset.addValue(values[i], rowKeys[i], columnKeys[i]);
        // }
        myOutlinePlot.setDataset(dataset);
        myOutlinePlot.setOrientation(vertical ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL);
        outlinePlot = myOutlinePlot;

    }
    return outlinePlot;
}

From source file:bookChapter.theoretical.AnalyzeTheoreticalMSMSCalculation.java

private static String result(MSnSpectrum msms, double precursorTolerance, HashSet<DBEntry> peptideAndMass,
        double fragmentTolerance, int correctionFactor, boolean hasAllPossCharge)
        throws IllegalArgumentException, IOException, MzMLUnmarshallerException {
    String res = "";
    HashMap<Peptide, Boolean> allSelectedPeps = getSelectedTheoPeps(msms, precursorTolerance, peptideAndMass); // select peptides within a given precursor tolerance
    int scoredPeps = allSelectedPeps.size();
    ArrayList<Identify> sequestResults = new ArrayList<Identify>(),
            andromedaResults = new ArrayList<Identify>();
    // for every peptide... calculate each score...
    for (Peptide selectedPep : allSelectedPeps.keySet()) {
        Identify toCalculateSequest = new Identify(msms, selectedPep, fragmentTolerance, true,
                allSelectedPeps.get(selectedPep), scoredPeps, correctionFactor, hasAllPossCharge),
                toCalculateAndromeda = new Identify(msms, selectedPep, fragmentTolerance, false,
                        allSelectedPeps.get(selectedPep), scoredPeps, correctionFactor, hasAllPossCharge);
        if (toCalculateSequest.getScore() != Double.NEGATIVE_INFINITY) {
            sequestResults.add(toCalculateSequest);
            andromedaResults.add(toCalculateAndromeda);
        }//from   w  ww .  j a  v a  2s  .co  m
    }
    if (!sequestResults.isEmpty()) {
        HashSet<Identify> theBestSEQUESTResults = getBestResult(sequestResults),
                theBestAndromedaResults = getBestResult(andromedaResults);
        res = printInfo(theBestAndromedaResults, theBestSEQUESTResults);
    }
    return res;
}

From source file:com.rapidminer.gui.plotter.charts.ParallelPlotter2.java

private void prepareData() {
    this.dataset = new XYSeriesCollection();

    // calculate min and max
    int columns = this.dataTable.getNumberOfColumns();
    double[] min = new double[columns];
    double[] max = new double[columns];
    if (isLocalNormalized()) {
        for (int c = 0; c < columns; c++) {
            min[c] = Double.POSITIVE_INFINITY;
            max[c] = Double.NEGATIVE_INFINITY;
        }//from  w  w  w  . j av  a 2s  .c  om

        synchronized (dataTable) {
            Iterator<DataTableRow> i = dataTable.iterator();
            while (i.hasNext()) {
                DataTableRow row = i.next();
                for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
                    double value = row.getValue(c);
                    min[c] = MathFunctions.robustMin(min[c], value);
                    max[c] = MathFunctions.robustMax(max[c], value);
                }
            }
        }
    }

    this.domainAxisMap = null;
    synchronized (dataTable) {
        this.colorMap = new double[dataTable.getNumberOfRows()];

        Iterator<DataTableRow> i = this.dataTable.iterator();
        int idCounter = 0;

        while (i.hasNext()) {
            DataTableRow row = i.next();
            String id = row.getId();
            if (id == null) {
                id = (idCounter + 1) + "";
            }

            XYSeries series = new XYSeries(id, false, false);
            int counter = 0;
            for (int column = 0; column < dataTable.getNumberOfColumns(); column++) {
                if ((!dataTable.isSpecial(column)) && (column != colorColumn)) {
                    double value = row.getValue(column);
                    if (isLocalNormalized()) {
                        value = (value - min[column]) / (max[column] - min[column]);
                    }
                    series.add(counter, value);
                    counter++;
                }
            }

            if (colorColumn >= 0) {
                this.colorMap[idCounter] = row.getValue(colorColumn);
            }

            this.dataset.addSeries(series);
            idCounter++;
        }
    }

    if (domainAxisMap == null) {
        List<String> domainValues = new LinkedList<>();
        for (int column = 0; column < dataTable.getNumberOfColumns(); column++) {
            if ((!dataTable.isSpecial(column)) && (column != colorColumn)) {
                domainValues.add(dataTable.getColumnName(column));
            }
        }
        this.domainAxisMap = new String[domainValues.size()];
        domainValues.toArray(this.domainAxisMap);
    }
}

From source file:dr.math.distributions.GammaDistribution.java

/**
 * the natural log of the probability density function of the distribution
 *
 * @param x     argument//from w ww  .j  a v a  2s.  com
 * @param shape shape parameter
 * @param scale scale parameter
 * @return log pdf value
 */
public static double logPdf(double x, double shape, double scale) {
    // double a = Math.pow(scale,-shape) * Math.pow(x, shape-1.0);
    // double b = x/scale + GammaFunction.lnGamma(shape);
    // return Math.log(a) - b;

    // AR - changed this to return -ve inf instead of throwing an
    // exception... This makes things
    // much easier when using this to calculate log likelihoods.
    // if (x < 0) throw new IllegalArgumentException();
    if (x < 0)
        return Double.NEGATIVE_INFINITY;

    if (x == 0) {
        if (shape == 1.0)
            return Math.log(1.0 / scale);
        else
            return Double.NEGATIVE_INFINITY;
    }
    if (shape == 1.0) {
        return (-x / scale) - Math.log(scale);
    }
    if (shape == 0.0) // uninformative
        return -Math.log(x);

    if (shape == -0.5) { // Gelman 2008, hierarchical variance, -1 degrees of freedom
        return 0.5 * Math.log(x);
    }

    /*return ((shape - 1.0) * Math.log(x/scale) - x / scale - GammaFunction
        .lnGamma(shape))
        - Math.log(scale);*/

    return ((shape - 1.0) * (Math.log(x) - Math.log(scale)) - x / scale - GammaFunction.lnGamma(shape))
            - Math.log(scale);
}