Class RBFCostFunction
- Namespace
- SignalSharp.CostFunctions.Cost
- Assembly
- SignalSharp.dll
Represents a cost function using the Radial Basis Function (RBF) kernel for the Piecewise Linear Trend Change (PELT) method.
public class RBFCostFunction : CostFunctionBase, IPELTCostFunction
- Inheritance
-
RBFCostFunction
- Implements
- Inherited Members
Remarks
The Radial Basis Function (RBF) kernel is commonly used in various machine learning algorithms, such as support vector machines and Gaussian processes, due to its ability to handle non-linear relationships between data points. It transforms the input data into a higher-dimensional space where it becomes easier to separate or cluster the data using linear methods.
In the context of the Piecewise Linear Trend Change (PELT) method, the RBF kernel is utilized to compute the cost of segmenting a time series or sequential data into different segments where the statistical properties change. This approach is beneficial when the underlying data relationships are complex and non-linear, making simple linear models insufficient.
The gamma parameter in the RBF kernel controls the influence of individual data points. A small gamma value means that the influence of a single training example reaches far, while a large gamma value means that the influence is close. The algorithm can automatically compute an appropriate gamma if not provided, using the median heuristic from the pairwise distances.
Consider using the RBF cost function in scenarios where:
- The data exhibits complex, non-linear patterns.
- You need to segment time series data into distinct regimes or phases.
- Traditional linear models are not capturing the underlying data structure effectively.
Constructors
RBFCostFunction(double?)
Initializes a new instance of the RBFCostFunction class with an optional gamma parameter.
public RBFCostFunction(double? gamma = null)
Parameters
gamma
double?The gamma parameter for the RBF kernel. If null, it will be calculated automatically based on the data.
Remarks
The gamma parameter defines the influence of individual data points in the RBF kernel. A smaller gamma value means a broader influence, while a larger gamma value means a more localized influence. If not provided, the gamma parameter is estimated using the median heuristic based on pairwise distances between data points.
Methods
ComputeCost(int?, int?)
Computes the cost for a segment of the data using the RBF kernel.
public override double ComputeCost(int? start = null, int? end = null)
Parameters
start
int?The start index of the segment. If null, defaults to 0.
end
int?The end index of the segment. If null, defaults to the length of the data.
Returns
- double
The computed cost for the segment.
Remarks
The cost function measures the dissimilarity of the segment compared to the rest of the data, which is useful for detecting change points in time series analysis.
This method must be called after the Fit(double[,]) method has been used to initialize the data and compute the necessary matrices.
var rbfCost = new RBFCostFunction().Fit(data);
double cost = rbfCost.ComputeCost(0, 10);
This computes the cost for the segment of the data from index 0 to index 10.
Exceptions
- UninitializedDataException
Thrown when data, distances, or prefix sum is not initialized.
- ArgumentOutOfRangeException
Thrown when the segment indices are out of bounds.
- SegmentLengthException
Thrown when the segment length is less than 1.
Fit(double[,])
Fits the cost function to the provided data.
public override IPELTCostFunction Fit(double[,] signalMatrix)
Parameters
signalMatrix
double[,]The signal matrix to fit.
Returns
- IPELTCostFunction
The fitted RBFCostFunction instance.
Remarks
This method initializes the internal structures needed to compute the cost for segments of the data. It calculates the pairwise distances between data points, applies the RBF kernel to these distances, and precomputes the prefix sum matrix for efficient cost computation later.
double[,] data = { { 1.0, 2.0, 3.0, 4.0 } };
var rbfCost = new RBFCostFunction().Fit(data);
This initializes the cost function with the provided data, making it ready for segment cost computation.
Exceptions
- ArgumentNullException
Thrown when data is null.