Class Scale<E extends Enum<E>>

java.lang.Object
dev.langchain4j.service.decision.Scale<E>
Type Parameters:
E - the enum whose constants are the levels

@Experimental public final class Scale<E extends Enum<E>> extends Object
The answer to a question of a decision service that places the input on an ordered scale: the mean level, the probability of each level and, if the model reports one, a confidence. It is the typed counterpart of ScaleAnswer.

The levels are the constants of the enum, from the lowest (the first declared constant) to the highest.

Since:
1.21.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Scale.Builder<E extends Enum<E>>
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <E extends Enum<E>>
    Scale.Builder<E>
    builder(Class<E> levelType)
    Creates a builder for a scale whose levels are the constants of the given enum.
    How confident the model is in mean(), from 0 to 1, or null if the model does not report a confidence.
    boolean
     
    int
     
    double
    The probability-weighted mean of the level indexes, from 0 (the first constant) to n - 1 (the last constant).
    The level with the highest probability or, if the model does not report probabilities, the level closest to mean().
    The probability of each level, from the lowest to the highest.
    double
    The probability of the given level or any higher level, for example the probability that an incident is at least of high severity.
    double
    The probability of the given level, or 0 if the model reported probabilities but none for this level.
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • builder

      public static <E extends Enum<E>> Scale.Builder<E> builder(Class<E> levelType)
      Creates a builder for a scale whose levels are the constants of the given enum.
    • mean

      public double mean()
      The probability-weighted mean of the level indexes, from 0 (the first constant) to n - 1 (the last constant). It can fall between two levels: with the levels LOW, MEDIUM and HIGH, a mean of 1.4 means "between medium and high, closer to medium".
    • mostLikely

      public E mostLikely()
      The level with the highest probability or, if the model does not report probabilities, the level closest to mean().
    • probabilities

      public Map<E,Double> probabilities()
      The probability of each level, from the lowest to the highest. Empty if the model does not report probabilities.
    • probabilityOf

      public double probabilityOf(E level)
      The probability of the given level, or 0 if the model reported probabilities but none for this level.
      Throws:
      IllegalStateException - if the model did not report probabilities.
    • probabilityAtLeast

      public double probabilityAtLeast(E level)
      The probability of the given level or any higher level, for example the probability that an incident is at least of high severity.
      Throws:
      IllegalStateException - if the model did not report probabilities.
    • confidence

      public Double confidence()
      How confident the model is in mean(), from 0 to 1, or null if the model does not report a confidence. The formula is defined by each model, so prefer probabilities() for thresholds.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object