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:PrintfStuff.java

public static void main(String[] args) throws IOException {
    char three[] = { 't', 'h', 'r', 'e', 'e' };
    System.out.printf("%b %n %c %n %s %n %s %n %d %n" + "%d %n %g %n %g %n %s %n", !false, '3',
            new String(three), "Three", 3, Long.MAX_VALUE, Math.PI, Double.MAX_VALUE, new Object());
}

From source file:MaxVariablesDemo.java

public static void main(String args[]) {

    //integers/*from  w  w  w .j av a  2s . c o  m*/
    byte largestByte = Byte.MAX_VALUE;
    short largestShort = Short.MAX_VALUE;
    int largestInteger = Integer.MAX_VALUE;
    long largestLong = Long.MAX_VALUE;

    //real numbers
    float largestFloat = Float.MAX_VALUE;
    double largestDouble = Double.MAX_VALUE;

    //other primitive types
    char aChar = 'S';
    boolean aBoolean = true;

    //Display them all.
    System.out.println("The largest byte value is " + largestByte + ".");
    System.out.println("The largest short value is " + largestShort + ".");
    System.out.println("The largest integer value is " + largestInteger + ".");
    System.out.println("The largest long value is " + largestLong + ".");

    System.out.println("The largest float value is " + largestFloat + ".");
    System.out.println("The largest double value is " + largestDouble + ".");

    if (Character.isUpperCase(aChar)) {
        System.out.println("The character " + aChar + " is uppercase.");
    } else {
        System.out.println("The character " + aChar + " is lowercase.");
    }
    System.out.println("The value of aBoolean is " + aBoolean + ".");
}

From source file:MaxVariablesDemo.java

public static void main(String args[]) {

    // integers//w  w  w  .  jav a  2s .c o  m
    byte largestByte = Byte.MAX_VALUE;
    short largestShort = Short.MAX_VALUE;
    int largestInteger = Integer.MAX_VALUE;
    long largestLong = Long.MAX_VALUE;

    /* real numbers*/
    float largestFloat = Float.MAX_VALUE;
    double largestDouble = Double.MAX_VALUE;

    // other primitive types
    char aChar = 'S';
    boolean aBoolean = true;

    // display them all
    System.out.println("The largest byte value is " + largestByte);
    System.out.println("The largest short value is " + largestShort);
    System.out.println("The largest integer value is " + largestInteger);
    System.out.println("The largest long value is " + largestLong);

    System.out.println("The largest float value is " + largestFloat);
    System.out.println("The largest double value is " + largestDouble);

    if (Character.isUpperCase(aChar)) {
        System.out.println("The character " + aChar + " is upper case.");
    } else {
        System.out.println("The character " + aChar + " is lower case.");
    }
    System.out.println("The value of aBoolean is " + aBoolean);
}

From source file:com.genentech.chemistry.openEye.apps.SDFSubRMSD.java

public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file oe-supported");
    opt.setRequired(true);/*from ww  w  .  java  2 s.com*/
    options.addOption(opt);

    opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("fragFile", true, "file with single 3d substructure query");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("isMDL", false,
            "if given the fragFile is suposed to be an mdl query file, query features are supported.");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String fragFile = cmd.getOptionValue("fragFile");

    // read fragment
    OESubSearch ss;
    oemolistream ifs = new oemolistream(fragFile);
    OEMolBase mol;
    if (!cmd.hasOption("isMDL")) {
        mol = new OEGraphMol();
        oechem.OEReadMolecule(ifs, mol);
        ss = new OESubSearch(mol, OEExprOpts.AtomicNumber, OEExprOpts.BondOrder);
    } else {
        int aromodel = OEIFlavor.Generic.OEAroModelOpenEye;
        int qflavor = ifs.GetFlavor(ifs.GetFormat());
        ifs.SetFlavor(ifs.GetFormat(), (qflavor | aromodel));
        int opts = OEMDLQueryOpts.Default | OEMDLQueryOpts.SuppressExplicitH;
        OEQMol qmol = new OEQMol();
        oechem.OEReadMDLQueryFile(ifs, qmol, opts);
        ss = new OESubSearch(qmol);
        mol = qmol;
    }

    double nSSatoms = mol.NumAtoms();
    double sssCoords[] = new double[mol.GetMaxAtomIdx() * 3];
    mol.GetCoords(sssCoords);
    mol.Clear();
    ifs.close();

    if (!ss.IsValid())
        throw new Error("Invalid query " + args[0]);

    ifs = new oemolistream(inFile);
    oemolostream ofs = new oemolostream(outFile);
    int count = 0;

    while (oechem.OEReadMolecule(ifs, mol)) {
        count++;
        double rmsd = Double.MAX_VALUE;
        double molCoords[] = new double[mol.GetMaxAtomIdx() * 3];
        mol.GetCoords(molCoords);

        for (OEMatchBase mb : ss.Match(mol, false)) {
            double r = 0;
            for (OEMatchPairAtom mp : mb.GetAtoms()) {
                OEAtomBase asss = mp.getPattern();
                double sx = sssCoords[asss.GetIdx() * 3];
                double sy = sssCoords[asss.GetIdx() * 3];
                double sz = sssCoords[asss.GetIdx() * 3];

                OEAtomBase amol = mp.getTarget();
                double mx = molCoords[amol.GetIdx() * 3];
                double my = molCoords[amol.GetIdx() * 3];
                double mz = molCoords[amol.GetIdx() * 3];

                r += Math.sqrt((sx - mx) * (sx - mx) + (sy - my) * (sy - my) + (sz - mz) * (sz - mz));
            }
            r /= nSSatoms;
            rmsd = Math.min(rmsd, r);
        }

        if (rmsd != Double.MAX_VALUE)
            oechem.OESetSDData(mol, "SSSrmsd", String.format("%.3f", rmsd));

        oechem.OEWriteMolecule(ofs, mol);
        mol.Clear();
    }

    ifs.close();
    ofs.close();

    mol.delete();
    ss.delete();
}

