Example usage for java.lang Double MAX_VALUE

List of usage examples for java.lang Double MAX_VALUE

Introduction

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

Prototype

double MAX_VALUE

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

Click Source Link

Document

A constant holding the largest positive finite value of type double , (2-2-52)·21023.

Usage

From source file:com.yoctopuce.YoctoAPI.YDataSet.java

protected int _parse(String json_str) throws YAPI_Exception {
    JSONObject json;/*from  ww  w . j a v a 2s . co  m*/
    JSONArray jstreams;
    double summaryMinVal = Double.MAX_VALUE;
    double summaryMaxVal = Double.MIN_VALUE;
    double summaryTotalTime = 0;
    double summaryTotalAvg = 0;
    long streamStartTime;
    long streamEndTime;
    long startTime = 0x7fffffff;
    long endTime = 0;

    try {
        json = new JSONObject(json_str);
        _functionId = json.getString("id");
        _unit = json.getString("unit");
        if (json.has("calib")) {
            _calib = YAPI._decodeFloats(json.getString("calib"));
            _calib.set(0, _calib.get(0) / 1000);
        } else {
            _calib = YAPI._decodeWords(json.getString("cal"));
        }
        _streams = new ArrayList<YDataStream>();
        _preview = new ArrayList<YMeasure>();
        _measures = new ArrayList<YMeasure>();
        jstreams = json.getJSONArray("streams");
        for (int i = 0; i < jstreams.length(); i++) {
            YDataStream stream = _parent._findDataStream(this, jstreams.getString(i));
            streamStartTime = stream.get_startTimeUTC() - stream.get_dataSamplesIntervalMs() / 1000;
            streamEndTime = stream.get_startTimeUTC() + stream.get_duration();
            if (_startTime > 0 && streamEndTime <= _startTime) {
                // this stream is too early, drop it
            } else if (_endTime > 0 && stream.get_startTimeUTC() > _endTime) {
                // this stream is too late, drop it
            } else {
                _streams.add(stream);
                if (startTime > streamStartTime) {
                    startTime = streamStartTime;
                }
                if (endTime < streamEndTime) {
                    endTime = streamEndTime;
                }

                if (stream.isClosed() && stream.get_startTimeUTC() >= _startTime
                        && (_endTime == 0 || streamEndTime <= _endTime)) {
                    if (summaryMinVal > stream.get_minValue())
                        summaryMinVal = stream.get_minValue();
                    if (summaryMaxVal < stream.get_maxValue())
                        summaryMaxVal = stream.get_maxValue();
                    summaryTotalAvg += stream.get_averageValue() * stream.get_duration();
                    summaryTotalTime += stream.get_duration();

                    YMeasure rec = new YMeasure(stream.get_startTimeUTC(), streamEndTime, stream.get_minValue(),
                            stream.get_averageValue(), stream.get_maxValue());
                    _preview.add(rec);
                }
            }
        }
        if ((_streams.size() > 0) && (summaryTotalTime > 0)) {
            // update time boundaries with actual data
            if (_startTime < startTime) {
                _startTime = startTime;
            }
            if (_endTime == 0 || _endTime > endTime) {
                _endTime = endTime;
            }
            _summary = new YMeasure(_startTime, _endTime, summaryMinVal, summaryTotalAvg / summaryTotalTime,
                    summaryMaxVal);
        }
    } catch (JSONException e) {
        throw new YAPI_Exception(YAPI.IO_ERROR, "invalid json structure for YDataSet: " + e.getMessage());
    }
    _progress = 0;
    return this.get_progress();
}

From source file:com.hazelcast.simulator.tests.map.SerializationStrategyTest.java

private DomainObject createNewDomainObject(DomainObjectFactory objectFactory, String indexedField) {
    DomainObject o = objectFactory.newInstance();
    o.setKey(randomAlphanumeric(7));/* www.j  a  va  2  s .  c  o  m*/
    o.setStringVal(indexedField);
    o.setIntVal(nextInt(0, Integer.MAX_VALUE));
    o.setLongVal(nextLong(0, Long.MAX_VALUE));
    o.setDoubleVal(nextDouble(0.0, Double.MAX_VALUE));
    return o;
}

