ProbabilisticKernel<T>
Models & Types · AiDotNet.Kernels
Implements the Probabilistic 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 Probabilistic kernel is special because it considers both:
- The angle between data points (like cosine similarity)
- The difference in their magnitudes (like Gaussian kernel)
How It Works
The Probabilistic kernel combines aspects of both the cosine similarity and the Gaussian kernel, making it useful for capturing both directional and magnitude-based relationships between data points.
Think of the Probabilistic kernel as a “smart similarity detector” that can tell if two data points are pointing in similar directions AND have similar sizes. This is particularly useful when both the direction and magnitude of your data are important.
The formula for the Probabilistic kernel is: k(x, y) = (x·y / v(||x||²·||y||²)) · exp(-||x||² - ||y||²)²/(2s²)) where:
- x and y are the two data points being compared
- x·y is the dot product (a measure of how aligned the vectors are)
- ||x|| and ||y|| are the magnitudes (lengths) of the vectors
- s (sigma) is a parameter that controls sensitivity to magnitude differences
Common uses include:
- Text classification where both word presence and frequency matter
- Image recognition where both pattern and intensity are important
- Any application where both direction and magnitude of data provide useful information
Example
using AiDotNet.Kernels;
using AiDotNet.Tensors.LinearAlgebra;
var kernel = new ProbabilisticKernel<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($"ProbabilisticKernel: K(a, b) = {similarity:F4}");
Constructors
| Constructor | Summary |
|---|---|
ProbabilisticKernel(T sigma) |
Initializes a new instance of the Probabilistic kernel with an optional sigma parameter. |
Methods
| Method | Summary |
|---|---|
T Calculate(Vector<T> x1, Vector<T> x2) |
Calculates the Probabilistic kernel value between two vectors. |