From source file:DifferentalEvolution.java

public static void main(String[] args) {
    solutions = new ArrayList<Double>(ControlVariables.RUNS_PER_FUNCTION);

    /* An array of the benchmark functions to evalute */
    benchmarkFunctions = new ArrayList<FitnessFunction>();
    benchmarkFunctions.add(new DeJong());
    benchmarkFunctions.add(new HyperEllipsoid());
    benchmarkFunctions.add(new Schwefel());
    benchmarkFunctions.add(new RosenbrocksValley());
    benchmarkFunctions.add(new Rastrigin());

    /* Apply the differential evolution algorithm to each benchmark function */
    for (FitnessFunction benchmarkFunction : benchmarkFunctions) {
        /* Set the fitness function for the current benchmark function */
        fitnessFunction = benchmarkFunction;

        /* Execute the differential evolution algorithm a number of times per function */
        for (int runs = 0; runs < ControlVariables.RUNS_PER_FUNCTION; ++runs) {
            int a;
            int b;
            int c;
            boolean validVector = false;
            Vector noisyVector = null;

            /* Reset the array of the best values found */
            prevAmount = 0;//from  w  w  w  .ja  v a  2  s. c o m
            lowestFit = new LinkedHashMap<Integer, Double>();
            lowestFit.put(prevAmount, Double.MAX_VALUE);

            initPopulation(fitnessFunction.getBounds());

            /* Reset the fitness function NFC each time */
            fitnessFunction.resetNFC();

            while (fitnessFunction.getNFC() < ControlVariables.MAX_FUNCTION_CALLS) {
                for (int i = 0; i < ControlVariables.POPULATION_SIZE; i++) {
                    // Select 3 Mutually Exclusive Parents i != a != b != c
                    while (!validVector) {
                        do {
                            a = getRandomIndex();
                        } while (a == i);

                        do {
                            b = getRandomIndex();
                        } while (b == i || b == a);

                        do {
                            c = getRandomIndex();
                        } while (c == i || c == a || c == b);

                        // Catch invalid vectors
                        try {
                            validVector = true;
                            noisyVector = VectorOperations.mutation(population.get(c), population.get(b),
                                    population.get(a));
                        } catch (IllegalArgumentException e) {
                            validVector = false;
                        }
                    }

                    validVector = false;

                    Vector trialVector = VectorOperations.crossover(population.get(i), noisyVector, random);

                    trialVector.setFitness(fitnessFunction.evaluate(trialVector));

                    population.set(i, VectorOperations.selection(population.get(i), trialVector));

                    /* Get the best fitness value found so far */
                    if (population.get(i).getFitness() < lowestFit.get(prevAmount)) {
                        prevAmount = fitnessFunction.getNFC();
                        bestValue = population.get(i).getFitness();
                        lowestFit.put(prevAmount, bestValue);
                    }
                }
            }

            /* save the best value found for the entire DE algorithm run */
            solutions.add(bestValue);
        }

        /* Display the mean and standard deviation */
        System.out.println("\nResults for " + fitnessFunction.getName());
        DescriptiveStatistics stats = new DescriptiveStatistics(Doubles.toArray(solutions));
        System.out.println("AVERAGE BEST FITNESS: " + stats.getMean());
        System.out.println("STANDARD DEVIATION:   " + stats.getStandardDeviation());

        /* Set the last value (NFC) to the best value found */
        lowestFit.put(ControlVariables.MAX_FUNCTION_CALLS, bestValue);

        /* Plot the best value found vs. NFC */
        PerformanceGraph.plot(lowestFit, fitnessFunction.getName());

        /* Reset the results for the next benchmark function to be evaluated */
        solutions.clear();
        lowestFit.clear();
        bestValue = Double.MAX_VALUE;
    }
}