From source file:com.netflix.config.DynamicFileConfigurationTest.java

@Test
public void testDefaultConfigFile() throws Exception {
    longProp = propertyFactory.getLongProperty("dprops1", Long.MAX_VALUE, new Runnable() {
        public void run() {
            propertyChanged = true;/*from  w w  w.  ja v  a 2  s  . c o m*/
        }
    });

    DynamicIntProperty validatedProp = new DynamicIntProperty("abc", 0) {
        @Override
        public void validate(String newValue) {
            if (Integer.parseInt(newValue) < 0) {
                throw new ValidationException("Cannot be negative");
            }
        }
    };
    assertEquals(0, validatedProp.get());
    assertFalse(propertyChanged);
    DynamicDoubleProperty doubleProp = propertyFactory.getDoubleProperty("dprops2", 0.0d);
    assertEquals(123456789, longProp.get());
    assertEquals(123456789, dynProp.getInteger().intValue());
    assertEquals(79.98, doubleProp.get(), 0.00001d);
    assertEquals(Double.valueOf(79.98), doubleProp.getValue());
    assertEquals(Long.valueOf(123456789L), longProp.getValue());
    modifyConfigFile();
    Thread.sleep(1000);
    assertEquals(Long.MIN_VALUE, longProp.get());
    assertEquals(0, validatedProp.get());
    assertTrue(propertyChanged);
    assertEquals(Double.MAX_VALUE, doubleProp.get(), 0.01d);
    assertFalse(ConfigurationManager.isConfigurationInstalled());
}

From source file:com.github.cambierr.lorawanpacket.semtech.Rxpk.java

public Rxpk(JSONObject _json) throws MalformedPacketException {

    /**// w  w  w.  java2 s . c om
     * tmst
     */
    if (!_json.has("tmst")) {
        throw new MalformedPacketException("missing tmst");
    } else {
        tmst = _json.getInt("tmst");
    }

    /**
     * time
     */
    if (!_json.has("time")) {
        throw new MalformedPacketException("missing time");
    } else {
        time = _json.getString("time");
    }

    /**
     * chan
     */
    if (!_json.has("chan")) {
        throw new MalformedPacketException("missing chan");
    } else {
        chan = _json.getInt("chan");
    }

    /**
     * rfch
     */
    if (!_json.has("rfch")) {
        throw new MalformedPacketException("missing rfch");
    } else {
        rfch = _json.getInt("rfch");
    }

    /**
     * freq
     */
    if (!_json.has("freq")) {
        throw new MalformedPacketException("missing freq");
    } else {
        freq = _json.getDouble("stat");
    }

    /**
     * stat
     */
    if (!_json.has("stat")) {
        throw new MalformedPacketException("missing stat");
    } else {
        stat = _json.getInt("stat");
        if (stat > 1 || stat < -1) {
            throw new MalformedPacketException("stat must be equal to -1, 0, or 1");
        }
    }

    /**
     * modu
     */
    if (!_json.has("modu")) {
        throw new MalformedPacketException("missing modu");
    } else {
        modu = Modulation.parse(_json.getString("modu"));
    }

    /**
     * datr
     */
    if (!_json.has("datr")) {
        throw new MalformedPacketException("missing datr");
    } else {
        switch (modu) {
        case FSK:
            datr = _json.getInt("datr");
            break;
        case LORA:
            datr = _json.getString("datr");
            break;
        }
    }

    /**
     * codr
     */
    if (!_json.has("codr")) {
        if (modu.equals(Modulation.FSK)) {
            codr = null;
        } else {
            throw new MalformedPacketException("missing codr");
        }
    } else {
        codr = _json.getString("codr");
    }

    /**
     * rssi
     */
    if (!_json.has("rssi")) {
        throw new MalformedPacketException("missing rssi");
    } else {
        rssi = _json.getInt("rssi");
    }

    /**
     * lsnr
     */
    if (!_json.has("lsnr")) {
        if (modu.equals(Modulation.FSK)) {
            lsnr = Double.MAX_VALUE;
        } else {
            throw new MalformedPacketException("missing lsnr");
        }
    } else {
        lsnr = _json.getDouble("lsnr");
    }

    /**
     * size
     */
    if (!_json.has("size")) {
        throw new MalformedPacketException("missing size");
    } else {
        size = _json.getInt("size");
    }

    /**
     * data
     */
    if (!_json.has("data")) {
        throw new MalformedPacketException("missing data");
    } else {
        byte[] raw;

        try {
            raw = Base64.getDecoder().decode(_json.getString("data"));
        } catch (IllegalArgumentException ex) {
            throw new MalformedPacketException("malformed data");
        }

        data = new PhyPayload(ByteBuffer.wrap(raw));
    }
}

