ArcKernel<T>

Models & Types · AiDotNet.Kernels

Arc (Angular) Kernel based on the angle between vectors.

Implements: IKernelFunction<T>

For Beginners

The Arc Kernel (also called Angular Kernel) is based on the angle θ between two vectors rather than their Euclidean distance.

In mathematical terms: k(x, x’) = 1 - (2/π) × arccos(cosine_similarity(x, x’)) = 1 - (2/π) × θ

Where θ is the angle between x and x’ in radians.

Properties:

  • Returns values in [0, 1]
  • k(x, x) = 1 (same vector)
  • k(x, x’) = 0 when vectors are opposite (θ = π)
  • k(x, x’) = 0.5 when vectors are orthogonal (θ = π/2)

Unlike the Cosine Kernel, the Arc Kernel is positive semi-definite, making it suitable for use as a GP kernel.

Applications:

  • Directional data (wind direction, compass headings)
  • Spherical data (locations on Earth, molecular orientations)
  • Any data where only direction matters

Example

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

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

Constructors

Constructor Summary
ArcKernel(int order, double outputScale) Initializes a new Arc Kernel.

Properties

Property Summary
double OutputScale { get; } Gets the output scale.
int Order { get; } Gets the kernel order.

Methods

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