From source file:edu.msu.cme.rdp.abundstats.cli.AbundMain.java

public static void main(String[] args) throws IOException {
    File inputFile;//from w  w  w. ja  v  a  2s .  co m
    File resultDir = new File(".");
    RPlotter plotter = null;
    boolean isClusterFile = true;
    List<AbundStatsCalculator> statCalcs = new ArrayList();
    double clustCutoffFrom = Double.MIN_VALUE, clustCutoffTo = Double.MAX_VALUE;

    String usage = "Main [options] <cluster file>";
    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("result-dir")) {
            resultDir = new File(line.getOptionValue("result-dir"));
            if (!resultDir.exists() && !resultDir.mkdirs()) {
                throw new Exception(
                        "Result directory " + resultDir + " does not exist and could not be created");
            }
        }

        if (line.hasOption("R-location")) {
            plotter = new RPlotter();
            plotter.setCommandTemplate(rplotterTemplate);
            plotter.setRPath(line.getOptionValue("R-location"));
            plotter.setOutFileExt(".png");

            if (!new File(plotter.getRPath()).canExecute()) {
                throw new Exception(plotter.getRPath() + " does not exist or is not exectuable");
            }
        }

        if (line.hasOption("lower-cutoff")) {
            clustCutoffFrom = Double.valueOf(line.getOptionValue("lower-cutoff"));
        }

        if (line.hasOption("upper-cutoff")) {
            clustCutoffTo = Double.valueOf(line.getOptionValue("upper-cutoff"));
        }

        if (line.hasOption("jaccard")) {
            statCalcs.add(new Jaccard(true));
        }

        if (line.hasOption("sorensen")) {
            statCalcs.add(new Sorensen(true));
        }

        if (line.hasOption("otu-table")) {
            isClusterFile = false;
        }

        if (statCalcs.isEmpty()) {
            throw new Exception("Must specify at least one stat to compute (jaccard, sorensen)");
        }

        args = line.getArgs();
        if (args.length != 1) {
            throw new Exception("Unexpected number of command line arguments");
        }

        inputFile = new File(args[0]);

    } catch (Exception e) {
        new HelpFormatter().printHelp(usage, options);
        System.err.println("Error: " + e.getMessage());
        return;
    }

    if (isClusterFile) {
        RDPClustParser parser;
        parser = new RDPClustParser(inputFile);

        try {
            if (parser.getClusterSamples().size() == 1) {
                throw new IOException("Cluster file must have more than one sample");
            }

            List<Cutoff> cutoffs = parser.getCutoffs(clustCutoffFrom, clustCutoffTo);
            if (cutoffs.isEmpty()) {
                throw new IOException(
                        "No cutoffs in cluster file in range [" + clustCutoffFrom + "-" + clustCutoffTo + "]");
            }

            for (Cutoff cutoff : cutoffs) {
                List<Sample> samples = new ArrayList();

                for (ClusterSample clustSample : parser.getClusterSamples()) {
                    Sample s = new Sample(clustSample.getName());
                    for (Cluster clust : cutoff.getClusters().get(clustSample.getName())) {
                        s.addSpecies(clust.getNumberOfSeqs());
                    }
                    samples.add(s);
                }

                processSamples(samples, statCalcs, resultDir, cutoff.getCutoff() + "_", plotter);
            }

        } finally {
            parser.close();
        }
    } else {
        List<Sample> samples = new ArrayList();
        BufferedReader reader = new BufferedReader(new FileReader(inputFile));
        String line = reader.readLine();

        if (line == null || line.split("\\s+").length < 2) {
            throw new IOException("Must be 2 or more samples for abundance statistic calculations!");
        }
        int numSamples = line.split("\\s+").length;

        boolean header = true;
        try {
            Integer.valueOf(line.split("\\s+")[0]);
            header = false;
        } catch (Exception e) {
        }

        if (header) {
            for (String s : line.split("\\s+")) {
                samples.add(new Sample(s));
            }
        } else {
            int sample = 0;
            for (String s : line.split("\\s+")) {
                samples.add(new Sample("" + sample));
                samples.get(sample).addSpecies(Integer.valueOf(s));
                sample++;
            }
        }

        int lineno = 2;
        while ((line = reader.readLine()) != null) {
            if (line.trim().equals("")) {
                continue;
            }
            int sample = 0;
            if (line.split("\\s+").length != numSamples) {
                System.err.println(
                        "Line number " + lineno + " didn't have the expected number of samples (contained "
                                + line.split("\\s+").length + ", expected " + numSamples + ")");
            }

            for (String s : line.split("\\s+")) {
                samples.get(sample).addSpecies(Integer.valueOf(s));
                sample++;
            }

            lineno++;
        }

        processSamples(samples, statCalcs, resultDir, inputFile.getName(), plotter);
    }
}

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

