Clustering functional data using wavelets
Abstract
We present two methods for detecting patterns and clusters in high dimensional timedependent functional data. Our methods are based on waveletbased similarity measures, since wavelets are well suited for identifying highly discriminant local time and scale features. The multiresolution aspect of the wavelet transform provides a timescale decomposition of the signals allowing to visualize and to cluster the functional data into homogeneous groups. For each input function, through its empirical orthogonal wavelet transform the first method uses the distribution of energy across scales generate a handy number of features that can be sufficient to still make the signals well distinguishable. Our new similarity measure combined with an efficient feature selection technique in the wavelet domain is then used within more or less classical clustering algorithms to effectively differentiate among high dimensional populations. The second method uses dissimilarity measures between the whole timescale representations and are based on waveletcoherence tools. The clustering is then performed using a kcentroid algorithm starting from these dissimilarities. Practical performance of these methods that jointly designs both the feature selection in the wavelet domain and the classification distance is demonstrated through simulations as well as daily profiles of the French electricity power demand.
1 Introduction
In different fields of applications, explanatory variables are not standard multivariate observations, but are functions observed either discretely or continuously. Ramsay and Dalzell (1991) gave the name “functional data analysis” to the analysis of data of this kind. As evidenced in the work by Ramsay and Silverman (1997, 2002) (see also Ferraty and Vieu (2006)), a growing interest is notable in investigating the dependence relationships between complex functional data such as curves, spectra, time series or more generally signals. Functional data often arise from measurements on fine time grids, and if the sampling grid is sufficiently dense, the resulting data may be viewed as a sample of curves. These curves may vary in shape, both in amplitude and phase. Typical examples involving functional data can be found when studying the forecasting of electricity consumption, temporal gene expression analysis or ozone concentration in environmental studies to cite only a few.
Given a sample of curves, an important task is to search for homogeneous subgroups of curves using clustering and classification. Clustering is one of the most frequently used data mining techniques, which is an unsupervised learning process for partitioning a data set into subgroups so that the instances within a group are similar to each other and are very dissimilar to the instances of other groups. In a functional context clustering helps to identify representative curve patterns and individuals who are very likely involved in the same or similar processes. Recently, several functional clustering methods have been developed such as variants of the kmeans method (Tarpey and Kinateder (2003); Tarpey (2007); CuestaAlbertos and Fraiman (2007)) and clustering after transformation and smoothing (CATS) (Serban and Wasserman (2004)) to modelbased procedures, such as clustering sparsely sampled functional data (James and Sugar (2003)) or mixed effects modeling approach using Bsplines (Luan and Li (2003)) mostly concentrate on curves exhibiting a regular behavior.
Our interest in time series of curves is motivated by an application in forecasting a functional time series when the most recent curve is observed. This situation arises frequently when a seasonal univariate time series is sliced into consecutive segments, for example days, and treated as a time series of functions. The idea of forming a functional time series from a seasonal univariate time series has been introduced by Bosq (1991) . Suppose one observes a square integrable continuous time stochastic process over the interval , at a relatively high sampling frequency. The commonly used approach is to divide the interval into subintervals , with , and to consider the functionalvalued discrete time stochastic process , defined by
(1) 
The random functions thus obtained, while exhibiting a possibly nonstationary behavior within each subinterval, form a functional times series that is usually assumed to be stationary. Such a procedure allows to handle seasonal variation of size in a natural way. This setup has been used for prediction when ones consider a Hilbertvalued autoregressive process (see Bosq (1991); Besse and Cardot (1996); Pumo (1992); Antoniadis and Sapatinas (2003)) or for a more general continuoustime process (see Antoniadis et al. (2006)). However, as already noticed above, for many functional data the segmentation into subintervals of length may not suffice to make reasonable the stationary hypothesis of the resulting segments. For instance, in modeling the electrical power demand process the seasonal effect of temperature and the calendar configuration strongly affects the mean level and the shape of the daily load demand profile. Recognizing this, our aim is therefore to propose a clustering technique that clusters the functional times series into groups that may be considered as stationary so that in each group more or less standard functional prediction procedures can be applied. )
We will apply the methodology focusing on edf’s (Électricité de France
Although slicing an univariate time series produces functional data, we do not observe the whole segments but a sample of the values at some time points. One could then use a vector representation of each observation. For example Wang et al. (2008) proposed to measure the distance between observations through the high dimensional multivariate distribution of all sampled time points along each curve. This approach does not exploit the eventually potential information of interactions between points of a single curve. To avoid this, many authors have clustered the coefficients of a suitable basis representation of functions. Since the analyzed curves are infinitedimensional and temporalstructured, one projects each curve over an appropriate basis of the functional space to extract specific features form the data which are then used as inputs for clustering or classification. One may cite for example Abraham et al. (2003) where the authors proposed to cluster the spline coefficients of the curves using means, or James and Sugar (2003) that use a spline decomposition specially adapted for sparsely sample functional data. Nevertheless, attention must be paid to the chosen basis because this operation involves linear transformation of data that may not be invariant for the clustering technique (see Tarpey (2007)). Splines are often used to describe functions with a certain degree of regularity. However, we will be working with curves like in Figure 6 that may present quite irregular paths. We chose to work with wavelets because of their good approximations properties on sample paths that might be rather irregular.
Wavelets offer an excellent framework when data are not stationary. For example, in Gurley et al. (2003) the wavelet transform is used to develop the concept of waveletcoherence that describes the local correlation of the timescale representation of two functions. Grinsted et al. (2004) proved that this concept is convenient for clustering geophysical time series. Another example supporting such a fact is the work by Quiroga et al. which uses wavelets to detect and cluster spikes on neural activity. Motivated by this and the fact that the wavelet transform has the property of timefrequency localization of the time series, we propose hereafter a timeseries feature extraction algorithm using orthogonal wavelets for automatically choosing feature dimensionality for clustering. We also study some more complex alternatives using the waveletcoherence concept in sake of better exploiting the well localized information of the wavelet transform.
The rest of the paper is organized as follows. Section 2 is a reminder on multiresolution analysis and introduces the basis supporting our feature extraction algorithm by means of the energy operator. Following wavelet analysis we cluster the functional data using the extracted features in Section 3. Our first clustering algorithm uses means as unsupervised learning routine. We test the proposed method in Section 4 on simulated and real data. Section 5 presents a more sophisticated method for clustering functional data using a more specific dissimilarity measure. Finally, we conclude the paper by summarizing the main contributions and perspectives in Section 6.
2 Feature extraction with wavelets
In this section we first introduce some basic ideas of the wavelet analysis before introducing more specific material: the energy contributions of the scale levels of the wavelet transform which are the key tools for future clustering. More details about wavelets and wavelet transforms can be found for example in Mallat (1999).
We will consider a probability space where we define a functionvalued random variable , where is a (real) separable Hilbert space (e.g. the space of squaredintegrable functions on (finite energy signals) or the Sobolev space of smooth function on , with integer regularity index ) endowed with the Hilbert inner product and the Hilbert norm .
2.1 Wavelet transform
A wavelet transform (WT for short) is a domain transform technique for hierarchical decomposing finite energy signals. It allows a real valued function to be described in terms of an approximation of the original function, plus a set of details that range from coarse to fine. The property of wavelets is that the broad trend of the input function is captured in the approximation part, while the localized changes are kept in the detail components. For short, a wavelet is a smooth and quickly vanishing oscillating function with good localization properties in both frequency and time. This is suitable for approximating curves that contain localized structures. A compactly supported WT uses a orthonormal basis of waveforms derived from scaling (i.e. dilating or compressing) and translating a compactly supported scaling function and a compactly supported mother wavelet . We consider periodized wavelets in order to work over the interval , denoting by
the periodized scaling function and wavelet, that we dilate or stretch and translate
For any , the collection
is an orthonormal basis of . Thus, any function can then be decomposed in terms of this orthogonal basis as
(2) 
where and are called respectively the scale and the wavelet coefficients of at the position of the scale defined as
To efficiently calculate the WT, Mallat introduced the notion of mutiresolution analysis of (MRA) and designed a family of fast algorithms (see Mallat (1999)).
With MRA, the first term at the right hand side of (2) can be viewed as a smooth approximation of the function at a resolution level . The second term is the approximation error. It is composed by the aggregation of the details at scales . These two components, approximation and details, can be viewed as a low frequency (smooth) nonstationary part and a component that keeps the timelocalized details at higher scales. The distinction between the smooth part and the details is determined by the resolution , that is the scale below which the details of a signal cannot be distinguished. We will focus our attention on the finer details, i.e. on the information at the scales .
From a practical of view, each function is usually observed on a fine time sampling grid of size . In the sequel we will be interested in input signals of length for some integer . If is not a power of 2, one may interpolate data to the nearest with . In this context we use a highly efficient pyramidal algorithm (Mallat (1989)) to obtain the coefficients of the Discrete Wavelet Transform (dwt).
Denote by the finite dimensional sample of the function . For the particular level of granularity given by the size of the sampling grid, one rewrites (2) using the truncation imposed by the points and the coarser approximation level , as:
(3) 
Hence, for a chosen wavelet and coarse resolution , one may define the dwt operator:
with . Since the dwt operator is based on an orthonormal basis decomposition, Parseval’s theorem states that the energy of a square integrable signal is preserved under the orthogonal wavelet transform:
(4) 
Hence, the global energy of is broken down into a few energetic components. The way these energies are distributed and contribute to the global energy of a signal is the key fact that we are going to exploit to generate a handy number of features that are going to be used for clustering.
The image of the dwt operator applied on the column vector of dimension may be written in matrix form as:
where is a by square matrix defining the dwt and satisfying (see [25, chap. 4]), and is a column vector of length with
where denotes the transpose of . It is easy to see that if we consider a vector with , then the wavelet coefficients of the dwt of are obtained from those of the as:
(5) 
2.2 Absolute and relative contributions
We just have seen that dwt coefficients describe properties of functions both at various locations and at various time granularity. Each time granularity here refers to the level of detail that can be captured by dwt. This is therefore the reason of choosing the dwt as a representation scheme in our previous section to compare the shapes of curves for clustering. The energy of the time series via decomposition (4) is equal to the sum of the energy of its wavelet coefficients distributed across scales
(6) 
the approximation (denoted informally by ) holding because of the truncation at scale for the wavelet expansion of , discarding finer scales. If we consider as the difference between two sampled curves, (6) justifies using the energy decomposition of wavelet coefficients for computing squared Euclidean distances between two series. However, when interested to see how the energy of wavelet coefficients is distributed across scales, other distance functions on dwt decompositions may be more appropriate for measuring the similarity between two series.
In what follows, we define for the absolute and relative contributions of the scale to the global energy of the centered function
(7) 
We call the two different representations: the absolute contribution (AC) and the relative contribution (RC).
We will therefore characterize each time series by the vector of its energy contributions or its relative contributions in order to define an appropriate measure of similarity that is going to be used for clustering. Note that in both of these choices of representation we leave out the eventual mean level differences of the time series since we do not make any use of the approximation term in their definition. An important consequence of this fact is that any dissimilarity considered over the representations will be invariant under vertical shifts of the curves. Moreover, using RC implies fixing the energy of the curves to one. Hence no difference in amplitude can be detected.
3 A means like functional clustering procedure
We have presented a way to represent the infinitedimensional original objects in features that summarize the time evolution of the curves at different scales. We will now see how we use the information that we have coded to effectively cluster it.
We can sum up the strategy for clustering that we will use in the first part of the paper in the following steps:
 0. Data preprocessing.

Approximate sample paths of by the truncated wavelet series (see (3)) at the scale from sampled data .
 1. Feature extraction.

Compute either the energetic components using absolute contribution (AC) or relative contribution (RC). If using the latter, transform the obtained vector using the logit transformation.
 2. Feature selection.

Use a feature selection algorithm for screening irrelevant variables.
 3. Determine the number of clusters .
 4. Clustering.

Obtain by means algorithm the clusters using the selected features.
The preprocessing step is mandatory when working with functional data that is only observed on a finite grid. Step 1 extracts from infinite dimensional curves a set of finite dimensional features. This allows us to employ multidimensional data analysis techniques. For the AC we have a vector of positive components that sums up the global energy on the details . Meanwhile for the RC the vector, all its positive components sum up one, in other words we have a probability vector. This is a constraint if we want to use the means algorithm because nothing that warrants that the resulting clusters will be probability vectors. Therefore we transform the vector by using the well known logit transformation.
At this stage we can use the means algorithm. Before that, a feature selection step is performed. Feature extraction and features selection have really different aims. Whether the former creates some new information from existing objects, the latter only selects a subset of existing features. This selection reduces the computational time of the algorithm and helps to avoid an unsatisfactory and unstable clustering. Another important advantage of using a feature selection algorithm is that the reduced number of features helps to better understand the cluster output. In our case, the number of features depends on the number of sampling points of the acquired data. For points, the number of features is that can be large. Moreover, since we are interested in the energy decomposition across scales, potentially several scales will not be informative for the cluster structure. Besides this, the feature selection algorithm aims to reduce (or eliminate) the presence of nonsignificant variables and a possible redundant information that could hide the cluster structure.
To decide which scales we retain with we use a variable selection algorithm for nonsupervised learning proposed and tested in Steinley and Brusco (2008). This algorithm combines a variable transformation with a variable selection technique. The transformed variables are used to construct an index of clusterability that serves to screen the variables that do not reveal information about the cluster structure. Then, for the remaining variables an evaluation of the feasible subsets of variables is done obtaining the best set of variables (minimum sumofsquareerrors (SSE)) for each subset size. The selected subset of variables is obtained by penalizing the SSE of each subset by its size.
One of the most difficult task in clustering is the determination of the number of clusters . Even if some statistical support can be given to achieve this task, usually the knowledge on the particular application helps on the choice. In the classical case, i.e. not the functional one, a lot of datadriven strategies can be defined. The first one by inspecting basically the withincluster dissimilarity as a function of . Many heuristics have been proposed trying to find a “kink” in the corresponding plot.
A more formal argument has been proposed by Tibshirani et al. (2001) by comparing, using the gap statistic, the logarithm of the empirical withincluster dissimilarity and the corresponding one for uniformly distributed data. Slight modifications have been proposed to the original argument, see for instance Ye (2007).
Another point of view useful to determine the number of clusters comes from modelbased clustering. The idea is to fit a Gaussian mixture model to data and identify clusters as mixture components. The number of clusters is usually obtained using the wellknown BIC criterion. All the above mentioned strategies seem to perform well when data do come from a mixture model but can perform poorly when the situation is more confused and fuzzy.
For determining the number of clusters James and Sugar (2003) proposed an information theoretic approach. They consider the transformed distortion curve , a kind of average Mahalanobis distance between data and the set of cluster centers as a function of . Jumps in the associated plot allow to select sensible values for while the largest one can be the best choice for a mixture of dimensional distributions with common covariance. An asymptotic analysis (as goes to infinity) states that, when the number of clusters used is smaller than the correct number (when any), then the transformed distortion remains close to zero, before jumping suddenly and increasing linearly. Then, detecting a jump in the transformed distortion curve is equivalent to detecting the number of clusters .
One last element to help on the determination of the number of clusters is the validation tools. Once a clustering has been achieved one can use diagnostic tools in order to asses the quality of the clustering. Usually, clustering analysis is not a linear procedure. The practitioner must try several solutions so it will iterate between steps three and four. The final quality of a clustering output will be assessed by means of diagnostic displays that will be presented later.
4 Numerical illustration
We study the empirical performance of our clustering strategy on two functional data sets. The first one has been simulated using functionalvalued processes and the second one is issued from the electricity power demand in France.
4.1 Simulated example
We simulated a functional data set structured in three () clusters. Each cluster is generated by a different functional model. An element of the first cluster is a simple superposition of two sinus and a white noise: . For the second and third clusters, we use two functional autoregressive (FAR) processes (see Bosq (2000)) defined by
Here for each a functional valued random value is observed, is a linear bounded operator and is a functional valued strong white noise. The first FAR has a diagonal covariance structure, and the second a full covariance matrix. The result is 25 segments of time series of length composing each cluster.
On the right of Figure 1 we plot one trajectory for each cluster. Note that the first model, dominated by a low frequency trend, is clearly distinguished from the two others whose differences are more intricate.
We apply to the sampled curves the DWT using a Symmlet 6 wavelet (see Nason (2008)) and we extract the absolute contribution (AC) of energy for each detail level . We calculate the mean AC by cluster. The results are plotted on the left of Figure 1. Note how for a wide range of levels (from 1 to 6) there is no clear separation between cluster of the mean values of the AC. However, for the highest levels the extracted features show a better discrimination.
To effectively detect which are the informative scales we use the Steinley and Brusco’s algorithm for variable selection for unsupervised learning. It needs as input the number of clusters so we perform the feature selection sequentially over a likely number of clusters ranging from two to twenty. We retain scales 8 to 10 which are associated with the lowest frequencies. We use the means algorithm (that we initialize many times, retaining the minimum within cluster distance solution) where the input data are the selected features and the number of clusters is the true one. We obtain so the predicted membership of each instance that we compare with the true ones. We repeat the process of generation of the three clusters, feature extraction, feature selection and clustering 100 times to eliminate the effect of the data generation.
We then compare our clustering strategy with the one consisting in clustering the raw curves directly (i.e. clustering the observations as if they were vectors of dimension 1024). We will abbreviate RC the clustering that uses as extracted features the relative contributions of the energy and RAW the direct clustering of the curves. Table 1 contains two quality indicators of the clustering while Figure 2 presents the boxplots of the quality indicators across replications.
Clustering  Feature Extraction  Raw curves 

Abbreviation  RC  RAW 
Mean Global error  21.05 (4.125)  25.32 (4.834) 
Mean Rand Index  0.414 (0.092)  0.335 (0.109) 
We measure the global quality of the clustering by counting the number of observation misclassified and the Rand Index. This index measures the agreement between two clustering partitions: we will compare the clustering output and the real classes that we simulate for this example. The index is computed a ratio between the number of agreements between the partitions and the total number of agreements and disagreements. When corrected it takes values between 1 and 1. Values close to 0 show partitions that are not correlated, while if it is close to 1 in absolute value the partitions are highly correlated. The mean difference of the global error between RC and RAW clustering is significantly less than zero (value: ). In the same way, we obtain a significant greater value of the Rand Index for RC clustering (value: ).
Even with a lower global rate error, one may be interested in the quality of each cluster. We will help us by using the shadow plot (Leisch (2010)) to examine the intraclass quality. The shadow of an observation measures it distance to its centroid and to the second nearest centroid. If the observation is close to its centroid the shadow value is near 0, while if it is at the same distance between the first and second nearest centroids it gives values near to one. The shadow plot is a graphical representation of all shadow values arranged by cluster and sorted in decreasing order within the cluster. We represent the shadow plots of the resulting clustering of a randomly selected replicate in Figure 3. The unequal width of each box is due to the different number of observations in each cluster. We see that globally the shadow values of the RC clustering (on the left) are lower than those of the RAW clustering (on the left) which shows that the former clustering provides more compact clusters than the latter one. Remark how the first cluster (the one that coincides with the sinus model) reveal a very compact cluster for the RC clustering. If the first cluster has such a good separation, most of the misclassification error must be made confusing clusters 2 and 3.
Another useful diagnostic tool to assess the clustering quality of some high dimensional data is the neighborhood graph (Leisch (2006)). The main idea is to obtain some representation of the relative position of the clusters in some low dimensional space. As the projection to a plane may yield to a misinformation of how well two clusters are separated, the author proposes to combine it with a graph that reveals this information on the thickness of its edges. By this way, one constructs a graph where the nodes are the centroids and the thickness of the edges is proportional to the shadow mean value of the points belonging to the respective clusters of the relied centroids. To help the interpretation, one last element is added to the graphics: two convex hulls per cluster that will play an analogous role of the box plot for unidimensional data. The hulls formed by the thick lines correspond to the “inner 50%”. For each cluster , consider the distances from the centroid to each point of the cluster. Let be be the median distance of the cluster . The “inner 50%” of the cluster is defined as all the points with distance from the centroid is less or equal . The second hull, the dashed one, contains all the points which distance from the centroid is less or equal .
The neighborhood graph of the RC and RAW clustering are shown on the left and right hand side respectively of Figure 4. For each clustering, the points are projected over the plane spanned by the two first principal directions of their respective spaces. The topology of both clusters is very different. While all the three convex hulls of the clusters on the RAW clustering overlaps in the principal plane, the separation of the clusters on the RC clustering is quite good. Thanks to the feature extraction, the cluster 1 (formed almost only by the sinus model observations) is completely separated from the rest of the observations on the principal plane. As we could anticipate in the shadow plots the separation of clusters two and three is less obvious.
4.2 Electricity power demand data
Our aim here is to discover clusters of daily load curves for a whole year. Before we start let us state some well known facts for edf’s experts from this data set. We will help us by using Figure 5 where a sample of one week per season is presented. One important issue is the highly dependence on the meteorological conditions that is translated by a seasonal cycle. Also social and economic phenomenons (like holidays or the dichotomy between workingdays and weekends) are present in the power demand. The structure of the weeks forms a weekly cycle where the profiles vary not only in mean level but also in the shape. It is also usual to found intraweekly differences, usually on the days next to weekends.
The centered profiles highlight the variation in shape mainly due to calendar structure (or to some special events like a few days when some industries are encouraged to reduce their demand). But the variability in the curves is not only reduced to first and second order moments. The standardized version of daily profiles shows that higher order moments contribute also to the variability in the dynamic of the curves (see Figure 6). The objective of this empirical evaluation is to discover groups that reflects this heterogeneity to better understand the underlying structure.
Data preprocessing. From the practical point of view we count have a discrete equidistant grid of 17520 () time points of an underlying continuous process. After splitting the process as in (1) with day, the corresponding discrete versions of are 48length vectors . We use spline interpolation over each function in order to obtain points () to be able to use Mallat’s pyramidal algorithm for the DWT.
Feature extraction and feature selection
We proceed as before: for each we compute the wavelet coefficients via the dwt. Then we calculate both the absolute and relative energy contributions of the scales to the global energy (as in as in (7)). We will called them AC and RC respectively. For the RC we compute the logit transformations. We arrange the coefficients in two matrices of 365 rows and six columns.
For each data matrix the SteinleyBrusco’s feature selection algorithm is used. As it needs as input the number of clusters we test it for a wide range of possibles number of clusters for some large positive . For our application we used ).
The algorithms returns which variables are significant for each . The results of the algorithm show that

