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:clus.statistic.ClassificationStat.java

public int getMajorityClass(int attr) {
    int m_class = -1;
    double m_max = Double.NEGATIVE_INFINITY;
    double[] clcts = m_ClassCounts[attr];
    for (int i = 0; i < clcts.length; i++) {
        if (clcts[i] > m_max) {
            m_class = i;
            m_max = clcts[i];// w  w w . j a  v a2  s .c  o  m
        }
    }
    if (m_max <= MathUtil.C1E_9 && m_Training != null) {
        // no examples covered -> m_max = null -> use whole training set majority class
        return m_Training.getMajorityClass(attr);
    }
    return m_class;
}

From source file:com.tussle.main.Utility.java

public static ProjectionVector combineProjections(Collection<ProjectionVector> vectors) {
    Iterator<ProjectionVector> i = vectors.iterator();
    if (vectors.size() == 0)
        return null;
    if (vectors.size() == 1)
        return i.next();
    ProjectionVector p0 = i.next();/*from  w w  w  . j  a v a  2s . c  o m*/
    ProjectionVector p1 = i.next();
    //Get bordering unit vectors
    double cos0 = p0.xNorm();
    double sin0 = p0.yNorm();
    double cos1 = p1.xNorm();
    double sin1 = p1.yNorm();
    //zeroth on the right, first on the left
    if (cos0 * sin1 < cos1 * sin0) {
        double tmpcos = cos1;
        double tmpsin = sin1;
        cos1 = cos0;
        sin1 = sin0;
        cos0 = tmpcos;
        sin0 = tmpsin;
    }
    while (i.hasNext()) {
        ProjectionVector next = i.next();
        double nextcos = next.xNorm();
        double nextsin = next.yNorm();
        if (nextcos * sin0 >= cos0 * nextsin && cos1 * nextsin >= nextcos * sin1) {
            //Case 0: Within cross product bounds
        } else if (nextcos * sin0 >= cos0 * nextsin) {
            //Case 1: Over the left, extend those bounds
            cos1 = nextcos;
            sin1 = nextsin;
        } else if (cos1 * nextsin >= nextcos * sin1) {
            //Case 2: Over the right, extend those bounds
            cos0 = nextcos;
            sin0 = nextsin;
        } else {
            //Case 3: something went horribly wrong
            return null;
        }
    }
    //Now... project all vectors onto the sum of the borders.
    double sumcos = cos0 + cos1;
    double sumsin = sin0 + sin1;
    double len = FastMath.hypot(sumcos, sumsin);
    if (len == 0)
        return null;
    sumcos /= len;
    sumsin /= len;
    double maxlen = Double.NEGATIVE_INFINITY;
    for (ProjectionVector v : vectors) {
        double scalarProj = (v.xComp() * sumcos + v.yComp() * sumsin) / (sumcos * sumcos + sumsin * sumsin);
        if (scalarProj > maxlen)
            maxlen = scalarProj;
    }
    return new ProjectionVector(sumcos, sumsin, maxlen);
}

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

/**
 * Test of generateFluorophoresFromCSV method, of class FluorophoreReceiver.
 *///w w  w  .  j  a  v a2 s  .  c  o m