public static void main(final String[] argv) {
    final RandomGenerator rng = new MersenneTwister(43);

    final int Nother_taxis = 0;
    final double slip = 0.0;
    final TaxiState state_prototype = TaxiWorlds.dietterich2000(rng, Nother_taxis, slip);

    final int T = 100000;

    final double gamma = 0.9;
    final double Vmax = 20.0;
    final double epsilon = 0.1;
    final double alpha = 0.1;
    final QLearner<TaxiState, PrimitiveTaxiRepresentation, TaxiAction> learner = new QLearner<TaxiState, PrimitiveTaxiRepresentation, TaxiAction>(
            new int[] { 0 }, rng, new PrimitiveTaxiRepresenter(state_prototype), new TaxiActionGenerator(),
            gamma, Vmax, epsilon, alpha);

    //      final int scale = 20;
    //      final TaxiVisualization vis = new TaxiVisualization( null, state_prototype.topology, state_prototype.locations, scale );
    //      final EpisodeListener<TaxiState, TaxiAction> updater = vis.updater( 0 );

    final AverageRewardAccumulator<TaxiState, TaxiAction> avg = new AverageRewardAccumulator<TaxiState, TaxiAction>(
            1);//  w ww  . java2 s  . c o m
    final double lag = -Double.MAX_VALUE;

    final Map<PrimitiveTaxiRepresentation, TObjectDoubleMap<TaxiAction>> old_values = new HashMap<PrimitiveTaxiRepresentation, TObjectDoubleMap<TaxiAction>>();

    int ns = 500;
    for (int i = 0; i < Nother_taxis; ++i) {
        ns *= 25 - i - 1;
    }
    final int Nstates = ns;

    int count = 0;
    while (true) {
        final TaxiState state = TaxiWorlds.dietterich2000(rng, Nother_taxis, slip);
        final TaxiSimulator sim = new TaxiSimulator(rng, state, slip, T);
        final Episode<TaxiState, TaxiAction> episode = new Episode<TaxiState, TaxiAction>(sim,
                JointPolicy.create(learner), T);
        episode.addListener(avg);
        //         episode.addListener( updater );
        //      episode.addListener( new LoggingEpisodeListener<TaxiState, TaxiAction>() );
        episode.run();

        //         final double diff = Math.abs( avg.reward[0].mean() - lag );

        //         System.out.println( "Episode " + count + ": avg reward = " + avg.reward[0].mean() );

        count += 1;

        if ((count % 10000 == 0) && learner.values.size() == Nstates) {
            //            System.out.println( "learner.values.size() == " + Nstates );
            boolean complete = true;
            double norm = 0.0;
            for (final Map.Entry<PrimitiveTaxiRepresentation, TObjectDoubleMap<TaxiAction>> e : learner.values
                    .entrySet()) {
                final TObjectDoubleMap<TaxiAction> new_q = e.getValue();
                TObjectDoubleMap<TaxiAction> old_q = old_values.get(e.getKey());
                if (old_q == null) {
                    old_q = new TObjectDoubleHashMap<TaxiAction>();
                    old_values.put(e.getKey(), old_q);
                    complete = false;
                }
                final TObjectDoubleIterator<TaxiAction> itr = new_q.iterator();
                while (itr.hasNext()) {
                    itr.advance();
                    final TaxiAction a = itr.key();
                    final double new_qa = itr.value();
                    final double old_qa = old_q.get(a);
                    final double diff = new_qa - old_qa;
                    norm += diff * diff;
                    old_q.put(a, new_qa);
                }
            }
            System.out.println("Qnorm = " + norm);
            if (complete && norm < 1e-6) {
                break;
            }
        }
    }

}

From source file:Main.java

public static double findMin(double[] list) {
    double min = Double.MAX_VALUE;
    for (double item : list) {
        if (min > item)
            min = item;//from   w  w w  .  j  a va  2 s  .com
    }
    return min;
}

From source file:Main.java

public static double getXMoveDistance(double slope, double dis) {
    if (slope == Double.MAX_VALUE) {
        return dis;
    }//from ww w.  ja v a 2 s  .c  om
    return Math.abs((dis * slope) / Math.sqrt(1 + slope * slope));
}

From source file:Main.java

public static double min(double... vals) {
    double min = Double.MAX_VALUE;
    for (double d : vals)
        if (min > d)
            min = d;/*from ww  w.  j  av  a 2  s. com*/
    return min;
}