From source file:es.udc.gii.common.eaf.plugin.parameter.jade.JADEFAdaptiveParameter.java

@Override
public double get(EvolutionaryAlgorithm algorithm) {

    //Lehmer mean:
    double meanl_f;
    double sum_f_i, sum_f_i_2;
    List<Individual> individuals;
    int f_individuals;
    double f_ind, f_i;

    //Hay que "chequear" que los individuos sean del tipo JADE:

    sum_f_i = 0.0;//from w  w w.j  a  v a2 s. c  om
    sum_f_i_2 = 0.0;

    if (algorithm.getGenerations() > this.alg_generation) {

        //Calculamos mu;
        individuals = algorithm.getPopulation().getIndividuals();

        meanl_f = 0.0;
        f_individuals = 0;
        for (Individual i : individuals) {

            if (i instanceof JADEIndividual) {

                f_ind = ((JADEIndividual) i).getF();
                if (f_ind != -Double.MAX_VALUE) {
                    sum_f_i += f_ind;
                    sum_f_i_2 += f_ind * f_ind;
                    f_individuals++;
                }
            } else {
                throw new ConfigurationException(
                        "JADECRAdaptiveParameter requires individuals of type JADEIndividual");
            }

        }

        if (f_individuals > 0) {
            meanl_f = sum_f_i_2 / sum_f_i;
            this.mu_f = (1.0 - this.c) * this.mu_f + this.c * meanl_f;
        }

        this.mu_f = (this.mu_f > 1.0 ? 1.0 : (this.mu_f < 0.0 ? 0.0 : this.mu_f));

        this.alg_generation++;
    }

    CauchyDistribution d = new CauchyDistributionImpl(this.mu_f, this.std_f);
    f_i = 0.0;
    try {
        do {
            double r = EAFRandom.nextDouble();
            f_i = d.inverseCumulativeProbability(r);
        } while (f_i < 1.0e-8);
        f_i = (f_i > 1.0 ? 1.0 : (f_i < 0.0 ? 0.0 : f_i));
    } catch (MathException ex) {
        Logger.getLogger(JADEFAdaptiveParameter.class.getName()).log(Level.SEVERE, null, ex);
    }

    return f_i;
}

From source file:edu.stanford.cfuller.imageanalysistools.fitting.DifferentialEvolutionMinimizer.java

/**
 * Performs a minimization of a function starting with a given population.
 * //from ww w.ja v a2  s.  com
 * @param population            The population of parameters to start from, one population entry per row, one parameter per column.
 * @param f                     The function to be minimized.
 * @param parameterLowerBounds  The lower bounds of each parameter.  This must have the same size as the column dimension of the population.  Generated parameter values less than these values will be discarded.
 * @param parameterUpperBounds  The upper bounds of each paraemter.  This must have the same size as the column dimension of the population.  Generated parameter values greater than these values will be discarded.
 * @param populationSize        The size of the population of parameters sets.  This must be equal to the row dimension of the population.
 * @param scaleFactor           Factor controlling the scale of crossed over entries during crossover events.
 * @param maxIterations         The maximum number of iterations to allow before returning a result.
 * @param crossoverFrequency    The frequency of crossover from 0 to 1.  At any given parameter, this is the probability of initiating a crossover as well as the probability of ending one after it has started.
 * @param tol                   Relative function value tolerance controlling termination; if the maximal and minimal population values differ by less than this factor times the maximal value, optimization will terminate.
 * @return                      The parameter values at the minimal function value found.
 */
