Package com.itextpdf.pdfocr.onnxtr.util
Class MathUtil
java.lang.Object
com.itextpdf.pdfocr.onnxtr.util.MathUtil
Additional math functions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
argmax
(float[] values) Returns the index of the maximum value in the given array.static int
calculateLevenshteinDistance
(String source, String target) 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) ofx
moduloy
.static float
expit
(float x) Computes the sigmoid function, also known as the logistic function, for the given input.
-
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
- ifvalues
isnull
-
IllegalArgumentException
- ifvalues
is empty
-
calculateLevenshteinDistance
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) ofx
moduloy
.- Parameters:
-
x
- the dividend -
y
- the divisor (must not be zero) - Returns:
-
the non-negative remainder of
x
moduloy
-
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
- ifmax
is less thanmin
-