ProductKernel<T>
Models & Types · AiDotNet.Kernels
Implements a Product kernel that combines multiple kernels by multiplying their outputs.
Implements: IKernelFunction<T>
For Beginners
The Product kernel combines multiple kernels by multiplying their similarity scores. This creates interactions between different pattern types.
In mathematical terms: k_prod(x, x’) = k1(x, x’) × k2(x, x’) × … × kn(x, x’)
How It Works
Why use Product kernels?
- Scaling: Multiply a kernel by a Constant kernel to scale its output
- ConstantKernel(c) × RBF = Scaled RBF kernel
- Interaction effects: When patterns only appear under certain conditions
- RBF × Periodic: Smooth patterns that also vary periodically
- Automatic Relevance Determination (ARD): Create dimension-specific scaling
by multiplying kernels over different feature subsets
- Non-stationary patterns: Combine with location-dependent kernels
Key difference from Sum kernel:
- Sum: Each kernel contributes independently (additive decomposition)
- Product: Kernels interact multiplicatively (AND-like combination)
Example: RBF × Periodic means “similar if BOTH spatially close AND at similar phase” (requires both conditions), while RBF + Periodic means “similar if EITHER close OR at similar phase” (either condition helps).
Example
using AiDotNet.Kernels;
using AiDotNet.Tensors.LinearAlgebra;
var kernel = new ProductKernel<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($"ProductKernel: K(a, b) = {similarity:F4}");
Constructors
| Constructor | Summary |
|---|---|
ProductKernel(IKernelFunction<T>[] kernels) |
Initializes a new Product kernel from an array of kernels. |
Methods
| Method | Summary |
|---|---|
IKernelFunction<T>[] GetKernels() |
Gets the component kernels in this product. |
T Calculate(Vector<T> x1, Vector<T> x2) |
Calculates the Product kernel value between two vectors. |