GeneralizedHistogramIntersectionKernel<T>
Models & Types · AiDotNet.Kernels
Implements the Generalized 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 Generalized Histogram Intersection kernel is an extension of the standard Histogram Intersection kernel, which is commonly used in image recognition and classification tasks. It measures similarity by finding the “overlap” between two vectors, with an additional parameter (beta) to control the influence of this overlap.
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 beta parameter lets you adjust how this overlap is weighted.
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.
Example
using AiDotNet.Kernels;
using AiDotNet.Tensors.LinearAlgebra;
var kernel = new GeneralizedHistogramIntersectionKernel<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($"GeneralizedHistogramIntersectionKernel: K(a, b) = {similarity:F4}");
Constructors
| Constructor | Summary |
|---|---|
GeneralizedHistogramIntersectionKernel(T beta) |
Initializes a new instance of the Generalized Histogram Intersection kernel with an optional beta parameter. |
Methods
| Method | Summary |
|---|---|
T Calculate(Vector<T> x1, Vector<T> x2) |
Calculates the Generalized Histogram Intersection kernel value between two vectors. |