StringKernel<T>

Models & Types · AiDotNet.Kernels

Implements various string kernels for comparing text/sequence data in Gaussian Processes.

For Beginners

String kernels allow Gaussian Processes to work directly with text or sequence data without needing to convert them to fixed-length feature vectors.

The key insight: We can define a kernel (similarity measure) between strings that captures meaningful notions of similarity:

  • Spectrum kernel: Counts shared substrings
  • Subsequence kernel: Counts shared (possibly non-contiguous) subsequences
  • Edit distance kernel: Based on how many edits to transform one string to another

Applications:

  • Text classification (spam detection, sentiment analysis)
  • Bioinformatics (DNA/protein sequence comparison)
  • Natural language processing
  • Any domain with sequential/string data

How It Works

Note: This class does NOT implement IKernelFunction by design. Unlike numeric kernels that operate on Vector feature vectors, string kernels operate directly on text data. To use string kernels with standard GP models, use this class to compute a kernel matrix from your text data, then use that matrix with a custom kernel implementation.

Constructors

Constructor Summary
StringKernel(KernelType<T> kernelType, int substringLength, double lambda, double scale) Initializes a new string kernel.

Properties

Property Summary
KernelType<T> Type { get; } Gets the kernel type.

Methods

Method Summary
Matrix<T> ComputeKernelMatrix(string[] strings) Creates a kernel matrix for a collection of strings.
T Calculate(string s1, string s2) Calculates the string kernel value between two strings.