opennlp.tools.ml.naivebayes

## Class LogProbabilities<T>

- java.lang.Object
- - opennlp.tools.ml.naivebayes.Probabilities<T>
  - - opennlp.tools.ml.naivebayes.LogProbabilities<T>

- Type Parameters:
    `T` - the label (category) class

      public class LogProbabilities<T>
      extends Probabilities<T>

  Class implementing the probability distribution over labels returned by a classifier as a log of probabilities. This is necessary because floating point precision in Java does not allow for high-accuracy representation of very low probabilities such as would occur in a text categorizer.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LogProbabilities()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addIn(T t, double probability, int count)` Compounds the existing probability mass on the label with the new probability passed in to the method.
    `void` | `discardCountsBelow(double i)`
    `Double` | `get(T t)` Returns the probability associated with a label
    `Map<T,Double>` | `getAll()` Returns the probabilities associated with all labels
    `Double` | `getLog(T t)` Returns the log probability associated with a label
    `T` | `getMax()` Returns the most likely label
    `void` | `set(T t, double probability)` Assigns a probability to a label, discarding any previously assigned probability.
    `void` | `set(T t, Probability<T> probability)` Assigns a probability to a label, discarding any previously assigned probability.
    `void` | `setIfLarger(T t, double probability)` Assigns a probability to a label, discarding any previously assigned probability, if the new probability is greater than the old one.
    `void` | `setLog(T t, double probability)` Assigns a log probability to a label, discarding any previously assigned probability.

    - ### Methods inherited from class opennlp.tools.ml.naivebayes.Probabilities

      `getConfidence, getKeys, getMaxValue, setConfidence, toString`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### LogProbabilities

          public LogProbabilities()

  - ### Method Detail

    - #### set

          public void set(T t,
                          double probability)

      Assigns a probability to a label, discarding any previously assigned probability.
      Overrides:
        `set` in class `Probabilities<T>`
      Parameters:
        `t` - the label to which the probability is being assigned
        `probability` - the probability to assign

    - #### set

          public void set(T t,
                          Probability<T> probability)

      Assigns a probability to a label, discarding any previously assigned probability.
      Overrides:
        `set` in class `Probabilities<T>`
      Parameters:
        `t` - the label to which the probability is being assigned
        `probability` - the probability to assign

    - #### setIfLarger

          public void setIfLarger(T t,
                                  double probability)

      Assigns a probability to a label, discarding any previously assigned probability, if the new probability is greater than the old one.
      Overrides:
        `setIfLarger` in class `Probabilities<T>`
      Parameters:
        `t` - the label to which the probability is being assigned
        `probability` - the probability to assign

    - #### setLog

          public void setLog(T t,
                             double probability)

      Assigns a log probability to a label, discarding any previously assigned probability.
      Overrides:
        `setLog` in class `Probabilities<T>`
      Parameters:
        `t` - the label to which the log probability is being assigned
        `probability` - the log probability to assign

    - #### addIn

          public void addIn(T t,
                            double probability,
                            int count)

      Compounds the existing probability mass on the label with the new probability passed in to the method.
      Overrides:
        `addIn` in class `Probabilities<T>`
      Parameters:
        `t` - the label whose probability mass is being updated
        `probability` - the probability weight to add
        `count` - the amplifying factor for the probability compounding

    - #### get

          public Double get(T t)

      Returns the probability associated with a label
      Overrides:
        `get` in class `Probabilities<T>`
      Parameters:
        `t` - the label whose probability needs to be returned
      Returns:
        the probability associated with the label

    - #### getLog

          public Double getLog(T t)

      Returns the log probability associated with a label
      Overrides:
        `getLog` in class `Probabilities<T>`
      Parameters:
        `t` - the label whose log probability needs to be returned
      Returns:
        the log probability associated with the label

    - #### discardCountsBelow

          public void discardCountsBelow(double i)

      Overrides:
        `discardCountsBelow` in class `Probabilities<T>`

    - #### getAll

          public Map<T,Double> getAll()

      Returns the probabilities associated with all labels
      Overrides:
        `getAll` in class `Probabilities<T>`
      Returns:
        the HashMap of labels and their probabilities

    - #### getMax

          public T getMax()

      Returns the most likely label
      Overrides:
        `getMax` in class `Probabilities<T>`
      Returns:
        the label that has the highest associated probability

Copyright © 2026 The Apache Software Foundation. All rights reserved.