@Test
public void testGenerateFluorophoresFromCSV() throws Exception {
    URL csv = FluorophoreReceiverIT.class.getResource("/label_pix_sass.csv");
    File csvFile = new File(csv.getFile());
    GenerateFluorophoresFromCSV.Builder fluorBuilder = new GenerateFluorophoresFromCSV.Builder();
    fluorBuilder.file(csvFile); // The file containing the locations.
    fluorBuilder.rescale(true); // Rescale positions to fit image?

    // Create the set of fluorophores.
    fluorBuilder.camera(camera).psfBuilder(psfBuilder).fluorDynamics(fluorDynamics).illumination(illumination);
    FluorophoreCommand fluorCommand = fluorBuilder.build();
    List<Fluorophore> fluorophores = fluorCommand.generateFluorophores();
    assertEquals(69358, 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:br.unicamp.cst.learning.glas.LearnerCodelet.java

@Override
public void proc() {

    if (enabled) {

        if ((first_run || (SOLUTION_TREE_MO.getEvaluation() < this.getGoal_fitness()))
                && !((String) EVENTS_SEQUENCE_MO.getI()).isEmpty()) {

            //         System.out.println("Init proc ... ");

            try {
                JSONArray sequence_json = new JSONArray(EVENTS_SEQUENCE_MO.getI());

                System.out.print(".");
                int sequence_lenght = sequence_json.length();
                //If (maxEventsSequenceLenght==Integer.MAX_VALUE), it tries to learn a new tree as soon as possible (if it has new events and previous learning is over)
                //TODO Increment this condition for it to start learning only if it makes a mistake?
                //If maxEventsSequenceLenght is a finite integer (set by the user) it waits until maxEventsSequenceLenght new events are presented to the current solution. Only then does it start learning a new sequence.
                if (maxEventsSequenceLenght == Integer.MAX_VALUE
                        || (sequence_lenght - last_number_of_events) >= maxEventsSequenceLenght) {

                    while (sequence_json.length() > maxEventsSequenceLenght) { // learns only with the last MAX_EVENTS_SEQUENCE_LENGHT events
                        sequence_json.remove(0);
                    }/*from  w  ww  . j  a  v a  2 s .  c om*/
                    if (this.printSequenceUsedForLearning) {
                        System.out.println("");
                    }
                    GlasSequence mySequence = new GlasSequence();
                    if (this.printSequenceUsedForLearning) {
                        System.out.println("Sequence used for learning: ");
                    }
                    for (int e = 0; e < sequence_json.length(); e++) {
                        //TODO Should be inside GlasSequence?            
                        JSONObject event_json = sequence_json.getJSONObject(e);
                        int stim = event_json.getInt(GlasSequenceElements.SENSED_STIMULUS.toString());
                        int act = event_json.getInt(GlasSequenceElements.EXPECTED_ACTION.toString());
                        double rew = event_json.getDouble(GlasSequenceElements.REWARD_RECEIVED.toString());

                        //                     Sequence used for learning: 
                        //                        0,2,0,-1.0 //TODO

                        if (this.printSequenceUsedForLearning) {
                            System.out.println(e + "," + stim + "," + act + "," + rew);
                        }

                        mySequence.addEvent(new GlasEvent(stim, act, rew));
                    }

                    //TODO Store WHO acted on this sequence, and its results

                    JSONArray solution_tree_phenotype_jsonarray = new JSONArray(SOLUTION_TREE_MO.getI());
                    int[] solution_tree_phenotype_int = new int[solution_tree_phenotype_jsonarray.length()];
                    for (int i = 0; i < solution_tree_phenotype_jsonarray.length(); i++) {
                        solution_tree_phenotype_int[i] = solution_tree_phenotype_jsonarray.getInt(i);
                    }

                    int[] genotype_int = this.getGenotypeFromPhenotype(solution_tree_phenotype_int);

                    int nNodesIndi = (solution_tree_phenotype_int.length / 3);
                    Individual indi = new Individual(nNodesIndi, nStimuli, nActions);
                    indi.setChromossome(genotype_int);

                    double max_fit = this.getMaxFitnessForSequence(mySequence);
                    double fit = indi.getFitness(mySequence);
                    indi.setNormalizedFitness(fit / max_fit);

                    indi_list.add(indi);
                    if (this.printLearnedSolutionTree) {
                        //                     System.out.println("");
                        System.out.print(fit + ",");
                        System.out.print(fit / max_fit + ",");
                        System.out.print(nNodesIndi + ",");
                        for (int i = 0; i < genotype_int.length; i++) {
                            System.out.print(genotype_int[i] + ",");
                        }
                        System.out.print(indi_list.size());
                        System.out.println("");
                    }

                    //LEARNING PHASE
                    System.out.println("I just started learning from a new sequence...");
                    int[] temp_best_found_int = { 1, 1, 1 };
                    double temp_best_found_fit = Double.NEGATIVE_INFINITY;
                    double normalized_fitness = Double.NEGATIVE_INFINITY;

                    GlasLearner myLearner = new GlasLearner(nNodes, nStimuli, nActions);
                    for (int local_nNodes = minNumberOfNodes; local_nNodes <= maxNumberOfNodes; local_nNodes++) {

                        myLearner = new GlasLearner(local_nNodes, nStimuli, nActions);
                        boolean show_gui = false;
                        myLearner.setShow_gui(show_gui);
                        myLearner.setnReRuns(nReRuns);
                        //      int max_number_reRuns=500;  //int max_number_reRuns=500;
                        //      int nParticles = 1000;            //int nParticles = 1000;
                        //      myLearner.setMax_number_reRuns(max_number_reRuns);
                        //      myLearner.setnParticles(nParticles);

                        //                     
                        myLearner.learnSequence(mySequence);
                        //                     
                        if (myLearner.getBest_found_fit() > temp_best_found_fit) {
                            temp_best_found_int = myLearner.getBest_found_solution();
                            temp_best_found_fit = myLearner.getBest_found_fit();
                        }

                        if (this.printLearnedSolutionTree) {
                            double temp_max_fit = this.getMaxFitnessForSequence(mySequence);
                            //                        System.out.println("");
                            System.out.print(temp_best_found_fit + ",");
                            normalized_fitness = temp_best_found_fit / temp_max_fit;
                            System.out.print(normalized_fitness + ",");
                            System.out.print(local_nNodes + ",");
                            for (int i = 0; i < temp_best_found_int.length - 1; i++) {
                                System.out.print(temp_best_found_int[i] + ",");
                            }
                            System.out.println(temp_best_found_int[temp_best_found_int.length - 1]);

                        }

                    }
                    System.out.println("...finished learning.");
                    int[] best_found_int = temp_best_found_int; //TODO Unnecessary?

                    int[] new_solution_tree_int = this.getPhenotypeFromGenotype(best_found_int);

                    double best_found_fit = temp_best_found_fit; //TODO Unnecessary?

                    best_solution_tree = new JSONArray();
                    for (int i = 0; i < new_solution_tree_int.length; i++) {
                        best_solution_tree.put(new_solution_tree_int[i]);
                    }

                    SOLUTION_TREE_MO.updateI(best_solution_tree.toString());
                    //                  SOLUTION_TREE_MO.setEvaluation(best_found_fit);
                    SOLUTION_TREE_MO.setEvaluation(normalized_fitness);
                    first_run = false;

                    //                  }
                    if (SOLUTION_TREE_MO.getEvaluation() >= this.getGoal_fitness()) {
                        System.out.println("Found goal fitness = " + SOLUTION_TREE_MO.getEvaluation());
                    }

                    if (plot_solution) {

                        double[] best_found_double = new double[best_found_int.length];

                        for (int i = 0; i < best_found_double.length; i++) {
                            best_found_double[i] = ((double) best_found_int[i]);
                        }

                        double[] sol = new double[nNodes * 3];
                        int count = 0;
                        for (int i = 0; i < sol.length; i++) {
                            if ((i % nNodes) == 0) {
                                sol[i] = 0;

                            } else {
                                sol[i] = best_found_double[count];
                                count++;
                            }

                        }

                        //                     ploter = new GlasPlot(sol);

                        //                     ploter.plot();

                    }

                    sequence_json = new JSONArray(EVENTS_SEQUENCE_MO.getI());
                    last_number_of_events = sequence_json.length();

                    //                  System.out.println("##########################################");

                } //if(sequence_json.length()>=MAX_EVENTS_SEQUENCE_LENGHT)

            } catch (JSONException e) {
                System.out.println("This should not happen! (at LearnerCodelet)");
                e.printStackTrace();
            }

        }

        if (indi_list.size() >= this.maxNumberOfSolutions) {
            System.out.println("Stopped learning.");
            this.setEnabled(false);
        }
    } else {//if enabled
            //         System.out.println("Learning is halted."); //Do nothing
    }

}

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

@Override
public List<ParameterType> getAdditionalParameterKeys(InputPort inputPort) {
    List<ParameterType> types = super.getAdditionalParameterKeys(inputPort);
    types.add(new ParameterTypeDouble(PARAMETER_MARKER, "Defines a horizontal line as a reference to the plot.",
            Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, true));
    return types;
}

From source file:edu.jhu.hlt.parma.inference.transducers.BackoffConditionalEditModel.java

public void train(AnnotatedString[] train_xs, AnnotatedString[] train_ys, AnnotatedString[] test_xs,
        AnnotatedString[] test_ys) {/*ww w.j  av  a  2 s  . com*/
    double ll = Double.NEGATIVE_INFINITY, prevll = Double.NEGATIVE_INFINITY;
    double test_ll = Double.NEGATIVE_INFINITY, prev_test_ll = Double.NEGATIVE_INFINITY;
    DecimalFormat df = new DecimalFormat("#.#");
    int iter = 0;
    do {
        prevll = ll;
        prev_test_ll = test_ll;
        ll = em_step(train_xs, train_ys);
        test_ll = calc_ll(test_xs, test_ys);
        System.err.println("===== EM iter " + iter + ": LL=" + df.format(ll) + " TEST_LL=" + df.format(test_ll)
                + " =====");
    } while (test_ll > prev_test_ll && ++iter < MAX_EM_ITER);
}

From source file:net.sourceforge.jasa.report.HistoricalDataReport.java

public double getHighestAcceptedAskPrice() {
    Iterator<Order> i = asks.iterator();
    double highestAcceptedAskPrice = Double.NEGATIVE_INFINITY;
    while (i.hasNext()) {
        Order s = i.next();//  ww w.  j  a v  a2 s.  c  o  m
        if (accepted(s)) {
            if (s.getPriceAsDouble() > highestAcceptedAskPrice) {
                highestAcceptedAskPrice = s.getPriceAsDouble();
            }
        }
    }
    return highestAcceptedAskPrice;
}

From source file:com.joliciel.jochre.search.highlight.LuceneQueryHighlighter.java

private double weigh(BytesRef term) {
    // TODO: is IDF the best formula?
    double termCountLog = termLogs.get(term);
    if (termCountLog == Double.NEGATIVE_INFINITY)
        return 0;
    double idf = docCountLog - termCountLog;
    return idf;//from w ww .  j  av a 2  s. com
}

From source file:de.tudarmstadt.lt.lm.lucenebased.CountingStringLM.java

@Override
public double getNgramLogProbability(List<String> ngram) {
    // check length
    assert ngram//from   w w  w .ja v  a2  s. com
            .size() <= _order : "Length of Ngram must be lower or equal to the order of the language model.";
    if (ngram.size() < 1)
        return Double.NEGATIVE_INFINITY;

    // c(w_1 ... w_n)
    Long nominator = getQuantity(ngram);
    if (nominator == 0)
        return Double.NEGATIVE_INFINITY;

    // c(w_1) / N
    if (ngram.size() == 1)
        return Math.log10((double) nominator) - Math.log10(_num_ngrams[1][0]);

    // c(w_1 ... w_n-1)
    Long denominator = getQuantity(ngram.subList(0, ngram.size() - 1));

    if (denominator == 0)
        return Double.NEGATIVE_INFINITY;

    double logprob = Math.log10((double) nominator) - Math.log10((double) denominator);
    return logprob;
}

From source file:edu.byu.nlp.util.Matrices.java

public static int[] argMaxesInColumns(double[][] mat) {
    int[] argMaxes = new int[mat[0].length];
    double[] maxes = DoubleArrays.constant(Double.NEGATIVE_INFINITY, argMaxes.length);
    for (int i = 0; i < mat.length; i++) {
        for (int j = 0; j < mat[i].length; j++) {
            if (mat[i][j] > maxes[j]) {
                maxes[j] = mat[i][j];//from   www.  ja v  a2 s .  c o  m
                argMaxes[j] = i;
            }
        }
    }
    return argMaxes;
}