The significant scales for revealing the cluster structure are independent of the number of clusters used on the feature selection algorithm.

As we could attend the significant scales are those associated with the midfrequencies. In one hand, too large scales represents slow varying frequencies that are associated with the common daynight structure inherent to every day. In the other, too small scales captures very high frequency activity usually noise and thus no structure should be found neither.

Finally, the scales that are significant may parametrize the cycle they represent. For the AC the scales that have been retained represent the cycles of 1.5, 3 and 6 hours. For the RC the scales retained are those associated to the cycles of 30 minutes, 1.5 and 3 hours.
Clustering results
The next step is to determine the number of clusters in data for both representations. We use the SugarJames’ own implementation of their algorithm to detect a jump in the transformed distortion curve. These curves are presented in Figure 7.
For the AC and RC the number of detected clusters is 8 and 5 respectively. The difference in the number of clusters is explained by the fact that while AC is vertical shift and scale invariant, the RC is only invariant by vertical shifts. Hence it founds less of variability in curves.
Then, we perform the detection of groups using means algorithm. The input are the selected variables and the number of clusters detected by a significant jump in the distortion curve.
AC  RC  AC  RC  

Summer workdays  1, 5, 7  1, 5  Saturday  3, 8  2 
Cold weekdays  2, 4, 6  4  Sundays and bank holiday  3, 8  3 
Let us sketch some interesting facts of the clustering results obtained from these both variants. First of all, we found for any of them what is well known in the electrical power demand environment: two well defined periods covering the summer and winter seasons. The clusterings also found the dichotomy of working days and weekends. The clusters that correspond to these two season structure if resumed in Table 2. Figure 8 shows the clustering result founded using ACR. The figure is composed by two groups of 8 graphics (one for each cluster). The group on the left hand size shows the curves that were assigned to each cluster, while the one on the right hand size gives information about the position on the year of the instances of each cluster. The curves graphics (left hand side) have a gray shade formed by all the (standardized) daily curves is drawn on the background in order to help the visual comparison. In the calendar graphics (right hand side), each day in the year is represented by the mean average load in GW/h arranged chronologically. Again a gray shade is represents the set of all the days and only those corresponding to each cluster are highlighted. Finally, Figure 9 presents the neighborhood graphs of the resulting outputs.
A second issue is the difference between the AC and RC. Basically when passing from AC to RC one eliminates some of the heterogeneity in clusters. See for example how the three different clusters for cold workdays 6, 2 and 4 of AC (corresponding to early, medium and late winter respectively) collapsed into one only cluster for the RC. This heterogeneity is consistent with the existence of two transition periods corresponding to the months of OctoberNovember and AprilMay. These transition days are no longer different from the winter workdays as soon as we do not authorize changes in scale (as mentioned before, RC is equivalent to standardized curves). So we can conclude that the transition days are different to the winter workdays on amplitude variation.
It is also interesting to see how the cluster are positioned in the space. The neighborhood graphs on the principal plane shows the summer clusters 1, 5 and 7 (corresponding to middle of the workdays, Fridays and summer break days and Mondays respectively) quite close between them, the winter clusters 2, 4 and 6 also closer between them, and Saturdays and Sundays clusters (3 and 8) slightly farther. There are also interesting links between the early winter cluster 6 and the late summer cluster 7 witnessed by an important edge that links them.
Results are quite satisfactory but at this step one could ask itself whether the feature extraction suffices to well cluster a set of curves. Moreover, time aggregation on the computation of the energy contribution deletes all time location information. We will try in the next section to develop some dissimilarity measure that better exploit the power of the wavelet transform.
5 Using the wavelet spectrums
The success of any clustering algorithm depends on the adopted dissimilarity measure. Direct similarity measures such as norms match two functional objects in their original representations without explicit feature extraction. When , this reduces to commonly used Euclidean distance. norms are straightforward and easy to compute. However, in many cases such as in shifting and scaling, the distance of two sequences cannot reflect the desired (dis)similarity between them. Furthermore, distance has meaning only in the relative sense when used to measure (dis)similarity.
In the previous section we have proposed instead the usage of the discrete wavelet transform of two curves of equal length to define a weighted normalized Euclidean like distance between them as a measure of their similarity. Indeed this was supported by the fact that the similarity of curves should be based on certain characteristics of the data rather than on the raw data itself by concentrating most of the energy in a small region of the scalefrequency domain. However the feature extraction procedure that we have used lost the location information. This is due to the aggregation on the time domain.
We may ask ourselves whether this loss is meaningful. To answer this question we present in this section two another direct and intuitive similarity measures that can be used for matching sequential patterns.
The adopted similarity measures are based on the wavelet coherence between two time series (here considered as curves) and in a principal components analysis of the common covariance structure measured in terms of the cross wavelet transform. These concepts provide a way of analyzing local correlation or covariance of time series both in the time domain and in the frequency domain. In this, it fundamentally differs from Fourier coherence that relies upon the correlation of the two series in the frequency domain only. In addition to locality, the continuous wavelet transform on which the wavelet coherence is based, possesses the very desirable ability of filtering the polynomial behavior to some predefined degree and therefore is invariant to vertical or scale shifts. Therefore, correct characterization of time series is possible, in particular in the presence of nonstationarities like global or local trends or biases.
In what follows, we first recall some facts on the continuous wavelet transform and the concept of wavelet coherence between two time series. After that, we will use the maximum covariance analysis (MCA) for measuring the common timefrequency patterns and deduct a similarity measure between them.
5.1 Continuous WT
Although Fourier analysis is well suited to quantifying constant periodic components in a timeseries, it is not able to characterize signals whose frequency content changes with time. On the other hand, a Fourier decomposition may determine all the spectral components embedded in a signal and does not provide any information about when they are present. To overcome this problem, the wavelet transform decomposes a signal using functions (wavelets) that narrow when highfrequency features are present and widen on lowfrequency structures (Daubechies (1992)). This decomposition yields a good localization in both time and frequency and is well suited for investigating the temporal evolution of aperiodic and transient signals. Indeed, wavelet analysis is the timefrequency decomposition with the optimal tradeoff between time and frequency resolution (Mallat (1999)).
Starting with a mother wavelet , we consider the analyzing functions generated by simply scaling by and translating it by
(8) 
The parameter is a scaling or dilation factor that controls the length of the wavelet (the factor being introduced to guarantee preservation of the unit energy, ) and is a location parameter that indicates where the wavelet is centered. Scaling a wavelet simply means stretching it (if ), or compressing it (if ). Note that the choice of the wavelet function is not arbitrary. This function verifies also the moment condition .
Given a function , its continuous wavelet transform (CWT), with respect to the wavelet , is a function defined as
(9) 
where ’’ denotes the complex conjugate. The wavelet decomposition is a linear representation of the signal where the variance is preserved (Daubechies (1992)). Briefly, the continuous wavelet transform yields a redundant decomposition (the information extracted from a given scale slightly overlaps that extracted from neighbor scales) but it is generally more robust to noise as compared with other decomposition schemes (Poularikas (2009)).
In some sense, the wavelet transform can be regarded as a generalization of the Fourier transform and by analogy with spectral approaches, one can compute the local wavelet energy spectrum of defined by where denotes the modulus.
It is often desirable to quantify statistical relationships between two nonstationary signals. In Fourier analysis, the coherency is used to determine the association between two squareintegrable signals and . The coherence function is a direct measure of the correlation between the spectra of two timeseries (Chatfield (1989)). To quantify the relationships between two nonstationary signals, the following quantities can be computed: the wavelet crossspectrum and the wavelet coherence.
The crosswavelet transform is given by . As in the Fourier spectral approaches, the cross wavelet coherence can be defined as ratio of the crosswavelet spectrum to the product of the spectrum of each series, and can be thought of as the local correlation between two CWTs. Here, again, we follow Grinsted et al. (2004) and define the wavelet coherence between two time series and as follows:
(10) 
where denotes a smoothing operator in both time and scale (smoothing is necessary since without that step, coherence is identically equal to 1). In Fourier analysis we overcome this problem by smoothing the crossspectrum before normalization. For wavelet analysis and in particular with the Morlet wavelet, one can follow Torrence and Compo (1998), where the smoothing is achieved by a convolution in time and scale. The time convolution is done with a Gaussian window and the scale convolution is performed by a rectangular window (see Grinsted et al. (2004) for details).
We will now explain our choice of wavelet coherence based distances motivated by the coefficient of determination from the linear regression framework.
5.2 Extended coefficient of determination
Consider a single linear regression between a response variable and its regressor . Given a set of sample data of length , the model can be estimated in the least squares sense and a fitted line can be obtained. To measure how well does the adjusted regression line fits the data one should recall the definition of the coefficient of determination :
where indicates the average of . Some simple calculations show that the coefficient of determination in simple linear regression is the square of Pearson’s coefficient of linear correlation between and . Therefore the coefficient measures the goodness of fit between the observed and the fitted values since it appears as the cosine of the angle of the vectors et . It takes its values between 0 and 1 where the closer the value is to 1, the better the regression line fits the data points.
The coefficient of determination has some desirable properties as reflexivity () or symmetry (). Thanks to these properties, appears to be a good similarity measure. Moreover has an intrinsic relation with the normalized Euclidean distance by meandeviation. Indeed if denotes the centered and standardized vector and if denotes the Euclidean distance between these two transformed vectors than it is easy to show that
(11) 
Unfortunately, is applicable only to 1dimensional sequences, but in our application, the sequences we will consider will be multidimensional (indexed by the scales in the wavelet coherence vector). To match a pair of dimensional sequences and , we will therefore use the extended coefficient of determination defined as:
where and are the th scale portions of and . It is easy to see that has properties similar to .
5.3 Scalespecific
Direct assessment of relationships between time series at specific scales has remained a challenging problem. Using the concept of wavelet coherence, we now show that traditional statistical measures, such as the extended multiple coefficient of determination analyzed in the previous subsection, can be adapted to address scalespecific questions in non stationary time series data. Scalespecific global relationships between two time series and can be quantified by computing first an averaged over time squared coherence
(12) 
By definition (10) the values of are bounded by exactly as it holds for the coefficient of determination . Moreover, the wavelet integrated over time squared coherency is equal to 1 when there is a strong linear association at a particular scale between the two signals, and equal to 0 if and are non correlated. We may therefore use this integrated squared wavelet coherence to define a scalespecific similarity measure that looks like the familiar extended based distance, say:
(13) 
Expression (13) must be approximated in practice because we do not observe the continuous sample paths . Instead, we have the samples and for . Hence, we must approximate the integral operation by summations over the time points. So in practice the CWT is computed only for and for an arbitrary set of scale values . The smallest scale and the greatest scale are usually chosen as a power of two depending on the minimum detail resolution and the length of the time grid respectively. The rest of the values corresponds to a linear interpolation on a logarithmic scale with base 2.
These considerations yield in a matrix whose th element is
The derived similarity measure, mimicking (11) over the scales is then given by
(14) 
where is the analogous to (13) calculated over a discrete grid where we have replaced integrals by summations over the scale set and the timepoints set.
5.4 MCA over the wavelet covariance
We will explore a more sophisticated alternative to measure non linear relationship between two non stationary time series. This approach uses a Maximum Covariance Analysis (MCA) over a localized covariance matrix based on the CWT. This way we can obtain timefrequency patterns that explains the principal covariation of the time series. We will introduce a way of quantifying the similarity of these patterns. Using MCA on the wavelet power spectrum of two series was originally proposed by Rouyer et al. (2008). .
As before, consider two time series and and their CWT and computed from the sampled sample path and . We first define the timefrequency local covariance matrix by
where is the conjugate transpose and is a symmetric matrix with possibly complex values. Performing a SVD of gives the following decomposition
where the columns of and are the orthonormal singular vectors of and respectively, and is a diagonal matrix with the positive real numbers that we arrange in decreasing order. These numbers, known as the singular values of the decomposition give important information about . For example the zeronorm gives the rank of the matrix. We have also that using the Frobenius norm so the total inertia of the covariance matrix is decomposed into the sum of squared singular values. By this way, the quantity can be seen as the portion of explained covariance associated to the direction of the pair of the th singular vectors of and that we write and respectively.
We define also the th leading pattern as the projections of the CWT of and over their respective th singular vectors
The leading patterns show how the wavelet scales evolve on time for the time series and in the orthogonal directions that maximize their common covariance. We can then decompose the CWT of and in terms of the singular vectors and the leading patterns obtaining
where and are matrices that have the leading patterns of and respectively in their rows. As in PCA we chose the first directions for the smallest such that
where is a prefixed threshold. Thus, we obtain approximations of the CWT for both and using
where the informal notation is due to the truncation at the first direction for the expansions. This approximation guarantees a portion of the inertia of the covariance matrix .
To compare the evolution on time of each pair of leading patterns we measure how dissimilar is their shape. For the th pair of leading pattern, take the first derivative of the difference between them. The energy in this quantity is bigger if two leading patters presents very different evolutions. We finally measure this energy by taking the modulus
Finally, we aggregate all the significant directions using a weighted combinations with weights given by the explained square covariances
In the literature more complicated proposals for measuring parallelism between curves in similar contexts have been proposed. For example Keogh and Pazzani (1998) proposed as parallelism index to measure the angles between the segments formed by each pair of consecutive points. Royuer et al. (2008) use this index in the context of a MCA analysis on the wavelet power spectrum of two series. Aguiar and Soares (2009) use the MCA on a local covariation matrix based on the CWT with a complex wavelet. The parallelism index between the resulting complex valued leading patterns is measure as a complex angle of consecutive segments. Our proposal aims to measure the parallelism between complex valued vector avoiding to pass through the notion of complex angle.
5.5 Clustering electricity power data through the wavelet spectrum.
We test the proposed dissimilarities to cluster functional data on the the electricity power data. These dissimilarities impose a new challenge for the clustering algorithm: it is not clear why when using a distance other than the euclidean we should still calculate the centroids of the clusters by the average mean. We could for example argue that, as a consequence of the linearity of the WT the mean of elements is the mean element of a group. Otherwise, some deepnessbased notion can be used to find some medianlike element (e.g. see Cuevas et al. (2006); Febrero et al.(2008)). We will instead use the cluster R package to perform a partitioning around medoids (PAM). This technique admits a general dissimilarity matrix as input and is known to be more robust than means. The representative element of a group (medoid) is the element of the cluster that minimizes the dissimilarity to all the points of the cluster.
Each one of the daily segments is transformed by means of the cwt using the Morlet complex wavelet (see Mallat (1999)). We use the discrete scales set and 8 octaves between dyadic scales. The choice of this scales is made to filter the highest scales (above 12 hours) in order to eliminate the common low frequency pattern. The result is a complex matrix for each segment.
Then, a dissimilarity matrix is computed for the wavelet based extended dissimilarity (WER) and another for the one based on the maximum covariance analysis over the wavelet transform (MCA). We use the PAM clustering to obtain clusters with each dissimilarity matrix. The number of clusters is chosen in order to be able to compare the clustering results with the AC clustering.
A.  Warming transition workdays  E.  Special days I 
B.  Summer workdays  F.  Hot Saturdays 
C.  Early winter workdays  G.  Special days II 
D.  Sundays  H.  Late winter and cooling 
transition workdays 
With the same display used for Figure 8, Figures 10 and 11 show the clustering results founded using WER and MCA respectively. We compute the adjusted Rand index between the resulting partitions. While we obtain an Index of 0.26 and 0.32 between the AC clustering and WER and MCA respectively, the rand Index between WER and MCA is 0.57. This show that the resulting outputs of WER and MCA are quite different from that obtained with AC, and more consistent between them. This is why we can use the same labels for the resulting clusters on both WER and MCA. Helping us with the calendar information we labeled the clusters as shown in Table 3. We leave two clusters with a generic names (special days I and II) to make a deeper analysis.
When we watch one year of daily curves, there is a large proportion of days where the dynamic of the demand is well known. This is the case of the clusters A, B, C, D, F and H where it is quite easy to find why they are together. Actually the graphics of the curves show that they are quite homogeneous groups with maybe some exceptions. However, important enhancement on the modeling on very few special tricky days can be made by founding this tricky days.
We focus our attention on the groups named “Special days” I and II (labels E and G respectively). These groups are not founded when using simpler clustering alternatives based on feature extraction. They are formed by only a few observations and they are not the same between the WER and MCA.
WER’s cluster E only has two bank holiday (Christmas and New Year days) while for MCA clustering the cluster is formed by the eves of Christmas and New Year days and the New Year day as well as other three other cold weekend days. Cluster G has more elements (19 for both dissimilarities). For the WER dissimilarity it mainly formed by winter’s Saturdays (16 out of 19). While for MCA the proportion of Saturdays is largely smaller (7 out 19) other winter tricky days are founded: the days of the one hour clock’s shift due to the daylight saving time or the whole week between Christmas and New Year’s day.
6 Concluding remarks
The initial interest on clustering nonstationary functional time series was guided by the need for determining big structures of behavior of the daily power demand curves. The alternative would be to work directly over the vectors that constrains the sampled daily records using the metric. However, this turn out to be useless results in terms of clustering because one obtains groups that differ mainly in mean level and no information on the shape of the curves is recovered.
Our proposals for clustering functional data can be arranged into two types. While the first one is based on a waveletbased feature extraction in order to use classical multidimensional clustering tools, the second way is to cluster using a dissimilarity measure between curves. Both approaches are based on the wavelet transform. Our choice is guided by the interesting theoretical properties of wavelets. They are particularly fruitful in describing functional objects with localized structures.
The feature extracted clustering is extremely fast thanks to the fast implementation of the DWT and the means algorithm. We believe that the feature selection step is particularly useful. On one hand, it eliminates non informative features that could induce an unsatisfactory clustering. On the other hand, it gives some adaptability to the technique with respect to the particular application and also gives interpretation ability to the clustering technique.
In spite of the fact that the results of the first clustering strategy are useful in practice, more refined ones can be obtained using the dissimilarity based clustering proposals. On the daily load curves application we shown that very particular shapes of days can be founded with an extra computational burden. If for the WER dissimilarity this computational cost remains considerably low, the extra computational burden of the singular value decomposition for the MCA dissimilarity and the lack of meaningful different results from the WER dissimilarity drive us to think that it would not be useful in practice.
Footnotes
 http://www.edf.com