public RealVector minimizeWithPopulation(RealMatrix population, ObjectiveFunction f,
        RealVector parameterLowerBounds, RealVector parameterUpperBounds, int populationSize,
        double scaleFactor, int maxIterations, double crossoverFrequency, double tol) {

    int numberOfParameters = parameterLowerBounds.getDimension();

    double currMinValue = Double.MAX_VALUE;
    double currMaxValue = -1.0 * Double.MAX_VALUE;
    int iterationCounter = maxIterations;

    double mutationProb = 0.01;

    //        int totalIterations =0;

    RealVector values = new ArrayRealVector(populationSize);

    boolean[] valuesChanged = new boolean[populationSize];

    java.util.Arrays.fill(valuesChanged, true);

    computeValues(f, population, values, valuesChanged);

    RealVector newVec = new ArrayRealVector(numberOfParameters);

    RealMatrix newPopulation = new Array2DRowRealMatrix(populationSize, numberOfParameters);

    while (iterationCounter > 0) {

        for (int i = 0; i < populationSize; i++) {

            int i1 = RandomGenerator.getGenerator().randInt(populationSize);
            int i2 = RandomGenerator.getGenerator().randInt(populationSize);
            int i3 = RandomGenerator.getGenerator().randInt(populationSize);

            newVec.mapMultiplyToSelf(0.0);

            boolean inBounds = true;

            boolean isCrossingOver = false;

            for (int j = 0; j < numberOfParameters; j++) {

                if ((RandomGenerator.rand() < crossoverFrequency) ^ isCrossingOver) {

                    if (!isCrossingOver) {
                        isCrossingOver = true;
                    }

                    newVec.setEntry(j, scaleFactor * (population.getEntry(i2, j) - population.getEntry(i1, j))
                            + population.getEntry(i3, j));

                } else {

                    if (isCrossingOver) {
                        isCrossingOver = false;
                    }

                    newVec.setEntry(j, population.getEntry(i, j));

                }

                //random 10% range +/- mutation

                if ((RandomGenerator.rand() < mutationProb)) {

                    double magnitude = 0.2
                            * (parameterUpperBounds.getEntry(j) - parameterLowerBounds.getEntry(j));

                    newVec.setEntry(j, newVec.getEntry(j) + (RandomGenerator.rand() - 0.5) * magnitude);

                }

                if (newVec.getEntry(j) < parameterLowerBounds.getEntry(j)
                        || newVec.getEntry(j) > parameterUpperBounds.getEntry(j)) {

                    inBounds = false;

                }

            }

            double functionValue = Double.MAX_VALUE;

            if (inBounds)
                functionValue = f.evaluate(newVec);

            //if (inBounds) System.out.printf("in bounds candidate value: %1.2f  old value: %1.2f \n", functionValue, values.getEntry(i));

            if (functionValue < values.getEntry(i)) {

                newPopulation.setRowVector(i, newVec);
                valuesChanged[i] = true;
                values.setEntry(i, functionValue);

            } else {

                newPopulation.setRowVector(i, population.getRowVector(i));
                valuesChanged[i] = false;
            }

        }

        population = newPopulation;

        double tempMinValue = Double.MAX_VALUE;
        double tempMaxValue = -1.0 * Double.MAX_VALUE;

        //            double averageValue = 0;

        for (int i = 0; i < values.getDimension(); i++) {
            double value = values.getEntry(i);
            //                averageValue += value;
            if (value < tempMinValue) {
                tempMinValue = value;
            }
            if (value > tempMaxValue) {
                tempMaxValue = value;
            }

        }

        //            averageValue /= values.getDimension();

        currMinValue = tempMinValue;
        currMaxValue = tempMaxValue;

        //LoggingUtilities.getLogger().info("Iteration counter: " + Integer.toString(totalIterations) + "  best score: " + currMinValue + "  worst score: " + currMaxValue + " average score: " + averageValue);

        if (Math.abs(currMaxValue - currMinValue) < Math.abs(tol * currMaxValue)
                + Math.abs(tol * currMinValue)) {
            iterationCounter--;
        } else {
            iterationCounter = 1;
        }

        //            totalIterations++;

    }

    for (int i = 0; i < populationSize; i++) {
        valuesChanged[i] = true;
    }

    computeValues(f, population, values, valuesChanged);

    double tempMinValue = Double.MAX_VALUE;
    int tempMinIndex = 0;

    for (int i = 0; i < populationSize; i++) {

        if (values.getEntry(i) < tempMinValue) {
            tempMinValue = values.getEntry(i);
            tempMinIndex = i;
        }
    }

    RealVector output = new ArrayRealVector(numberOfParameters);

    for (int i = 0; i < numberOfParameters; i++) {

        output.setEntry(i, population.getEntry(tempMinIndex, i));

    }

    return output;

}

