HistogramIntersectionKernel<T>
Models & Types · AiDotNet.Kernels
Implements the Histogram Intersection 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 Histogram Intersection kernel is especially useful when your data represents frequencies, counts, or distributions (like histograms in image processing).
How It Works
The Histogram Intersection kernel is a similarity measure commonly used in image recognition and classification tasks. It measures similarity by finding the “overlap” between two vectors.
Think of this kernel as comparing two histograms (or any two sets of non-negative values) by looking at their overlap. For each pair of corresponding values, it takes the smaller one (the overlap) and adds it to the total similarity. The more overlap there is, the higher the similarity score.
This kernel works best when your data contains non-negative values, such as pixel intensities, word frequencies, or other count-based features. It’s particularly popular in computer vision and document classification.
Note: For proper use of the Histogram Intersection kernel, input vectors should contain non-negative values. If your data has negative values, you might need to preprocess it before using this kernel.
Example
using AiDotNet.Kernels;
using AiDotNet.Tensors.LinearAlgebra;
var kernel = new HistogramIntersectionKernel<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($"HistogramIntersectionKernel: K(a, b) = {similarity:F4}");
Constructors
| Constructor | Summary |
|---|---|
HistogramIntersectionKernel() |
Initializes a new instance of the Histogram Intersection kernel. |
Methods
| Method | Summary |
|---|---|
T Calculate(Vector<T> x1, Vector<T> x2) |
Calculates the Histogram Intersection kernel value between two vectors. |