naginterfaces.library.tsa.cp_pelt¶
- naginterfaces.library.tsa.cp_pelt(ctype, y, beta=None, minss=2, param=None)[source]¶
cp_pelt
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 the PELT (Pruned Exact Linear Time) algorithm using one of a provided set of cost functions.For full information please refer to the NAG Library document for g13na
https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/g13/g13naf.html
- Parameters
- ctypeint
A flag indicating the assumed distribution of the data and the type of change point being looked for.
Data from a Normal distribution, looking for changes in the mean, .
Data from a Normal distribution, looking for changes in the standard deviation .
Data from a Normal distribution, looking for changes in the mean, and standard deviation .
Data from a Gamma distribution, looking for changes in the scale parameter .
Data from an exponential distribution, looking for changes in .
Data from a Poisson distribution, looking for changes in .
- yfloat, array-like, shape
, the time series.
If , that is the data is assumed to come from a Poisson distribution, is used in all calculations.
- betaNone or float, optional
Note: if this argument is None then a default value will be used, determined as follows: if : ; otherwise: .
, 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.
This is usually set to when and otherwise.
If no penalty is required then set .
Generally, the smaller the value of the larger the number of suggested change points.
- minssint, optional
The minimum distance between two change points, that is .
- paramNone or float, array-like, shape , optional
, values for the parameters that will be treated as fixed. If then must be supplied.
If supplied, then when
, the standard deviation of the normal distribution. If not supplied then is estimated from the full input data,
, the mean of the normal distribution. If not supplied then is estimated from the full input data,
must hold the shape, , for the gamma distribution,
otherwise
is not referenced.
- 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 .
- sparamfloat, ndarray, shape or
The estimated values of the distribution parameters in each segment
, or
and for , where and is the mean and standard deviation, respectively, of the values of in the th segment.
It should be noted that when and when , for all and .
and for , where and are the shape and scale parameters, respectively, for the values of in the th segment. It should be noted that for all .
or
for , where is the mean of the values of in the th segment.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: , , , , or .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: if , or then , for .
- (errno )
On entry, , is too large.
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: if or and has been supplied, then .
- Warns
- NagAlgorithmicWarning
- (errno )
To avoid overflow some truncation occurred when calculating the cost function, . All output is returned as normal.
- (errno )
To avoid overflow some truncation occurred when calculating the parameter estimates returned in . All output is returned as normal.
- 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_pelt
solveswhere is a penalty term used to control the number of change points. This minimization is performed using the PELT algorithm of Killick et al. (2012). The PELT algorithm is guaranteed to return the optimal solution to [equation] if there exists a constant such that
for all .
cp_pelt
supplies four families of cost function. Each cost function assumes that the series, , comes from some distribution, . The parameter space, is subdivided into containing those parameters allowed to differ in each segment and those parameters treated as constant across all segments. All four cost functions can then be described in terms of the likelihood function, and are given by:where is the maximum likelihood estimate of within the th segment. In all four cases setting satisfies equation [equation]. Four distributions are available: Normal, Gamma, Exponential and Poisson. Letting
the log-likelihoods and cost functions for the four distributions, and the available subdivisions of the parameter space are:
Normal distribution:
Mean changes:
Variance changes:
Both mean and variance change:
Gamma distribution:
Scale changes:
Exponential Distribution:
Mean changes:
Poisson distribution:
Mean changes:
when calculating for the Poisson distribution, the sum is calculated for rather than .
- References
Chen, J and Gupta, A K, 2010, Parametric Statistical Change Point Analysis With Applications to Genetics, Medicine and Finance (Second Edition), Birkhäuser
Killick, R, Fearnhead, P and Eckely, I A, 2012, Optimal detection of changepoints with a linear computational cost, Journal of the American Statistical Association (107:500), 1590–1598