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 intargmax(float[] values) Returns the index of the maximum value in the given array.static intcalculateLevenshteinDistance(String source, String target) Calculates the Levenshtein distance between two input strings.static doubleclamp(double value, double min, double max) Clamps a value between a specified minimum and maximum range.static floateuclideanModulo(float x, float y) Computes the Euclidean modulo (non-negative remainder) ofxmoduloy.static floatexpit(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- ifvaluesisnull -
IllegalArgumentException- ifvaluesis 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) ofxmoduloy.- Parameters:
-
x- the dividend -
y- the divisor (must not be zero) - Returns:
-
the non-negative remainder of
xmoduloy
-
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:
-
valueif it falls within the range; otherwise, the nearest bound (min or max) - Throws:
-
IllegalArgumentException- ifmaxis less thanmin
-