-
-
Notifications
You must be signed in to change notification settings - Fork 41
Kernels Library
Omega Joctan edited this page Mar 3, 2024
·
1 revision
The kernels.mqh
library provides an essential set of kernel functions commonly used in machine learning, particularly for Support Vector Machines (SVMs). These kernels act as similarity measures between data points and play a crucial role in transforming data into a higher-dimensional space, enabling linear separation for classification tasks.
Supported Kernels:
- KERNEL_LINEAR: The simplest kernel, representing the dot product of input vectors.
- KERNEL_POLYNOMIAL: Allows modeling polynomial relationships between data points.
- KERNEL_RADIAL_BASIS_FUNCTION_RBF: Also known as the Gaussian kernel, captures complex, non-linear relationships. One of the most commonly used kernels.
- KERNEL_SIGMOID: Inspired by the sigmoid function, often used in conjunction with SVMs for classification.
The __kernels__
Class:
- Encapsulates the chosen kernel type, along with relevant hyperparameters:
-
alpha
(for Sigmoid kernel only) -
beta
(for Sigmoid kernel only) -
degree_polynomial
(for Polynomial kernel only) -
sigma
(for RBF kernel only)
-
- Provides member functions for calculating the kernel matrix between two data matrices:
LinearKernel(matrix &x1, matrix &x2)
-
PolynomialKernel(matrix &x1, matrix &x2, double lambda=1)
(optionallambda
parameter) RBFKernel(const matrix &x1, const matrix &x2)
SigmoidKernel(matrix &x1, matrix &x2)
- Offers a unified
KernelFunction(matrix &x1, matrix &x2)
function that selects and executes the appropriate kernel function based on the chosen kernel type.
Key Points:
- The constructor for
__kernels__
allows specifying the desired kernel type and initializing hyperparameters (optional, with default values). - Kernel functions operate on MQL5 matrices, representing data points as rows and features as columns.
- Understanding the specific properties and suitable applications of each kernel is crucial for effective machine learning model selection and hyperparameter tuning.
Incorporating the Library:
#include "kernels.mqh"
Example Usage:
// Example: Using the RBF kernel
__kernels__ kernel(KERNEL_RADIAL_BASIS_FUNCTION_RBF, sigma=0.5); // Set sigma for RBF kernel
matrix data1, data2;
// ... populate data matrices ...
matrix kernel_matrix = kernel.KernelFunction(data1, data2);
// Use the kernel matrix for further machine learning tasks (e.g., SVM training)
By understanding and utilizing the kernels.mqh
library, MQL5 users can leverage various kernel functions for their machine learning projects, particularly those involving SVMs and non-linear data relationships.