Class MathUtil

java.lang.Object
com.itextpdf.pdfocr.onnxtr.util.MathUtil

public final class MathUtil extends Object
Additional math functions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    argmax(float[] values)
    Returns the index of the maximum value in the given array.
    static int
    Calculates the Levenshtein distance between two input strings.
    static double
    clamp(double value, double min, double max)
    Clamps a value between a specified minimum and maximum range.
    static float
    euclideanModulo(float x, float y)
    Computes the Euclidean modulo (non-negative remainder) of x modulo y.
    static float
    expit(float x)
    Computes the sigmoid function, also known as the logistic function, for the given input.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • argmax

      public static int argmax (float[] values)
      Returns the index of the maximum value in the given array.
      Parameters:
      values - the array of float values (must not be null or empty)
      Returns:
      the index of the maximum value in the array
      Throws:
      NullPointerException - if values is null
      IllegalArgumentException - if values is empty
    • calculateLevenshteinDistance

      public static int calculateLevenshteinDistance (String source, String target)
      Calculates the Levenshtein distance between two input strings.
      Parameters:
      source - the original string to be transformed
      target - the target string to transform into
      Returns:
      the minimum number of single-character edits required to convert the source string into the target string
    • expit

      public static float expit (float x)
      Computes the sigmoid function, also known as the logistic function, for the given input.
      Parameters:
      x - the input value
      Returns:
      the sigmoid of the input value
    • euclideanModulo

      public static float euclideanModulo (float x, float y)
      Computes the Euclidean modulo (non-negative remainder) of x modulo y.
      Parameters:
      x - the dividend
      y - the divisor (must not be zero)
      Returns:
      the non-negative remainder of x modulo y
    • clamp

      public static double clamp (double value, double min, double max)
      Clamps a value between a specified minimum and maximum range.
      Parameters:
      value - the value to clamp
      min - the minimum allowed value
      max - the maximum allowed value
      Returns:
      value if it falls within the range; otherwise, the nearest bound (min or max)
      Throws:
      IllegalArgumentException - if max is less than min