naginterfaces.library.tsa.cp_​binary_​user

naginterfaces.library.tsa.cp_binary_user(n, beta, chgpfn, minss=2, mdepth=0, data=None)[source]

cp_binary_user detects change points in a univariate time series, that is, the time points at which some feature of the data, for example the mean, changes. Change points are detected using binary segmentation for a user-supplied cost function.

For full information please refer to the NAG Library document for g13ne

https://www.nag.com/numeric/nl/nagdoc_28.6/flhtml/g13/g13nef.html

Parameters
nint

, the length of the time series.

betafloat

, the penalty term.

There are a number of standard ways of setting , including:

SIC or BIC

.

AIC

.

Hannan-Quinn

.

where is the number of parameters being treated as estimated in each segment.

The value of will depend on the cost function being used.

If no penalty is required then set .

Generally, the smaller the value of the larger the number of suggested change points.

chgpfncallable (v, cost, info) = chgpfn(side, u, w, minss, info, data=None)

must calculate a proposed change point, and the associated costs, within a specified segment.

Parameters
sideint

Flag indicating what must calculate and at which point of the Binary Segmentation it has been called.

only need be calculated and returned in , neither nor the other elements of need be set. In this case, and .

all elements of and must be set. In this case, and .

the segment, , is a left-hand side subsegment from a previous iteration of the Binary Segmentation algorithm. All elements of and must be set.

the segment, , is a right-hand side subsegment from a previous iteration of the Binary Segmentation algorithm. All elements of and must be set.

The distinction between or may allow for to be implemented in a more efficient manner.

The first call to will always have and the second call will always have .

All subsequent calls will be made with or .

uint

, the start of the segment of interest.

wint

, the end of the segment of interest.

minssint

The minimum distance between two change points, as passed to cp_binary_user.

infoint

.

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

Returns
vint

If then need not be set.

if then , the proposed change point.

That is, the value which minimizes

for to .

costfloat, array-like, shape

Costs associated with the proposed change point, .

If then and the remaining two elements of need not be set.

If then

.

.

.

infoint

In most circumstances should remain unchanged.

If is set to a strictly positive value then cp_binary_user terminates with = 51.

If is set to a strictly negative value the current segment is skipped (i.e., no change points are considered in this segment) and cp_binary_user continues as normal.

If was set to a strictly negative value at any point and no other errors occur then cp_binary_user will terminate with = 52.

minssint, optional

The minimum distance between two change points, that is .

mdepthint, optional

, the maximum depth for the iterative process, which in turn puts an upper limit on the number of change points with .

If then no limit is put on the depth of the iterative process and no upper limit is put on the number of change points, other than that inherent in the length of the series and the value of .

dataarbitrary, optional

User-communication data for callback functions.

Returns
ntauint

, the number of change points detected.

tauint, ndarray, shape

The first elements of hold the location of the change points. The th segment is defined by to , where and .

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

User requested termination by setting .

Warns
NagAlgorithmicWarning
(errno )

User requested a segment to be skipped by setting .

Notes

Let denote a series of data and denote a set of ordered (strictly monotonic increasing) indices known as change points with and . For ease of notation we also define . The change points, , split the data into segments, with the th segment being of length and containing .

Given a cost function, , cp_binary_user gives an approximate solution to

where is a penalty term used to control the number of change points. The solution is obtained in an iterative manner as follows:

  1. Set , and

  2. Set . If , where is a user-supplied control parameter, then terminate the process for this segment.

  3. Find that minimizes

  4. Test

  5. If inequality [equation] is false then the process is terminated for this segment.

  6. If inequality [equation] is true, then is added to the set of change points, and the segment is split into two subsegments, and . The whole process is repeated from step 2 independently on each subsegment, with the relevant changes to the definition of and (i.e., is set to when processing the left-hand subsegment and is set to when processing the right-hand subsegment.

The change points are ordered to give .

References

Chen, J and Gupta, A K, 2010, Parametric Statistical Change Point Analysis With Applications to Genetics, Medicine and Finance (Second Edition), Birkhäuser