ConstantKernel<T>
Models & Types · AiDotNet.Kernels
Implements the Constant kernel, which returns a constant value regardless of input.
Implements: IKernelFunction<T>
For Beginners
The Constant kernel is the simplest possible kernel - it always returns the same value, no matter what inputs you give it.
In mathematical terms: k(x, x’) = c
Where c is a constant value (the “constant value” parameter).
How It Works
Why would you want a kernel that ignores the input?
The Constant kernel is primarily used as a building block for more complex kernels:
- Scaling other kernels: When you multiply the Constant kernel with another kernel
(like RBF), you can control the overall scale of your predictions.
- ConstantKernel(c) * RBFKernel() gives you a scaled RBF kernel
- Adding bias: When you add a Constant kernel to another kernel, you’re essentially
adding a constant offset to all predictions.
- RBFKernel() + ConstantKernel(c) adds a “baseline” to your model
- Modeling a constant mean: In Gaussian Processes, the Constant kernel represents
the assumption that all points have some shared, constant relationship.
By itself, the Constant kernel assumes that all data points are equally similar to each other - not very useful! But combined with other kernels, it’s a powerful tool.
Example
using AiDotNet.Kernels;
using AiDotNet.Tensors.LinearAlgebra;
var kernel = new ConstantKernel<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($"ConstantKernel: K(a, b) = {similarity:F4}");
Constructors
| Constructor | Summary |
|---|---|
ConstantKernel(double constantValue) |
Initializes a new instance of the Constant kernel. |
Methods
| Method | Summary |
|---|---|
T Calculate(Vector<T> x1, Vector<T> x2) |
Calculates the Constant kernel value between two vectors. |