alib
Universal C Library Collection for Machine Learning & Artificial Intelligence
|
A simple calculus library header. More...
#include <math.h>
Go to the source code of this file.
Data Structures | |
struct | calc_function |
Structure representing an function and its derivative. More... | |
Typedefs | |
typedef struct calc_function | calc_function |
Structure representing an function and its derivative. | |
typedef double(* | calc_function_fn) (double) |
A function pointer type for functions. | |
Functions | |
double | calc_approx_derivative (double(*f)(double), double x, double h) |
Calculate the numerical derivative of a function at a point. | |
double | calc_approx_finite_integral (double(*f)(double), double a, double b, int n) |
Calculate the numerical integral of a function over an interval. | |
double | calc_function_negation (double x) |
Negate the value of a given double. | |
double | calc_function_negation_derivative (double x) |
Calculate the derivative of the negation function. | |
double | calc_function_relu (double x) |
Calculate the ReLU (Rectified Linear Unit) function. | |
double | calc_function_relu_derivative (double x) |
Calculate the derivative of the ReLU function. | |
double | calc_function_sigmoid (double x) |
Calculate the sigmoid function. | |
double | calc_function_sigmoid_derivative (double x) |
Calculate the derivative of the sigmoid function. | |
double | calc_function_square (double x) |
Calculate the square of a given double. | |
double | calc_function_square_derivative (double x) |
Calculate the derivative of the square function. | |
double | calc_function_tanh (double x) |
Calculate the Tanh function. | |
double | calc_function_tanh_derivative (double x) |
Calculate the derivative of the Tanh function. | |
Variables | |
const calc_function | CALC_FUNCTION_NEGATION |
Predefined negation function. | |
const calc_function | CALC_FUNCTION_RELU |
Predefined ReLU function. | |
const calc_function | CALC_FUNCTION_SIGMOID |
Predefined Sigmoid function. | |
const calc_function | CALC_FUNCTION_SQUARE |
Predefined square function. | |
const calc_function | CALC_FUNCTION_TANH |
Predefined Tanh function. | |
A simple calculus library header.
This header file contains declarations for mathematical calculation functions, including numerical differentiation and integration. The implementations of these functions are included in the compiled library lib/libcalc.so
.
Definition in file calc.h.
typedef struct calc_function calc_function |
Structure representing an function and its derivative.
This structure holds the name of the function, the function itself, and its derivative function.
typedef double(* calc_function_fn) (double) |
double calc_approx_derivative | ( | double(*)(double) | f, |
double | x, | ||
double | h ) |
Calculate the numerical derivative of a function at a point.
This function approximates the derivative of a given function \( f \) at a point \( x \) using the central difference method:
\[ f'(x) \approx \frac{f(x + h) - f(x - h)}{2h} \]
f | Pointer to the function to differentiate. |
x | The point at which to evaluate the derivative. |
h | A small value for the finite difference approximation. |
double calc_approx_finite_integral | ( | double(*)(double) | f, |
double | a, | ||
double | b, | ||
int | n ) |
Calculate the numerical integral of a function over an interval.
This function approximates the integral of a given function \( f \) over the interval \([a, b]\) using the trapezoidal rule:
\[ \int_a^b f\left(x\right) \, dx \approx \frac{b - a}{2n} \sum_{i=0}^{n-1} \left(f\left(x_i\right) + f\left(x_{i+1}\right)\right) \]
f | Pointer to the function to integrate. |
a | The lower limit of integration. |
b | The upper limit of integration. |
n | The number of subintervals. |
double calc_function_negation | ( | double | x | ) |
Negate the value of a given double.
This function takes a double value and returns its negation.
Example usage:
x | The value to be negated. |
double calc_function_negation_derivative | ( | double | x | ) |
Calculate the derivative of the negation function.
This function calculates the derivative of the negation function, which is \( -1 \) for any value of \( x \).
x | The value at which to evaluate the derivative. |
double calc_function_relu | ( | double | x | ) |
Calculate the ReLU (Rectified Linear Unit) function.
The ReLU function is defined as: \[ \text{ReLU}(x) = \max(0, x) \]
This function is commonly used as an function in neural networks.
x | The input value. |
Example:
double calc_function_relu_derivative | ( | double | x | ) |
Calculate the derivative of the ReLU function.
The derivative of the ReLU function is: \[ \text{ReLU}'(x) = \begin{cases} 1 & \text{if } x > 0 \\ 0 & \text{if } x \leq 0 \end{cases} \]
x | The input value. |
Example:
double calc_function_sigmoid | ( | double | x | ) |
Calculate the sigmoid function.
The sigmoid function, \( \sigma(x) \), is defined as: \[ \sigma(x) = \frac{1}{1 + e^{-x}} \]
The sigmoid function maps any real-valued number \( x \) to a value in the range (0, 1). It is commonly used in logistic regression and as an activation function in neural networks.
x | The input value. |
Example:
double calc_function_sigmoid_derivative | ( | double | x | ) |
Calculate the derivative of the sigmoid function.
The derivative of the sigmoid function is defined as: \[ \sigma'(x) = \sigma(x) \cdot (1 - \sigma(x)) \]
This function is used during the backpropagation step in neural networks.
x | The input value. |
Example:
double calc_function_square | ( | double | x | ) |
Calculate the square of a given double.
This function takes a double value and returns its square.
Example usage:
x | The value to be squared. |
double calc_function_square_derivative | ( | double | x | ) |
Calculate the derivative of the square function.
This function calculates the derivative of the square function, which is \( 2x \).
x | The value at which to evaluate the derivative. |
double calc_function_tanh | ( | double | x | ) |
Calculate the Tanh function.
The Tanh function is defined as: \[ \tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}} \]
This function maps any real-valued number \( x \) to a value in the range (-1, 1). It is commonly used as an function in neural networks.
x | The input value. |
Example:
double calc_function_tanh_derivative | ( | double | x | ) |
Calculate the derivative of the Tanh function.
The derivative of the Tanh function is defined as: \[ \tanh'(x) = 1 - \tanh^2(x) \]
This function is used during the backpropagation step in neural networks.
x | The input value. |
Example:
|
extern |
Predefined negation function.
This constant represents the negation function and its derivative.
|
extern |
Predefined ReLU function.
This constant represents the ReLU function and its derivative.
|
extern |
Predefined Sigmoid function.
This constant represents the Sigmoid function and its derivative.
|
extern |
Predefined square function.
This constant represents the square function and its derivative.
|
extern |
Predefined Tanh function.
This constant represents the Tanh function and its derivative.