Source code for naginterfaces.​library.​examples.​tsa.​cp_pelt_ex

#!/usr/bin/env python
"``naginterface.library.tsa.cp_pelt`` Python Example."

# NAG Copyright 2017-2019.

# pylint: disable=invalid-name

from naginterfaces.library import tsa

[docs]def main(): """ Example for :func:`naginterfaces.library.tsa.cp_pelt`. Change point detection, using the PELT algorithm. >>> main() naginterfaces.library.tsa.cp_pelt Python Example Results. Change point detection, using the PELT algorithm. -- Change Points -- --- Distribution --- Number Positions Parameters 1 12 0.34 1.00 2 32 2.57 1.00 3 49 1.45 1.00 4 52 -0.48 1.00 5 70 1.20 1.00 6 100 -0.23 1.00 """ print('naginterfaces.library.tsa.cp_pelt Python Example Results.') print('Change point detection, using the PELT algorithm.') # The change-point/distribution type: ctype = 1 # The time series: y = [ 0., 0.78, -0.02, 0.17, 0.04, -1.23, 0.24, 1.7, 0.77, 0.06, 0.67, 0.94, 1.99, 2.64, 2.26, 3.72, 3.14, 2.28, 3.78, 0.83, 2.8, 1.66, 1.93, 2.71, 2.97, 3.04, 2.29, 3.71, 1.69, 2.76, 1.96, 3.17, 1.04, 1.5, 1.12, 1.11, 1., 1.84, 1.78, 2.39, 1.85, 0.62, 2.16, 0.78, 1.7, 0.63, 1.79, 1.21, 2.2, -1.34, 0.04, -0.14, 2.78, 1.83, 0.98, 0.19, 0.57, -1.41, 2.05, 1.17, 0.44, 2.32, 0.67, 0.73, 1.17, -0.34, 2.95, 1.08, 2.16, 2.27, -0.14, -0.24, 0.27, 1.71, -0.04, -1.03, -0.12, -0.67, 1.15, -1.1, -1.37, 0.59, 0.44, 0.63, -0.06, -0.62, 0.39, -2.63, -1.63, -0.42, -0.73, 0.85, 0.26, 0.48, -0.26, -1.77, -1.53, -1.39, 1.68, 0.43, ] # The penalty term: beta = 4.5 # The fixed parameters: param = [1.] soln = tsa.cp_pelt( ctype, y, beta=beta, param=param, ) print(' -- Change Points -- --- Distribution ---') print(' Number Positions Parameters') for i in range(soln.ntau): print( ' {:d} {:6d} {:12.2f} {:12.2f}'.format( i+1, soln.tau[i], soln.sparam[0, i], soln.sparam[1, i] ) )
if __name__ == '__main__': import doctest import sys sys.exit( doctest.testmod( None, verbose=True, report=False, optionflags=doctest.REPORT_NDIFF, ).failed )