What is Dynamic Time Warping
In time series analysis, dynamic time warping (DTW) is an algorithm for measuring similarity between two temporal sequences, which may vary in speed. For instance, similarities in walking could be detected using DTW, even if one person was walking faster than the other, or if there were accelerations and decelerations during the course of an observation. DTW has been applied to temporal sequences of video, audio, and graphics data  indeed, any data that can be turned into a linear sequence can be analyzed with DTW. A wellknown application has been automatic speech recognition, to cope with different speaking speeds. Other applications include speaker recognition and online signature recognition. It can also be used in partial shape matching applications. Every index from the first sequence must be matched with one or more indices from the other sequence, and vice versa. The DTW is considered alignmentbased metrics that rely on a temporal alignment of the series in order to assess their similarity. The dynamic time warping usage is not limited to the temporal data, but it can be with any sequence of data, and matter of fact we can even ignore the timestamp index in the data set that we are warping since it won?t be needed in the calculation. In Euclidean based distance metric or similarity measure compares the pairs in a 11 fashion as we can see on the left picture, while the Dynamic Time Warping which is an example of alignmentbased metric it tries to scan the two time series for temporal matching so the matching procedure is not limited to the correspondent element only, and we will see this also can be an issue since the matching procedure can go more than desired. Note how DTW matches distinctive patterns of the time series, which is likely to result in a more sound similarity assessment than when using Euclidean distance that matches timestamps regardless of the feature values. It is also worth mentioning that the DTW can be applied to any sequence based.
Two simulation skeletons walking in different speed.
DTW will be used to study the similarity between the two movements
We can see in this animation that the algorithm tries to realign both time series or let?s say both sequences by minimizing the Euclidean distance between the two, we can also use any other distance measure other than the Euclidean to what serves our use case. The process of realigning these sequences is the core of the dynamic time warping algorithm.
The animation explains how the DTW tries to align two time series.
In addition to the details below, please also find a TAF23 video presentation on this topic by Atheer AlAttar from the Spotfire Data Science team, starting at 11mins 05secs into this video.
Algorithm Assumptions and Mathematical Representation
If we have two series A and B, then:

Referring to the mathematical model above:Dynamic Time Warping is invariant to time shifts, whatever their temporal span. In order to allow invariances to local deformations only, one can impose additional constraints on the set of admissible paths. In practice, global constraints on admissible DTW paths restrict the set of possible matches for each element in a time series, the matching width is called the warping window sometimes. As stated above, setting such constraints leads to restricting the shiftinvariance to local shifts only. Typically, DTW with a SakoeChiba band constraint of radius r is invariant to time shifts of magnitude up to r, but is no longer invariant to longer time shifts, and we can see here the time shift invariance is limited only in the window range, or the radius range only.
 Where X, X? are the time series
 𝜋 is the alignment path
 And the target function is to minimize the distance between X, X? pairs.
DTW temporal spans
Applications in Oil and Gas
Production Profile Similarity
An oilfield generally consists of hundreds of oil wells or more, which have been produced for several years or decades. If these oil wells are analyzed one by one, the workload will be tremendously huge. The dynamic time warping algorithm provides a method to quickly classify oil wells. Oil flow rates of oil wells are very different, but several representative curves can be abstracted as references. By matching actual well output curves with the references, the category of oil wells can be decided based on the similarity between actual output curves and reference type curves.
Automatic Depth Matching
From left to right: First the query, secondly the reference and thirdly the warping obtained with the first order Parametric Time Warping. Finally, the warping is obtained with the piecewise linear parametrization. In red the reference is plotted. In the top the total crosscorrelation between the curves is shown. Dynamic Time Warping can also be used to identify formation tops and depth match multi wells.
ROP Optimizing
Motivation
 Knowing the optimum ROP plays a vital role in the drilling process (cost saving, risk mitigation)
 We already have some completed wells to the one we are currently drilling
 These drilled wells are sources of information we can use to have an idea about the most optimum ROP
 The DTW helps us to answer the question of which well is the most similar to the one we are drilling
Process
The suggested logic is as follows: Select target well  nearby wells are highlighted automatically
 Align target and nearby wells by depth using DTW  on the feature level
 Identify the most similar well to target well, and deltas between at current and future depths
 Inputs: Location of nearby wells, well logs
 Outputs: Location of target and similar wells
 Prediction of time to reservoir (via RoP analysis)
Spotfire Implementation and Data Function
Implementing DTW using fastdtw package is straightforward, below is an example of a starter data function that can be used in Spotfire.def dtw_calc(s1, s2, distance = 'euclidean'): """ Calculates similarity using Dynamic Time Warping Input: s1 (real): A series represents sequential values. s2 (real): A series represents sequential values. distance (str): any distance metric other than the default. normalized (boolean): whether to normalize the resulting score. Returns: score (real): A scalar describes similarity score between the two provided series. associations (int): A dictionary that contains the associations between the pairs from the two series. log (str): a variable used to share error messages with the end user. """ from scipy.spatial.distance import euclidean import fastdtw # drop nan values s1.dropna(inplace=True) s2.dropna(inplace=True) # calculating the dtw distance, path = fastdtw.fastdtw (s1, s2) return distance, path
Recommended Comments
There are no comments to display.