References
 C. Abraham, P.A. Cornillon, E. MatznerLøber, and N. Molinari. Unsupervised curve clustering using Bsplines. Scandinavian Journal of Statistics, 30(3):581–595, 2003.
 L.F. Aguiar and M.J. Soares. Business Cycle Synchronization Across the EuroArea: a Wavelet Analysis. NIPE Working Papers 8/2009, NIPE  Universidade do Minho, 2009.
 A. Antoniadis, E. Paparoditis, and T. Sapatinas. A functional waveletkernel approach for time series prediction. Journal Royal Statisticial Society Series B Statistical Methodology, 68(5):837, 2006.
 A. Antoniadis and T. Sapatinas. Wavelet methods for continuoustime prediction using Hilbertvalued autoregressive processes. Journal of Multivariate Analysis, 87(1):133–158, 2003.
 P.C. Besse and H. Cardot. Approximation spline de la prévision d’un processus fonctionnel autorégressif d’ordre 1. Canadian Journal of Statistics, 24(4):467–487, 1996.
 D. Bosq. Modelization, nonparametric estimation and prediction for continuous time processes. In George Roussas, editor, Nonparametric functional estimation and related topics, pages 509–529. NATO ASI Series, 1991.
 D. Bosq. Linear processes in function spaces: Theory and applications. SpringerVerlag, New York, 2000.
 C. Chatfield. The Analysis of Time Series. Ed. Chapman and Hall, 1989.
 J.A. CuestaAlbertos and R. Fraiman. Impartial trimmed kmeans for functional data. Computational Statistics & Data Analysis, 51(10):4864–4877, 2007.
 A. Cuevas, M. Febrero, and R. Fraiman. On the use of the bootstrap for estimating functions with functional data. Computational statistics & data analysis, 51(2):1063–1074, 2006.
 I. Daubechies. Ten lectures on wavelets. Society of Industrial Mathematics, 1992.
 M. Febrero, P. Galeano, and W. GonzálezManteiga. Outlier detection in functional data by depth measures, with application to identify abnormal NOx levels. Environmetrics, 19(4):331–345, 2008.
 F. Ferraty and P. Vieu. Nonparametric functional data analysis: theory and practice. SpringerVerlag, New York, 2006.
 A. Grinsted, J.C. Moore, and S. Jevrejeva. Application of the cross wavelet transform and wavelet coherence to geophysical time series. Nonlinear Processes in Geophysics, 11(5/6):561–566, 2004.
 K. Gurley, T. Kijewski, and A. Kareem. Firstand higherorder correlation detection using wavelet transforms. Journal of engineering mechanics, 129(2):188, 2003.
 G.M. James and C.A. Sugar. Clustering for Sparsely Sampled Functional Data. Journal of the American Statistical Association, 98(462):397–409, 2003.
 G.M. James and C.A. Sugar. Finding the Number of Clusters in a Dataset: An InformationTheoretic Approach. Journal of the American Statistical Association, 98(463):750–764, 2003.
 A. Keogh and M. Pazzani. An enhanced representation of time series which allows fast and accurate classification, clustering and relevance feedback. In Proceedings of the 4th International Conference of Knowledge Discovery and Data Mining. AAAI Press, 1998.
 F. Leisch. A toolbox for kcentroids cluster analysis. Computational Statistics and Data Analysis, 51(2):526–544, 2006.
 F. Leisch. Neighborhood graphs, stripes and shadow plots for cluster visualization. Statistics and Computing, 20(4):457–469, 2010.
 Y. Luan and H. Li. Clustering of timecourse gene expression data using a mixedeffects model with bsplines. Bioinformatics, (19):474—482, 2003.
 S.G. Mallat. A theory for multiresolution signal decomposition: The wavelet representation. IEEE transaction on pattern analysis and machine intelligence, 11(7):674–693, 1989.
 S.G. Mallat. A wavelet tour of signal processing. Academic Press, 1999.
 G. Nason. Wavelet methods in statistics with R. Springer, 2008.
 D.B. Percival and A.T. Walden. Wavelet methods for time series analysis. Cambridge Univ Press, 2006.
 A.D. Poularikas. Transforms and Applications Hanbook. CRC Press, 2009.
 B. Pumo. Estimation et prévision de processus autorégressifs fonctionnels. PhD thesis, University of Paris 6, 1992.
 R.Q. Quiroga, Z. Nadasdy, and Y. BenShaul. Unsupervised spike detection and sorting with wavelets and superparamagnetic clustering. Neural computation, 16(8):1661–1687, 2004.
 J.O. Ramsay and C.J. Dalzell. Some tools for functional data analysis (with discussion). Journal of the Royal Statistical Society. Series B, 53(3):539–572, 1991.
 J.O. Ramsay and B.W. Silverman. Functional data analysis. SpringerVerlag, New Yok, 1997.
 J.O. Ramsay and B.W. Silverman. Applied functional data analysis. SpringerVerlag, New York, 2002.
 T. Rouyer, J.M. Fromentin, N.C. Stenseth, and B. Cazelles. Analysing multiple time series and extending significance testing in wavelet analysis. Marine Ecology Progress Series, 359:11–23, 2008.
 N. Serban and L. Wasserman. CATS: clustering after transformation and smoothing. Journal of the American Statistical Association, 100:990–999, 2004.
 D. Steinley and M.J. Brusco. A new variable weighting and selection procedure for kmeans cluster analysis. Multivariate Behavioral Research, 43(1):32, 2008.
 D. Steinley and M.J. Brusco. Selection of variables in cluster analysis: An empirical comparison of eight procedures. Psychometrika, 73(1):125–144, 2008.
 T. Tarpey. Linear transformations and the kmeans clustering algorithm: Applications to clustering curves. The American Statistician, 61(1):34, 2007.
 T. Tarpey and K.K.J. Kinateder. Clustering functional data. Journal of Classification, 20(1):93–114, 2003.
 R. Tibshirani, G. Walther, and T. Hastie. Estimating the number of clusters in a data set via the gap statistic. Journal of the Royal Statistical Society. Series B (Statistical Methodology), 63(2):411–423, 2001.
 C. Torrence and G.P. Compo. A practical guide to wavelet analysis. Bulletin of the American Meteorological Society, 79(1):61–78, 1998.
 H. Wang, J. Neill, and F. Miller. Nonparametric clustering of functional data. Statistics and its interface, 1:47–62, 2008.
 M. Yan and K. Ye. Determining the number of clusters using the weighted gap statistic. Biometrics, 63(4):1031–1037, 2007.