ExpSineSquaredKernel<T>
Models & Types · AiDotNet.Kernels
Implements the Exp-Sine-Squared (Periodic) kernel for modeling repeating patterns.
Implements: IKernelFunction<T>
For Beginners
The Exp-Sine-Squared kernel is designed for data that has repeating patterns, like daily temperature cycles, seasonal sales, or heartbeat signals.
In mathematical terms: k(x, x’) = exp(-2 * sin²(π * |x - x’| / period) / lengthScale²)
Where:
- period: How often the pattern repeats (e.g., 24 hours for daily cycles)
- lengthScale: How smooth the pattern is within each period
How It Works
Think of it like a wave function that repeats forever. If you have:
- Daily temperature data, period = 24 (hours)
- Yearly sales data, period = 12 (months) or 365 (days)
- Weekly patterns, period = 7 (days)
The kernel considers points at the same phase of the cycle as similar, regardless of how many cycles apart they are. So Monday’s data is similar to other Mondays, even if they’re weeks apart.
This kernel is commonly used in:
- Time series forecasting with seasonal patterns
- Signal processing with periodic components
- Any domain where you expect repeating behavior
Example
using AiDotNet.Kernels;
using AiDotNet.Tensors.LinearAlgebra;
var kernel = new ExpSineSquaredKernel<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($"ExpSineSquaredKernel: K(a, b) = {similarity:F4}");
Constructors
| Constructor | Summary |
|---|---|
ExpSineSquaredKernel(double period, double lengthScale) |
Initializes a new instance of the Exp-Sine-Squared (Periodic) kernel. |
Methods
| Method | Summary |
|---|---|
T Calculate(Vector<T> x1, Vector<T> x2) |
Calculates the Exp-Sine-Squared kernel value between two vectors. |