PolynomialKernel<T>

Models & Types · AiDotNet.Kernels

Implements the Polynomial 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 Polynomial kernel is special because it can find complex patterns in your data by implicitly mapping your data to a higher-dimensional space without actually performing the expensive calculations that would normally be required.

How It Works

The Polynomial kernel is a popular kernel function used in machine learning algorithms like Support Vector Machines (SVMs) to find patterns in higher-dimensional spaces.

Think of the Polynomial kernel as a “pattern detector” that can identify more complex relationships than simple linear patterns. For example, if you’re trying to classify data that can’t be separated by a straight line, the Polynomial kernel can help find a curved boundary instead.

The formula for the Polynomial kernel is: k(x, y) = (x·y + c)^d 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)
  • c is a constant term (coef0) that influences the kernel’s behavior
  • d is the degree of the polynomial

Common uses include:

  • Classification problems where data isn’t linearly separable
  • Natural language processing tasks
  • Image recognition

Example

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

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

Constructors

Constructor Summary
PolynomialKernel(T degree, T coef0) Initializes a new instance of the Polynomial kernel with optional degree and coefficient parameters.

Methods

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