Package jline.util
Class Maths
java.lang.Object
jline.util.Maths
Mathematical functions and utilities.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
static class
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrix
circul
(int c) static Matrix
static double[]
cumSum
(double[] ar) Cumulative sum of an array, where the value at each index of the result is the sum of all the previous values of the input.static int[]
cumSum
(int[] ar) Cumulative sum of an array, where the value at each index of the result is the sum of all the previous values of the input.static void
elementAdd
(int[] ar, int i) Helper method that adds an integer to every element of an integer array.static double
erf
(double x) static double
fact
(double n) static int
fact
(int n) static double
factln
(double n) static double
factln
(int n) static double
gammaFunction
(double x) static Maths.simplexQuadResult
Grundmann-Moeller simplex integrationstatic Matrix
Implementation of MATLAB "hist": puts elements of v into k binsstatic Maths.laplaceApproxReturn
static double[]
linspace
(double start, double end, int num) static double
logmeanexp
(Matrix x) static double[]
logspace
(double min, double max, int n) static int[]
logspacei
(int start, int stop, int n) Generates an integer list of n logarithmically spaced values.static void
static double
max
(double x, double y) Returns the max of two numbers.static double
min
(double x, double y) Returns the min of two numbers.static Matrix
multichoose
(double n, double k) static Matrix
multiChooseCon
(Matrix n, double S) static double
static double
nchoosek
(double n, double k) static Matrix
Computes the combinations of the elements in v taken k at a timeprotected static int
nextPowerOfTwo
(int x) Given an integer x input, find the next integer y greater than x such that y is a power of 2.static Matrix
num_grad_h
(Matrix x0, double h, SerializableFunction<Matrix, Matrix> hfun) static ComplexMatrix
num_grad_h_complex
(Matrix x0, double h, SerializableFunction<Matrix, ComplexMatrix> hfun) static Matrix
num_hess_h
(Matrix x0, double h, SerializableFunction<Matrix, Matrix> hfun) static ComplexMatrix
num_hess_h_complex
(Matrix x0, double h, SerializableFunction<Matrix, ComplexMatrix> hfun) static Matrix
static double
rand()
static double
randn()
static boolean
static org.apache.commons.math3.complex.Complex[]
roots
(double[] coefficients) static org.apache.commons.math3.complex.Complex[]
static void
setMatlabRandomSeed
(long seed) static void
setRandomNumbersMatlab
(boolean matlab_style) static double
simplex_fun
(double[] x, Matrix L, Matrix N) static Maths.simplexQuadResult
simplexquad
(Function<double[], Double> f, int n, int order, double tol) static double
softmin
(double x, double y, double alpha) Softmin function.static double[][]
transpose
(double[][] data) Transposes a 2D array of values.static Matrix
uniquePerms
(Matrix vec)
-
Constructor Details
-
Maths
public Maths()
-
-
Method Details
-
softmin
public static double softmin(double x, double y, double alpha) Softmin function.- Parameters:
x
- first term to comparey
- second term to comparealpha
- softmin smoothing parameter- Returns:
- Softmin function value
-
max
public static double max(double x, double y) Returns the max of two numbers. If one of the two is NaN, it returns the other.- Parameters:
x
- - the first number to be comparedy
- - the second number to be compared- Returns:
- - the max between the two
-
min
public static double min(double x, double y) Returns the min of two numbers. If one of the two is NaN, it returns the other.- Parameters:
x
- - the first number to be comparedy
- - the second number to be compared- Returns:
- - the min between the two
-
erf
public static double erf(double x) -
setRandomNumbersMatlab
public static void setRandomNumbersMatlab(boolean matlab_style) -
randomMatlabStyle
public static boolean randomMatlabStyle() -
setMatlabRandomSeed
public static void setMatlabRandomSeed(long seed) -
rand
public static double rand() -
randn
public static double randn() -
fact
public static int fact(int n) -
factln
public static double factln(int n) -
fact
public static double fact(double n) -
factln
public static double factln(double n) -
gammaFunction
public static double gammaFunction(double x) -
circul
-
circul
-
hist
Implementation of MATLAB "hist": puts elements of v into k bins- Parameters:
v
- - vector of elementsminVal
- - lowest number in vmaxVal
- - highest number in v- Returns:
- - vector containing number of elements in each bin
-
perms
-
uniquePerms
-
nchoosek
public static double nchoosek(double n, double k) -
nchoosek
Computes the combinations of the elements in v taken k at a time- Parameters:
v
- - vector of elementsk
- - how many elements to pick at a time- Returns:
- - the combinations of the elements in v taken k at a time
-
multinomialln
-
multichoose
-
multiChooseCon
-
cumSum
public static int[] cumSum(int[] ar) Cumulative sum of an array, where the value at each index of the result is the sum of all the previous values of the input.- Parameters:
ar
- Array we want the cumulative sum of.- Returns:
- New array that is the cumulative sum of the input.
-
cumSum
public static double[] cumSum(double[] ar) Cumulative sum of an array, where the value at each index of the result is the sum of all the previous values of the input.- Parameters:
ar
- Array we want the cumulative sum of.- Returns:
- New array that is the cumulative sum of the input.
-
linspace
public static double[] linspace(double start, double end, int num) -
logspace
public static double[] logspace(double min, double max, int n) -
logspacei
public static int[] logspacei(int start, int stop, int n) Generates an integer list of n logarithmically spaced values.- Parameters:
start
- First element of array.stop
- Last element of array.n
- Number of values.- Returns:
- Array of logarithmically spaced values.
-
transpose
public static double[][] transpose(double[][] data) Transposes a 2D array of values.- Parameters:
data
- 2D array to be transposed.- Returns:
- New 2D array of transposed data.
-
elementAdd
public static void elementAdd(int[] ar, int i) Helper method that adds an integer to every element of an integer array.- Parameters:
ar
- Array to be added to.i
- Integer to add.
-
nextPowerOfTwo
protected static int nextPowerOfTwo(int x) Given an integer x input, find the next integer y greater than x such that y is a power of 2.- Parameters:
x
- Input to find next power- Returns:
- Closest integer greater than input that is a power of two.
-
grnmol
public static Maths.simplexQuadResult grnmol(Function<double[], Double> f, double[][] V, int s, double tol) Grundmann-Moeller simplex integration -
simplex_fun
-
simplexquad
public static Maths.simplexQuadResult simplexquad(Function<double[], Double> f, int n, int order, double tol) -
logmeanexp
-
roots
-
roots
public static org.apache.commons.math3.complex.Complex[] roots(double[] coefficients) -
num_grad_h_complex
public static ComplexMatrix num_grad_h_complex(Matrix x0, double h, SerializableFunction<Matrix, ComplexMatrix> hfun) -
num_grad_h
-
sub2ind
-
num_hess_h_complex
public static ComplexMatrix num_hess_h_complex(Matrix x0, double h, SerializableFunction<Matrix, ComplexMatrix> hfun) -
num_hess_h
-
laplaceapprox_h_complex
public static Maths.laplaceApproxComplexReturn laplaceapprox_h_complex(Matrix x0, SerializableFunction<Matrix, ComplexMatrix> h) -
laplaceapprox_h
public static Maths.laplaceApproxReturn laplaceapprox_h(Matrix x0, SerializableFunction<Matrix, Matrix> h) -
main
-