AdditiveChiSquaredKernel<T>

Models & Types · AiDotNet.Kernels

Implements the Additive Chi-Squared kernel function for measuring similarity between data points.

Implements: IKernelFunction<T>

For Beginners

A kernel function is a way to measure how similar two data points are to each other. Think of it like a special ruler that can measure distance in complex data spaces. The Additive Chi-Squared kernel is particularly good at comparing data that represents counts or frequencies (like how many times words appear in documents, or how many pixels of each color appear in images).

How It Works

The Additive Chi-Squared kernel is a variation of the Chi-Squared distance measure that is particularly useful for histogram comparison in image recognition, document classification, and other applications where data is represented as frequency distributions.

The kernel is defined as K(x,y) = -log(1 + S[(x_i - y_i)²/(x_i + y_i)]) for all dimensions i.

Unlike regular distance measures where smaller values mean “closer” (more similar), kernel functions typically return larger values for more similar items. This kernel transforms the Chi-Squared distance so that more similar items have higher values.

Example

using AiDotNet.Kernels;
using AiDotNet.Tensors.LinearAlgebra;

var kernel = new AdditiveChiSquaredKernel<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($"AdditiveChiSquaredKernel: K(a, b) = {similarity:F4}");

Constructors

Constructor Summary
AdditiveChiSquaredKernel() Initializes a new instance of the Additive Chi-Squared kernel.

Methods

Method Summary
T Calculate(Vector<T> x1, Vector<T> x2) Calculates the Additive Chi-Squared kernel value between two vectors.