From source file:com.redhat.lightblue.metadata.types.BigDecimalTypeTest.java

@Test
public void testEqualsFalse() {
    assertFalse(bigDecimalType.equals(Double.MAX_VALUE));
}

From source file:no.met.jtimeseries.netcdf.plot.SimplePlotProvider.java

/**
 * Get the list of all range axes to be used. This method will collate 
 * axes with the same units.//w  ww  . ja v  a2  s  .c  o m
 * 
 * @param dataList  List to create axis from
 * @return An axis for plotting, with value elements
 */
private List<ValueAxis> getRangeAxis(List<NumberPhenomenon> dataList) {

    class AxisInfo {
        private final String unit;
        private double low = Double.MAX_VALUE;
        private double high = -Double.MAX_VALUE;

        public AxisInfo(String unit) {
            this.unit = unit;
        }

        public void add(NumberPhenomenon p) {
            if (p.getMinValue() < low)
                low = p.getMinValue();
            if (p.getMaxValue() > high)
                high = p.getMaxValue();
        }

        private double border() {
            if (unit.equals("%"))
                return 0;
            return (high - low) / 10.0;
        }

        public String getUnit() {
            return unit;
        }

        public NumberAxis getAxis() {
            NumberAxis rangeAxis = new NumberAxis(getUnit());
            rangeAxis.setRange(getLowValue(), getHighValue());
            return rangeAxis;
        }

        private double getLowValue() {
            if (unit.equals("%"))
                return 0;
            else if (low == 0)
                return 0;
            return low - border();
        }

        private double getHighValue() {
            if (unit.equals("%"))
                return 100;
            return high + border();
        }
    }

    Vector<AxisInfo> axisInfoList = new Vector<AxisInfo>();

    for (NumberPhenomenon p : dataList) {

        AxisInfo axisInfo = null;
        for (AxisInfo ai : axisInfoList)
            if (ai.getUnit().equals(p.getPhenomenonUnit())) {
                axisInfo = ai;
                break;
            }
        if (axisInfo == null) {
            axisInfo = new AxisInfo(p.getPhenomenonUnit());
            axisInfoList.add(axisInfo);
        }
        axisInfo.add(p);
    }

    Vector<ValueAxis> ret = new Vector<ValueAxis>();
    for (AxisInfo axisInfo : axisInfoList) {
        ret.add(axisInfo.getAxis());
    }

    return ret;
}

From source file:edu.oregonstate.eecs.mcplan.rl.QLearner.java

private double maxQ(final TObjectDoubleMap<A> Qfunction) {
    double best = -Double.MAX_VALUE;
    final TObjectDoubleIterator<A> itr = Qfunction.iterator();
    while (itr.hasNext()) {
        itr.advance();//from ww  w.j a va  2  s.com
        final double d = itr.value();
        if (d > best) {
            best = d;
        }
    }
    return best;
}

From source file:com.redhat.lightblue.crud.ldap.translator.ResultTranslatorTest.java

@Test
public void testTranslate_SimpleField_BigDecimalType() throws JSONException {
    SearchResultEntry result = new SearchResultEntry(-1, "uid=john.doe,dc=example,dc=com",
            new Attribute[] { new Attribute("key", String.valueOf(Double.MAX_VALUE)) });

    EntityMetadata md = fakeEntityMetadata("fakeMetadata", new SimpleField("key", BigDecimalType.TYPE));

    DocCtx document = new ResultTranslator(factory, md, new TrivialLdapFieldNameTranslator()).translate(result);

    assertNotNull(document);/* w ww  .  ja  va  2 s . c o  m*/

    JSONAssert.assertEquals(
            "{\"key\":" + String.valueOf(Double.MAX_VALUE) + ",\"dn\":\"uid=john.doe,dc=example,dc=com\"}",
            document.getOutputDocument().toString(), true);
}