Table of Contents

Class CostFunctionBase

Namespace
SignalSharp.CostFunctions.Cost
Assembly
SignalSharp.dll

Provides a base implementation of the IPELTCostFunction interface.

public abstract class CostFunctionBase : IPELTCostFunction
Inheritance
CostFunctionBase
Implements
Derived
Inherited Members

Remarks

This abstract class includes a default implementation for fitting one-dimensional time series data by converting it to a two-dimensional format. Subclasses must implement the methods for fitting multidimensional time series data and computing the cost for a data segment.

Subclasses may also optionally implement ILikelihoodCostFunction if they provide likelihood-based metrics suitable for information criteria like BIC and AIC.

Methods

ComputeCost(int?, int?)

Computes the cost for a segment of the data.

public abstract double ComputeCost(int? start = null, int? end = null)

Parameters

start int?

The start index of the segment (inclusive). If null, defaults to 0.

end int?

The end index of the segment (exclusive). If null, defaults to the length of the data.

Returns

double

The computed cost for the segment.

Remarks

Subclasses must implement this method to calculate the cost or dissimilarity of a segment of the data, which is used by the PELT algorithm to determine the optimal segmentation.

The exact definition of "cost" depends on the specific cost function implementation. For likelihood-based costs, this might be related to the negative log-likelihood.

Exceptions

UninitializedDataException

Thrown if Fit(double[,]) or Fit(double[]) has not been called.

ArgumentOutOfRangeException

Thrown if segment indices are invalid.

SegmentLengthException

Thrown if segment length is invalid for the cost function.

Fit(double[,])

Fits the cost function to the provided multi-dimensional time series data.

public abstract IPELTCostFunction Fit(double[,] signalMatrix)

Parameters

signalMatrix double[,]

The multi-dimensional time series data to fit, where each row represents a different time series.

Returns

IPELTCostFunction

The fitted IPELTCostFunction instance.

Remarks

Subclasses must implement this method to initialize any internal structures or computations needed to evaluate segment costs later on. It prepares the cost function for subsequent calls to ComputeCost(int?, int?).

Exceptions

ArgumentNullException

Thrown if the signal matrix is null.

Fit(double[])

Fits the cost function to the provided one-dimensional time series data.

public IPELTCostFunction Fit(double[] signal)

Parameters

signal double[]

The one-dimensional time series data to fit.

Returns

IPELTCostFunction

The fitted IPELTCostFunction instance.

Remarks

This method converts the one-dimensional data into a two-dimensional format (1 row) and calls Fit(double[,]) to perform the actual fitting.

Exceptions

ArgumentNullException

Thrown if the signal is null.