LaplacianKernel<T>
Models & Types · AiDotNet.Kernels
Implements the Laplacian kernel for measuring similarity between data points.
Implements: IKernelFunction<T>
For Beginners
A kernel function is a mathematical tool that measures how similar two data points are. The Laplacian kernel is like a “similarity detector” that gives higher values when points are close together and lower values when they’re far apart.
How It Works
The Laplacian kernel is a radial basis function kernel that uses the Manhattan distance (L1 norm) instead of the Euclidean distance (L2 norm) used by the Gaussian kernel. It’s particularly useful for data that has sparse features or when you want to be less sensitive to outliers.
Think of this kernel as a “distance translator” - it takes the distance between two points and converts it into a similarity score between 0 and 1. Points that are identical get a score of 1, while points that are very different get a score closer to 0.
What makes the Laplacian kernel special is how it measures distance - it uses what’s called the “Manhattan distance” or “city block distance.” Imagine you’re in a city with a grid of streets: you can only travel along the streets (not diagonally through buildings). The Manhattan distance is the total number of blocks you’d need to walk. This makes the Laplacian kernel less sensitive to outliers compared to kernels that use the straight-line (Euclidean) distance.
The Laplacian kernel is often used in machine learning tasks like classification, regression, and anomaly detection, especially when dealing with high-dimensional or sparse data.
Example
using AiDotNet.Kernels;
using AiDotNet.Tensors.LinearAlgebra;
var kernel = new LaplacianKernel<double>();
var a = new Vector<double>(new[] { 1.0, 2.0, 3.0 });
var b = new Vector<double>(new[] { 1.5, 1.0, 2.5 });
double similarity = kernel.Calculate(a, b);
Console.WriteLine($"LaplacianKernel: K(a, b) = {similarity:F4}");
Constructors
| Constructor | Summary |
|---|---|
LaplacianKernel(T sigma) |
Initializes a new instance of the Laplacian kernel with an optional bandwidth parameter. |
Methods
| Method | Summary |
|---|---|
T Calculate(Vector<T> x1, Vector<T> x2) |
Calculates the Laplacian kernel value between two vectors. |