Package: fABBA
fABBA is a fast and accurate symbolic representation method for temporal data.
It is based on a polygonal chain approximation of the time series followed by an aggregation of the polygonal pieces into groups.
The aggregation process is sped up by sorting the polygonal pieces and exploiting early termination conditions.
In contrast to the ABBA method [S. Elsworth and S. Güttel, Data Mining and Knowledge Discovery, 34:1175-1200, 2020], fABBA avoids repeated within-cluster-sum-of-squares computations which reduces its computational complexity significantly.
Furthermore, fABBA is fully tolerance-driven and does not require the number of time series symbols to be specified by the user.InstallfABBA has the following essential dependencies for its functionality:cythonnumpyscipyrequestsTo install the current release via PIP use:pipinstallfABBADownload this repository:gitclonehttps://github.com/nla-group/fABBA.gitExamplesCompress and reconstruct a time seriesThe following example approximately transforms a time series into a symbolic string representation (transform) and then converts the string back into a numerical format (inverse_transform). fABBA essentially requires two parameterstolandalpha. The tolerancetoldetermines how closely the polygonal chain approximation follows the original time series. The parameteralphacontrols how similar time series pieces need to be in order to be represented by the same symbol. A smallertolmeans that more polygonal pieces are used and the polygonal chain approximation is more accurate; but on the other hand, it will increase the length of the string representation. A smalleralphatypically results in a larger number of symbols.The choice of parameters depends on the application, but in practice, one often just wants the polygonal chain to mimic the key features in time series and not to approximate any noise. In this example the time series is a sine wave and the chosen parameters result in the symbolic representation#$!”!”!”!”!”!”!”%. Note how the periodicity in the time series is nicely reflected in repetitions in its string representation.importnumpyasnpimportmatplotlib.pyplotaspltfromfABBAimportfabba_modelts=[np.sin(0.05*i)foriinrange(1000)]# original time seriesfabba=fabba_model(tol=0.1,alpha=0.1,sorting='2-norm',scl=1,verbose=0)string=fabba.fit_transform(ts)# string representation of the time seriesprint(string)# prints BbAaAaAaAaAaAaAaCinverse_ts=fabba.inverse_transform(string,ts[0])# numerical time series reconstructionAdaptive polygonal chain approximationInstead of usingtransformwhich combines the polygonal chain approximation of the time series and the symbolic conversion into one, both steps of fABBA can be performed independently. Here’s how to obtain the compression pieces and reconstruct time series by inversely transforming the pieces:importnumpyasnpfromfABBAimportcompressfromfABBAimportinverse_compressts=[np.sin(0.05*i)foriinrange(1000)]pieces=compress(ts,tol=0.1)# pieces is a list of the polygonal chain piecesinverse_ts=inverse_compress(pieces,ts[0])# reconstruct polygonal chain from piecesSimilarly, the digitization can be implemented after compression step as belows:fromfABBAimportdigitizefromfABBAimportinverse_digitizestring,parameters=digitize(pieces,alpha=0.1,sorting='2-norm',scl=1)# compression of the polygonprint(''.join(string))# prints BbAaAaAaAaAaAaAaCinverse_pieces=inverse_digitize(string,parameters)inverse_ts=inverse_compress(inverse_pieces,ts[0])# numerical time series reconstructionAlternative ABBA approachWe also provide other clustering based ABBA methods, it is easy to use with the support of scikit-learn tools. The user guidance is as followsimportnumpyasnpfromsklearn.clusterimportKMeansfromfABBAimportABBAbasets=[np.sin(0.05*i)foriinrange(1000)]# original time series#  specifies 5 symbols using kmeans clusteringkmeans=KMeans(n_clusters=5,random_state=0,init='k-means++',verbose=0)abba=ABBAbase(tol=0.1,scl=1,clustering=kmeans)string=abba.fit_transform(ts)# string representation of the time seriesprint(string)# prints BbAaAaAaAaAaAaAaCinverse_ts=abba.inverse_transform(string)# reconstructionImage compressionThe following example shows how to apply fABBA to image data.importmatplotlib.pyplotaspltfromfABBA.load_datasetsimportload_imagesfromfABBAimportimage_compressfromfABBAimportimage_decompressfromfABBAimportfabba_modelfromcv2importresizeimg_samples=load_images()# load test imagesimg=resize(img_samples[0],(100,100))# select the first image for testfabba=fabba_model(tol=0.1,alpha=0.01,sorting='2-norm',scl=1,verbose=1)string=image_compress(fabba,img)# compress imageinverse_img=image_decompress(fabba,string)# decompress imageCitationIf you use fABBA in a scientific publication, we would appreciate your citing:@techreport{CG22a,title={An efficient aggregation method for the symbolic representation of temporal data},author={Chen, Xinye and G\"{u}ttel, Stefan},year={2022},number={arXiv:2201.05697},pages={23},institution={The University of Manchester},address={UK},type={arXiv EPrint},url={https://arxiv.org/abs/2201.05697}}