DotProductKernel<T>

Models & Types · AiDotNet.Kernels

Implements the Dot Product (Linear) kernel with optional inhomogeneity.

Implements: IKernelFunction<T>

For Beginners

The Dot Product kernel measures similarity by computing the inner product (dot product) between two vectors, optionally with a constant offset.

In mathematical terms: k(x, x’) = σ₀² + x · x’

Where:

  • σ₀² is the variance of the constant offset (inhomogeneity parameter)
  • x · x’ is the dot product (sum of element-wise products)

How It Works

Why use the Dot Product kernel?

  1. Linear relationships: When your data has a linear relationship, this kernel works well
  • Equivalent to Bayesian linear regression when used in a GP
  1. Interpretability: Each feature’s contribution is directly proportional to its value

  2. Computational efficiency: Very fast to compute, O(d) for d-dimensional vectors

  3. Feature importance: In a GP with this kernel, the predictive variance grows

indefinitely away from the origin, which can be useful for extrapolation

The inhomogeneity parameter σ₀² adds a constant “bias” to all similarities, which allows the model to capture a non-zero mean function.

Example

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

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

Constructors

Constructor Summary
DotProductKernel(double sigma0Squared) Initializes a new instance of the Dot Product kernel.

Methods

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