Class NumericalUtil
Defined in File numerical_util.hpp
Class Documentation
-
class NumericalUtil
Utility class for various numerical operations including interpolation, regression, optimization, and variability estimation.
Public Static Functions
-
static inline std::vector<double> calculate_first_derivative(const std::vector<double> &x, const std::vector<double> &y)
Computes the first derivative (finite difference) of y with respect to x.
- Parameters:
x – Vector of x-values.
y – Vector of y-values.
- Returns:
Vector of approximate derivatives.
-
static inline std::string to_lower_case(const std::string &str)
Converts a string to lowercase.
- Parameters:
str – Input string.
- Returns:
Lowercase version of the string.
-
static int spline(const double *x, const double *y, int n, double yp1, double ypn, double *y2, double *u)
Computes the second derivatives (spline coefficients) for natural cubic spline.
- Parameters:
x – Input x-values.
y – Input y-values.
n – Number of points.
yp1 – First derivative at first point.
ypn – First derivative at last point.
y2 – Output array for second derivatives.
u – Temporary array for intermediate results.
- Returns:
Status code.
-
static int splint(const double *xa, const double *ya, double *y2a, int n, double x, double *y, int klo = -1, int khi = -1)
Evaluates cubic spline interpolation.
- Parameters:
xa – x-values used in spline.
ya – y-values used in spline.
y2a – Second derivatives computed by spline().
n – Number of data points.
x – The point to evaluate the spline at.
y – Output interpolated value.
klo – Optional: lower index for interval search.
khi – Optional: upper index for interval search.
- Returns:
Status code.
-
static void interpolate_values(int size, const double *x, const double *y, double *u, int size2, const double *x2, double *y2, double *y2a, bool truncate = false, bool extrapolate = false)
Interpolates a set of values onto another grid.
- Parameters:
size – Size of original data.
x – Input x-values.
y – Input y-values.
u – Temporary buffer.
size2 – Size of output grid.
x2 – New x-values.
y2 – Output interpolated y-values.
y2a – Temporary buffer for spline coefficients.
truncate – Whether to truncate output range.
extrapolate – Whether to allow extrapolation.
-
static void gaussian_kernal2_d(const arma::mat &surface, arma::mat &output, double bwx, double bwy)
Applies a 2D Gaussian kernel smoother to a surface.
- Parameters:
surface – Input matrix (data grid).
output – Smoothed output.
bwx – Bandwidth in x-direction.
bwy – Bandwidth in y-direction.
-
static void local_polynomial_regression(const arma::mat &xyw, arma::mat &xy2, double bw, unsigned int order)
Performs local polynomial regression on a dataset.
- Parameters:
xyw – Input matrix of (x, y, weights).
xy2 – Output matrix of (x, smoothed y).
bw – Bandwidth for kernel.
order – Polynomial order.
-
static void gaussian_kernal1_d(const arma::mat &xyw, arma::mat &xy2, double bw)
Applies a 1D Gaussian kernel smoother to weighted data.
- Parameters:
xyw – Input matrix of (x, y, weights).
xy2 – Output matrix of (x, smoothed y).
bw – Bandwidth for kernel.
-
static void local_regression(const arma::mat &xyw, arma::mat &xy2, double bw, unsigned int order)
Performs 1D local regression on a dataset.
- Parameters:
xyw – Input matrix of (x, y, weights).
xy2 – Output matrix of (x, smoothed y).
bw – Bandwidth.
order – Polynomial order.
-
static int newton(double &x, double (&f)(double), double (&fdiv)(double), int max_loop, double accuracy)
Newton’s method to find a root of a function.
- Parameters:
x – Input and output: initial guess and result.
f – Function whose root to find.
fdiv – Derivative of the function.
max_loop – Maximum number of iterations.
accuracy – Target accuracy.
- Returns:
Status code.
-
static double zbrent(double (*func)(double, void *adata), double x1, double x2, double tol, double ftol, int ITMAX, void *adata)
Finds a root using Brent’s method.
Note
Using Brent’s method, find the root of a function func known to lie between x1 and x2. The root, returned as zbrent, will be refined until its accuracy is tol.
- Parameters:
func – Function whose root to find.
x1 – Lower bound of root.
x2 – Upper bound of root.
tol – Tolerance for root location.
ftol – Tolerance for function value.
ITMAX – Maximum number of iterations.
adata – Additional data for the function.
- Returns:
The computed root.
-
static double first_order_variability(const std::vector<double> &x, const std::vector<double> &y, const std::vector<double> &ye)
Computes first-order variability measure of a curve.
- Parameters:
x – Vector of x-values.
y – Vector of y-values.
ye – Vector of y-errors or weights.
- Returns:
First-order variability measure.
-
static double second_order_variability(const std::vector<double> &x, const std::vector<double> &y, const std::vector<double> &ye)
Computes second-order variability measure of a curve.
- Parameters:
x – Vector of x-values.
y – Vector of y-values.
ye – Vector of y-errors or weights.
- Returns:
Second-order variability measure.
-
static inline std::vector<double> calculate_first_derivative(const std::vector<double> &x, const std::vector<double> &y)