A Unifying Framework for Analysis of Spatial-Temporal Event Sequence Similarity and Its Applications

: Measures of similarity or differences between data objects are applied frequently in geography, biology, computer science, linguistics, logic, business analytics, and statistics, among other ﬁelds. This work focuses on event sequence similarity among event sequences extracted from time series observed at spatially deployed monitoring locations with the aim of enhancing the understanding of process similarity over time and geospatial locations. We present a framework for a novel matrix-based spatiotemporal event sequence representation that uniﬁes punctual and interval-based representation of events. This uniﬁed representation of spatiotemporal event sequences (STES) supports different event data types and provides support for data mining and sequence classiﬁcation and clustering. The similarity measure is based on the Jaccard index with temporal order constraints and accommodates different event data types. The approach is demonstrated through simulated data examples and the performance of the similarity measures is evaluated with a k-nearest neighbor algorithm (k-NN) classiﬁcation test on synthetic datasets. As a case study, we demonstrate the use of these similarity measures in a spatiotemporal analysis of event sequences extracted from space time series of a water quality monitoring system.


Introduction
Wireless sensor networks (WSN) or other monitoring systems, deployed regularly or irregularly in geographic space, have become commonly used for environmental data collection and monitoring. Each monitoring station or node can have one or more sensors producing time series on variables of interest for monitoring. Within this setting, we may be interested in the similarity among the time series observed across a set of monitoring stations. For example, we might want to ask, how similar are water quality monitoring variables within an estuary or across different estuaries? Several prior studies have researched time series similarity measures but time series can contain substantial data redundancy making similarity computations inefficient and expensive [1,2]. Converting time series to event sequences can reduce the data volume while retaining key information [3][4][5]. In this paper we report on development of an approach for measuring the similarity among event sequences associated with monitoring stations distributed within some geographic space. We refer to these as spatiotemporal event sequences (STES) because of the pertinence of their distribution in space. The approach aims to address two basic questions. Firstly, how similar are event sequences within a defined geospatial region? Secondly, within the region, do event sequences that are closer in space tend to be more similar? Answers to these questions can contribute to insights on patterns in spatial processes that can be helpful for environmental monitoring. Figure 1A illustrates an instance of an STES as a set of temporally ordered events observed at a fixed location in space. An STES differs from other types of event sequences such as genomic sequences [6], industrial process monitoring sequences [7], patient symptom sequences [8], political event sequences [9], or consumer purchasing sequences [10] in each monitoring station as illustrated in Figure 1B. An individual STES conceptually represents a realization of a process at the location and the set of STES deployed in a region conceptually forms a field of event sequences representing an evolving underlying process [11]. As an example, a precipitation event sequence observed at station S1 ( Figure  1A) represents a local realization of a meteorological process. Through similarity measures among event sequences in geographic space we can extend Tobler's First Law of Geography, which states that "everything is related to everything else, but near things are more related than distant things", to an assessment of process similarity in space. Related work on a number of similarity measures can be found for event sequences, but not directly STES as we define them. Edit distance is a measure of similarity first developed for comparing strings (a type of sequence). It refers to the total number of editing operations needed to transform one string into another string. The lower the number, the more similar the strings. Some examples of edit distance include Hamming distance [12], Levenshtein distance [13], Jaro-Winkler distance [14], and Longest Common Subsequence (LCSS) distance [15]. The edit distance measure was first extended to measure event sequence similarity using the lowest cost of three types of editing operations: insert, delete and move [16,17]. The move operation was included to incorporate the occurrence time of the events. As noted by Wongsuphasawat et al. [18] this approach allows only monotonic mapping, which means that the matched events in the target and candidate sequences must be in similar order. The Jaccard similarity coefficient is a classic measure of similarity between two sets that continues to be applied in several application domains, for example in comparing biological sequence data [19,20] and in web usage mining [21]. More recent event sequence similarity measures have been proposed to take into consideration temporal order and temporal duration in addition to assessing event type similarity [22]. While most similarity metrics treat events as points in time, Kotsifakos et al. (2013) and Mirbagheri and Hamilton (2020) propose approaches for interval based event sequence similarity [23,24]. Their event representation includes an event label and start and end time, and the event sequence is a list of these arranged in ascending order. Their concept of similarity between two event sequences includes the presence of event intervals with the same labels, the order of occurrences of the event Converting time series to event sequences leads to on-going production of STES at each monitoring station as illustrated in Figure 1B. An individual STES conceptually represents a realization of a process at the location and the set of STES deployed in a region conceptually forms a field of event sequences representing an evolving underlying process [11]. As an example, a precipitation event sequence observed at station S1 ( Figure 1A) represents a local realization of a meteorological process. Through similarity measures among event sequences in geographic space we can extend Tobler's First Law of Geography, which states that "everything is related to everything else, but near things are more related than distant things", to an assessment of process similarity in space.
Related work on a number of similarity measures can be found for event sequences, but not directly STES as we define them. Edit distance is a measure of similarity first developed for comparing strings (a type of sequence). It refers to the total number of editing operations needed to transform one string into another string. The lower the number, the more similar the strings. Some examples of edit distance include Hamming distance [12], Levenshtein distance [13], Jaro-Winkler distance [14], and Longest Common Subsequence (LCSS) distance [15]. The edit distance measure was first extended to measure event sequence similarity using the lowest cost of three types of editing operations: insert, delete and move [16,17]. The move operation was included to incorporate the occurrence time of the events. As noted by Wongsuphasawat et al. [18] this approach allows only monotonic mapping, which means that the matched events in the target and candidate sequences must be in similar order. The Jaccard similarity coefficient is a classic measure of similarity between two sets that continues to be applied in several application domains, for example in comparing biological sequence data [19,20] and in web usage mining [21]. More recent event sequence similarity measures have been proposed to take into consideration temporal order and temporal duration in addition to assessing event type similarity [22]. While most similarity metrics treat events as points in time, Kotsifakos et al. (2013) and Mirbagheri and Hamilton (2020) propose approaches for interval based event sequence similarity [23,24]. Their event representation includes an event label and start and end time, and the event sequence is a list of these arranged in ascending order. Their concept of similarity between two event sequences includes the presence of event intervals with the same labels, the order of occurrences of the event intervals, the duration of the event intervals, and the temporal relations among the event intervals. To our knowledge, none of the currently available similarity measures for event sequences address both time stamped and interval based events and consider the spatial dimension. Our event sequence similarity approach builds on the Jaccard index and integrates interval and time stamped events.
The paper is organized as follows. Section 2, Materials and Methods, describes the process of eventization and generation of STES, the proposed methods for transforming STES to matrices based on various measurement characteristics, and the development of similarity measures for different levels of event representation (qualitative vs. quantitative), as applied to entire sequences or user defined moving windows. Section 3, Results and Discussion, demonstrates construction of STES similarity matrices and implementation of the similarity measures on synthetic mini datasets, further evaluates the performance of the similarity measures on execution speed and classification accuracy and provides a real world application on classification of the Maine coastal regions based on cluster analysis of precipitation event sequences. Finally, Section 4 concludes this study, considering the remaining issues and future work.

Eventization and Spatiotemporal Event Sequences (STES)
Jassby and Powel (1990) describe an event as a short-term, yet substantial, discontinuity in the underlying behavior of a time series [25]. Eventization is the process of event identification from observations or measured raw data according to user definitions applied in a specific domain. In this paper it refers to the process of event identification from space-time series and formation of timestamped, ordered event sequences. Briefly, primitive or simple event extraction [26] or detection can be grouped into three categories: (1) threshold-based approaches [27] in which an event is regarded to occur when observations exceed some predefined thresholds, (2) pattern-based approaches [28] in which an event is represented as a spatiotemporal pattern and event detection is performed using pattern matching techniques; and (3) learning-based approaches [29] in which selected modeling methods are used to model spatiotemporal dependencies of sensor data and make probabilistic inference about events.
In environmental applications, we are interested in the spatiotemporal context of the sequences. The expressions of space and time components capture different granularities. Temporal entities have two types of time expression, timestamps and time intervals [30]. Timestamps can express different granularities as in what time, what date, what day of the  week, what week, and what year, etc. Time intervals can also be of different granularities, such as seconds, minutes, hours, days, months, seasons, and years. Given these two temporal concepts, we identify two general types of STES: timestamped and interval events as illustrated in Figure 2.
For eventization, we need to consider the level of measurement of an observed time series variable. A real valued level of measurement may for example be retained in an event representation (as illustrated in Figure 3A). Alternatively, an observed real value at a time stamp may be transformed to an ordinal or binary value (as illustrated in Figure 3D). Interval events can be divided into as many timestamps as determined by an event definition and user defined granularity, within which the full range of observed values satisfying the event definition may be retained (see Figure 3B,C). Alternatively, all observed values within an interval that satisfy an event definition may be transformed to ordinal or binary values (as illustrated in Figure 3E,F). also be of different granularities, such as seconds, minutes, hours, days, months, seasons, and years. Given these two temporal concepts, we identify two general types of STES: timestamped and interval events as illustrated in Figure 2.  For eventization, we need to consider the level of measurement of an observed time series variable. A real valued level of measurement may for example be retained in an event representation (as illustrated in Figure 3A). Alternatively, an observed real value at a time stamp may be transformed to an ordinal or binary value (as illustrated in Figure  3D). Interval events can be divided into as many timestamps as determined by an event definition and user defined granularity, within which the full range of observed values satisfying the event definition may be retained (see Figure 3B,C). Alternatively, all observed values within an interval that satisfy an event definition may be transformed to ordinal or binary values (as illustrated in Figure 3E,F).

Matrix Representation of STES
For a regularly sampled time series, the set of timestamps T forms a discrete set, with observations spaced at uniform time intervals. Given s locations and t timestamps, a space-time series dataset can be represented with a s × t matrix where locations correspond to rows and timestamps to columns and ν represents an observed variable.
G 0 -Timestamps represent the finest temporal granularity as described by Shahar [30], here corresponding to the time series sampling rate. Each value potentially corresponds to a status change, which could define a timestamped event or the start or end of an interval event. As noted above, events are identified based on different user defined functions such as threshold based, pattern-based, or learning based [31]. For simplicity, in the following definitions, we assume use of a threshold, but the approach is generalizable to other event detection approaches [32]. A temporal granularity in integer unit G i scaled from G 0 (e.g., hour to day, day to week) is specified by a user based on application domain considerations. At each observation location s, an event sequence is formed at the Gi scale after eventization. The event sequences for all locations form an initial STES matrix. In the eventization process, the dimension can be further reduced through removing rows and columns without events in locations across all G i -timestamps or G i -timestamps across all locations. Following this data reduction, we may have n locations and G i granularity of m timestamps, in which the STES are represented as n × m matrix (n ≤ s and m ≤ t).
We identify four different cases corresponding to timestamped versus interval events and qualitative versus quantitative. For the case of nominal values, appearance of a user specified nominal category or label at a timestamp indicates the occurrence of an event. For this case the event value is defined as follows: where all timestamped observations (v ij ) are ordinal, interval or ratio values, the corresponding event value e ij may retain the original observation value or be subjected to some data transformation such as logarithm, percentage or normalization. Given a threshold for defining an event instance, sequences in this case can be represented as follows: An interval event occurs when the defining event conditions persist for more than one G 1 timestamp. As long as we determine the smallest temporal granularity in a specific study or system, we can represent an interval event sequence through the same timestamped event matrix as described above. The case for interval events with categorical values can be defined according to Equation (5): The case for interval events with ordinal or interval/ratio values can be defined according to Equation (6): . . , v ij+∆t ∆t ≥ 1 0 otherwise i = 1, 2, 3, . . . , n; j = 1, 2, 3, . . . , m For all interval events with no internal variation within the interval, i.e., with a constant event class level, the defined interval events are as described in Equation (6):

Development of Similarity Measures for Spatiotemporal Event Sequences
The matrix framework presented above provides a flexible method to investigate sequence similarity over space for the same time windows. In this context, we consider the event sequence similarity as the level of co-occurring timestamped events for a certain time period for two or more locations. We can vary the selection of a time window based on the sampling frequency of the observation data and a target event granularity (e.g., drought events which may be defined as over 10 days of no rain need a larger time window relative to heavy precipitation events). We present similarity measures for five situations: (a) binary timestamped events (no consideration of variable class levels or magnitude), (b) timestamped events with variable class levels or magnitude, (c) interval events considering time overlaps only, (d) interval events with constant nominal or ordinal labels and time overlaps, and (e) interval events with a range of real values and time overlaps.
We follow the concept of Jaccard similarity [33] but consider the order of individual event elements within each event sequence. The intersection between two sets of spatiotemporal event sequences means the common events must "co-occur" in both sequences, and the union refers to all events in either sequence. The measure of co-occurrence is demonstrated by the following example: ISPRS Int. J. Geo-Inf. 2021, 10, x FOR PEER REVIEW 7 spatiotemporal event sequences means the common events must "co-occur" in b sequences, and the union refers to all events in either sequence. The measure of occurrence is demonstrated by the following example: Given the two spatiotemporal timestamped event sequences with 10 timestamps compute the similarity between the two spatiotemporal event sequences as: where, , are two spatiotemporal event sequences from two locations S1, S2; t …, t10 are 10 timestamps. The intersection between two event sequences is the numbe co-occurring events between them. We discuss this similarity measure in more detail five different situations in the following sections.

Similarity Measures between Event Sequences without Considering Event Magnitude
First, we compute the level of pairwise co-occurrence between two event sequen and , _ ( , ), by simply counting the number of punctual events w the same occurrence time appearing in both and . So, the global (long durat similarity between event sequences can be calculated as below: -global similarity between event sequences and meaning overall similarity between two event sequences over a long user speci duration, _ ( , ) -co-occurring number of events betw sequences and , | ∪ | -cardinality of the union of two event sequen . In contrast to global similarity, we introduce a user defined local compari temporal window (ctw) (equivalent to a moving window), for which local (short durat similarity is calculated as: where, = 1, 2, 3, … , ; = , the number of time wind chunks in an event sequence; | _ ∪ _ | , cardinality of the union of corresponding subsequences of two event sequences in the same . For each pai spatiotemporal event sequences, we have local similarities in an ordered represented as , , , … , .

Similarity Measures between Event Sequences Considering Event Magnitude
We first find all co-occurrence time points between two event sequences , and then we calculate the similarity between two individual events at the occurrence timestamp based on their level of measurement. We have two simila calculation situations. First, if event values are interval or ratio level, the global simila can be calculated as below: Given the two spatiotemporal timestamped event sequences with 10 timestamps, we compute the similarity between the two spatiotemporal event sequences as: where, es 1 , es 2 are two spatiotemporal event sequences from two locations S1, S2; t1, t2, . . . , t10 are 10 timestamps. The intersection between two event sequences is the number of co-occurring events between them. We discuss this similarity measure in more detail for five different situations in the following sections.

Similarity Measures between Event Sequences without Considering Event Magnitude
First, we compute the level of pairwise co-occurrence between two event sequences es 1 and es 2 , co_occur(es 1 , es 2 ), by simply counting the number of punctual events with the same occurrence time appearing in both es 1 and es 2 . So, the global (long duration) similarity between event sequences can be calculated as below: where sim globlal (es 1 , es 2 )-global similarity between event sequences es 1 and es 2 , meaning overall similarity between two event sequences over a long user specified duration, co_occur(es 1 , es 2 )-co-occurring number of events between sequences es 1 and es 2 , |es 1 ∪ es 2 |-cardinality of the union of two event sequences es 1 and es 2 .
In contrast to global similarity, we introduce a user defined local comparison temporal window (ctw) (equivalent to a moving window), for which local (short duration) similarity is calculated as: where, i = 1, 2, 3, . . . , k; k = Temporal Length o f Event Sequence ctw , the number of time window chunks in an event sequence; |es 1 _ctw i ∪ es 2 _ctw i |, cardinality of the union of two corresponding subsequences of two event sequences in the same ctw. For each pair of spatiotemporal event sequences, we have k local similarities in an ordered list, represented as sim 1 local , sim 2 local , sim 3 local , . . . , sim k local big).

Similarity Measures between Event Sequences Considering Event Magnitude
We first find all co-occurrence time points between two event sequences es 1 and es 2 , and then we calculate the similarity between two individual events at the co-occurrence timestamp based on their level of measurement. We have two similarity calculation situations. First, if event values are interval or ratio level, the global similarity can be calculated as below: Second, if event levels are ordinal attribute based, the formula becomes: where, sim globlal (es 1 , es 2 )-global similarity between event sequences es 1 and es 2 , es 1j , es 2j -the event levels of two corresponding co-occurring events in es 1 and es 2 at timestamp j, inherited from original measurements, lev es 1j , lev es 2j -the relative event levels of two corresponding co-occurring events in es 1 and es 2 at timestamp j, respectively: lev es 1j = es 1j es 1j + es 2j and lev es 2j = es 2j es 1j + es 2j where, C-the total number of co-occurring timestamps, Abs lev es 1j − lev es 2j -absolute value of difference between relative event levels of two corresponding co-occurring events in es 1 and es 2 at time stamp j, |es 1 ∪ es 2 |-cardinality of the union of two event sequences es 1 and es 2 , n-the number of ordinal attribute-based event levels.
Similarly, we can characterize the local similarity between event sequences by the following Equation (11) for interval/ratio attribute-based events and (12) for ordinal attribute-based events: and where, i = 1, 2, 3, . . . , k; k = Temporal Length o f Event Sequence ctw , c is the number of co-occurring time points in ctw, es 1ctw ij ∪ es 2ctw ij , cardinality of the union of two corresponding subsequences of two event sequences in the same ctw. As before for each pair of spatiotemporal event sequences, we have k local similarities in an ordered list, represented as . . , sim k local . We note that the approaches for measuring sequence similarity as described above apply also to interval event sequences. We simply transform interval event sequences to punctual event vectors to form a matrix.

Implementation Examples
In this section we use simulated precipitation and temperature datasets to demonstrate the transformation of raw space-time series observations to event sequence matrices based on the event definitions described in the previous section. We calculate global and local pairwise event sequence similarities according to the steps described above. The transformation to STES matrices and the similarity measure calculations have been developed as R functions (see the link for software availability). The first two experiments cover timestamped events based on simulated precipitation measurements for 5 locations and 20 timestamps as shown in Table 1. We note that these timestamps could apply to different temporal granularities, but some minimum granularity is considered a punctual timestamp. Situation 1. We define precipitation ≥ 1 inch as events from the dataset in Table 1 and based on Equation (3) 1 1 1 1 0 0 1 0 1 0 1 0  0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1  0 1 0 1 1 1 0 0 0 0 1 0 1 0 1 1  0 1 0 1 0 0 0 1 0 0 0 1 0 1 0 1  0 1 0 1 0 0 1 1 0 0 0 1 0 1 0 1 In an alternate view of this matrix seen in Figure 4. we show temporal windows based on 4 timestamps, i.e., = 4: The pairwise global similarity and local similarity between eve calculated based on Equations (7) and (8). Here, = 4 , so we subsequences for each original event sequence. The pairwise similarity event sequences of 5 locations is shown in Figure 5. The pairwise global similarity and local similarity between event sequences were calculated based on Equations (7) and (8). Here, ctw = 4, so we have 5 chunks of subsequences for each original event sequence. The pairwise similarity measures between event sequences of 5 locations is shown in Figure 5.
By intuition, the event sequences in locations s2 and s3 are more similar than other pairs with only one mismatch, which is reflected in the global similarity matrix with the highest score of 0.91. The lowest similarity score is between s1 and s4 event sequences with only two co-occurring events. The rest of the similarity scores for other pairwise comparisons reflect their closeness in terms of co-occurrences. By intuition, the event sequences in locations s2 and s3 are more similar tha pairs with only one mismatch, which is reflected in the global similarity matrix w highest score of 0.91. The lowest similarity score is between s1 and s4 event seq with only two co-occurring events. The rest of the similarity scores for other p comparisons reflect their closeness in terms of co-occurrences. Table 1 consider the magnitude of the precipitation ≥ 1 inch by retaining the original observation Based on the transformation rules described in Equation (4)  The alternate view of this event matrix is shown in Figure 6. Where Equations (11) are used to calculate the global and local similarity respectively: Figure 6. A schematic view of the punctual event matrix of Situation 2 while considering event levels with 5 temporal comparison windows. Blocking 2 columns in yellow is for bett separation of 5 local windows.

Situation 2.
We again extract precipitation ≥ 1 inch-events from the dataset in Table 1 but now consider the magnitude of the precipitation ≥ 1 inch by retaining the original observation values. Based on the transformation rules described in Equation (4)  The alternate view of this event matrix is shown in Figure 6. Where Equations (9) and (11) are used to calculate the global and local similarity respectively: Figure 5. Output matrix of local similarity with five temporal windows and global similarity between five spatiotemporal event sequences from Situation 1.
By intuition, the event sequences in locations s2 and s3 are more similar than other pairs with only one mismatch, which is reflected in the global similarity matrix with the highest score of 0.91. The lowest similarity score is between s1 and s4 event sequences with only two co-occurring events. The rest of the similarity scores for other pairwise comparisons reflect their closeness in terms of co-occurrences.

Situation 2.
We again extract precipitation ≥ 1 inch-events from the dataset in Table 1  The alternate view of this event matrix is shown in Figure 6. Where Equations (9) and (11) are used to calculate the global and local similarity respectively: From the similarity matrix in Figure 7 we can see the change of similarity scores from the results shown in Figure 5 that do not take event magnitude into consideration. While all scores in Figure 7 decrease compared to Figure 5, the overall rankings of these scores are the same. This indicates that refinement of event levels and additional attributes of From the similarity matrix in Figure 7 we can see the change of similarity scores from the results shown in Figure 5 that do not take event magnitude into consideration. While all scores in Figure 7 decrease compared to Figure 5, the overall rankings of these scores are the same. This indicates that refinement of event levels and additional attributes of events incorporated into the similarity measure can affect the similarity values but rankings between event sequences remain stable. events incorporated into the similarity measure can affect the similarity values but rankings between event sequences remain stable.

Figure 7.
Output matrix including local similarity with five temporal windows and global similarity with consideration of events with variable class levels between five spatiotemporal event sequences from Situation 2.
The following examples for interval events are based on the temperature graph for five locations shown in Figure 8.

Situation 3.
Here we identify interval events ≥ 10 ℃ from high frequency temperature measurements at 5 locations. Assume that a minimum temporal granularity is specified (e.g., day, hour) such that we can obtain the measurements at all time points (t1, t2, …, t20) as in the dataset shown in Table 2. Using Equation (5), we obtain interval events as a sequence of contiguous 1s in a binary event matrix.  The following examples for interval events are based on the temperature graph for five locations shown in Figure 8. The following examples for interval events are based on the temperature graph for five locations shown in Figure 8.

Situation 3.
Here we identify interval events ≥ 10 ℃ from high frequency temperature measurements at 5 locations. Assume that a minimum temporal granularity is specified (e.g., day, hour) such that we can obtain the measurements at all time points (t1, t2, …, t20) as in the dataset shown in Table 2. Using Equation (5), we obtain interval events as a sequence of contiguous 1s in a binary event matrix.

Situation 3.
Here we identify interval events ≥ 10 • C from high frequency temperature measurements at 5 locations. Assume that a minimum temporal granularity is specified (e.g., day, hour) such that we can obtain the measurements at all time points (t1, t2, . . . , t20) as in the dataset shown in Table 2. Using Equation (5), we obtain interval events as a sequence of contiguous 1s in a binary event matrix. The sequence of contiguous 1's represents interval events, but these are processed as punctual events in the event sequence matrix: The alternative view of the interval event matrix in the example of Situation 3 can be seen in Figure 9. In this figure, we also assume that the comparative temporal window has 10 timestamps, i.e., ctw = 10 such that we have only 2 subsequences. The alternative view of the interval event matrix in the ex seen in Figure 9. In this figure, we also assume that the com has 10 timestamps, i.e., ctw = 10 such that we have only 2 subs The pairwise global similarity and local similarity be calculated with the Formulas (7) and (8). Here, = 10 subsequences for each original event sequence. The pairwise event sequences for the 5 locations is shown in Figure 10. The pairwise global similarity and local similarity between event sequences is calculated with the Formulas (7) and (8). Here, ctw = 10, so we have 2 chunks of subsequences for each original event sequence. The pairwise similarity matrices between event sequences for the 5 locations is shown in Figure 10.
The event sequences for locations s2 and s3 in Figure 10 are more similar than other pairs with only one mismatch at one timepoint, which is reflected in the global similarity matrix with the highest score of 0.88. The lowest similarity is between s1 and s4 event sequences with only four co-occurring timepoints and a relatively long union of events. The rest of the similarity scores reasonably reflect their actual closeness. ISPRS Int. J. Geo-Inf. 2021, 10, x FOR PEER REVIEW 13 of 23 Figure 10. Output matrix of local similarity with two temporal windows and global similarity between five spatiotemporal event sequences from Situation 3.
The event sequences for locations s2 and s3 in Figure 10 are more similar than other pairs with only one mismatch at one timepoint, which is reflected in the global similarity matrix with the highest score of 0.88. The lowest similarity is between s1 and s4 event sequences with only four co-occurring timepoints and a relatively long union of events. The rest of the similarity scores reasonably reflect their actual closeness.

Situation 4. For the interval events of Situation 3 with the consideration of event level, i.e., the variation of event values within the interval, we obtain a matrix of interval events based on Equation (7) as below:
The sequence of contiguous values represents interval events, but these are processed as punctual events in the event sequence matrix: The alternative view of the interval event matrix in the example of Situation 4 is represented in Figure 11. In this figure, we assume that the comparative temporal window has 10 timestamps, i.e., ctw = 10.  The sequence of contiguous values represents interval events, but these are processed as punctual events in the event sequence matrix: The alternative view of the interval event matrix in the example of Situation 4 is represented in Figure 11. In this figure, we assume that the comparative temporal window has 10 timestamps, i.e., ctw = 10. The pairwise global similarity and local similarity between event sequences is calculated with Equations (9) and (11) for this situation. Here, = 10, so we have 2 chunks of subsequences for each original event sequence. The pairwise similarity matrices between event sequences of 5 locations is shown in Figure 12. The pairwise global similarity and local similarity between event sequences is calculated with Equations (9) and (11) for this situation. Here, ctw = 10, so we have 2 chunks of subsequences for each original event sequence. The pairwise similarity matrices between event sequences of 5 locations is shown in Figure 12. Figure 11. A schematic view of the interval event matrix of Situation 4 with consideration of event level and variation between starting and ending time points with 2 temporal comparison windows. Notice that the chunks blocked with colors in the horizontal orientation represent interval events.
The pairwise global similarity and local similarity between event sequences is calculated with Equations (9) and (11) for this situation. Here, = 10, so we have 2 chunks of subsequences for each original event sequence. The pairwise similarity matrices between event sequences of 5 locations is shown in Figure 12. This situation considers the internal variation within an interval event along with cooccurrences. We can compare the similarity scores in Figure 12 with those in Figure 10. Like Situation 2, the overall similarity values decrease compared to the situations without considering event magnitude. We can see here the event sequences at locations s2 and s3 in Figure 12 are still more similar than other pairs with slight variations of event values between co-occurring timepoints, which can be reflected in the global similarity matrix with the highest score of 0.81. The lowest similarity (0.29) remains between s1 and s4 as in Situation 3. The rest of the similarity scores for other pairwise comparisons also reasonably reflect an intuitive sequence closeness. Table 3. This situation considers the internal variation within an interval event along with co-occurrences. We can compare the similarity scores in Figure 12 with those in Figure 10. Like Situation 2, the overall similarity values decrease compared to the situations without considering event magnitude. We can see here the event sequences at locations s2 and s3 in Figure 12 are still more similar than other pairs with slight variations of event values between co-occurring timepoints, which can be reflected in the global similarity matrix with the highest score of 0.81. The lowest similarity (0.29) remains between s1 and s4 as in Situation 3. The rest of the similarity scores for other pairwise comparisons also reasonably reflect an intuitive sequence closeness.

A Special Case in Situation 4. If the temperature measurements are recorded as an average value for every four days as shown in
A Special Case in Situation 4. If the temperature measurements are recorded as an average value for every four days as shown in Table 3. We can transform this dataset to a matrix of interval events with event levels based on Equation The alternative view of the interval event matrix for this example of average temperature can be seen in Figure 13. In this figure, we also assume that the comparative temporal window has 10 timestamps, i.e., ctw = 10.
on Equation (6) as shown in the matrix below: Temporal points (1, 2, 3, …, 20) Spatial locations (1, 2, 3, 4 The alternative view of the interval event matrix for this example of average temperature can be seen in Figure 13. In this figure, we also assume that the comparative temporal window has 10 timestamps, i.e., ctw = 10. Figure 13. A schematic view of the interval event matrix of Situation 4 with consideration of event level and no variation between starting and ending time points with 2 temporal comparison windows. Notice that the chunks blocked with colors in the horizontal orientation represent interval events. The pairwise global similarity and local similarity between event sequences can be calculated with Equations (9) and (11). Here, ctw = 10, so we have 2 chunks of subsequences for each original event sequence. The pairwise similarity matrices between event sequences of 5 locations is shown in Figure 14. The pairwise global similarity and local similarity between event sequences can be calculated with Equations (9) and (11). Here, ctw = 10, so we have 2 chunks of subsequences for each original event sequence. The pairwise similarity matrices between event sequences of 5 locations is shown in Figure 14.
We can transform this dataset to a matrix of interval events with event levels based on Equation (6)  The alternative view of the interval event matrix for this example of average temperature can be seen in Figure 13. In this figure, we also assume that the comparative temporal window has 10 timestamps, i.e., ctw = 10. Figure 13. A schematic view of the interval event matrix of Situation 4 with consideration of event level and no variation between starting and ending time points with 2 temporal comparison windows. Notice that the chunks blocked with colors in the horizontal orientation represent interval events.
The pairwise global similarity and local similarity between event sequences can be calculated with Equations (9) and (11). Here, ctw = 10, so we have 2 chunks of subsequences for each original event sequence. The pairwise similarity matrices between event sequences of 5 locations is shown in Figure 14. Intuitively we can see the event sequences between locations s1 and s2, and between locations s3 and s4 in Figure 14 are more similar than other pairs with all co-occurring events of similar value at most timepoints, which can be reflected in the global similarity matrix with the highest score of 0.91 and 0.90. The lowest similarity is 0.51 between s4 and s5 event sequences with three co-occurring events of different significance and two mismatched events.

Performance Evaluation
In this section we present our experimental evaluation of the accuracy and speed of different similarity measures with some synthetic datasets. In the first experiment, we compared the speed for computing similarity matrices using the small dataset used in this section. For the second, we used K-nearest neighbor (k-NN) classification with different similarity measures for comparing classification accuracy and efficiency.

Execution Speed for a Binary Event Matrix
The purpose of this experiment is to assess processing times for the timestamp locked Jaccard based similarity described in this paper (STES.sim1, see the software availability link). We compared STES.sim1 with generic edit distance in R (EditD Dynamic), and two functions of Edit Distance and original Jaccard similarity from the R package Rstringdist. The dataset contains 20 timestamps and 5 locations so we can generate a 5 × 5 similarity matrix. Microbenchmarks [34] in R was used to record the time elapsed for each similarity algorithm in the same similarity matrix generation function in R. The result indicated that STES.sim1 outperformed edit distance by a factor of 10 (Table 4).

Accuracy Evaluation with Synthetic Datasets Using 1-NN Classifier
K-NN is a conventional non-parametric classifier, used widely as the baseline classifier for solving many classification problems [35,36]. It is based on measuring the distances or similarities between a test data set and each of the training data to decide the final classification output. When proposing a new distance or similarity measure, 1-NN accuracy was strongly recommended for testing [37]. Note that this does not exclude the additional other trainings and tests with different K values. Here, however, the 1-NN test has the advantage of having no parameters and allowing comparisons between similarity measures.
Synthetic dataset 1: This dataset contains 100 event sequences (records) with 50 timestamped fields of binary values (0, 1) representing whether the event occurred or not. The test uses 3 different event distribution patterns (groups or classes) labeled by A, B and C. The sample function in R with the prob argument was used to control density and order of event occurrences. The first pattern (Label A) is characterized with the first 20 timestamps having a higher probability (0.8) of event occurrence and the remainder with lower probability (0.2). In the second pattern (Label B) the subsequence of higher probability of event occurrence is placed in the middle, and in the third pattern (Label C), the higher probability occurrence region is placed at the end. The event data structure of these three patterns and the observation number of each pattern are graphically depicted in Figure 15. the higher probability occurrence region is placed at the end. The event data structure of these three patterns and the observation number of each pattern are graphically depicted in Figure 15. We should note that the binary data (0, 1) can represent either two categories or actual values of 0 and 1. Therefore, both category-based and value-based similarity measures can be applied to this dataset. In this evaluation experiment, the category-based measures include Edit Distance and time-restricted Jaccard Distance for category data (trJacDist-cat) developed in this paper, and the value-based distance measures are Euclidean, Manhattan, Minkowski, and Cosine Distance. When running 1-NN classification test, the dataset with three patterns is first randomized and then divided into 70% training and 30% test set for the experimental setup. Hence, there are 70 training event sequences and 30 test sequences on which classification was performed. The effectiveness of a similarity measure in this experiment is evaluated with accuracy for classifying three patterns of event sequences (Label A, B, and C) and time for completing the task. To capture the fluctuation of time used for each task due to internal computer operation system, we run each 1-NN test for each similarity measure 15 times to compute the error bars.
Using seven similarity measures carried out with 1-NN classification for the dataset mentioned above, Figure 16 shows the comparison of accuracy and time elapsed to complete the given task. The effectiveness of different similarity measures can be seen by comparing the accuracy and time required to complete the task. While the same accuracy We should note that the binary data (0, 1) can represent either two categories or actual values of 0 and 1. Therefore, both category-based and value-based similarity measures can be applied to this dataset. In this evaluation experiment, the category-based measures include Edit Distance and time-restricted Jaccard Distance for category data (trJacDist-cat) developed in this paper, and the value-based distance measures are Euclidean, Manhattan, Minkowski, and Cosine Distance. When running 1-NN classification test, the dataset with three patterns is first randomized and then divided into 70% training and 30% test set for the experimental setup. Hence, there are 70 training event sequences and 30 test sequences on which classification was performed. The effectiveness of a similarity measure in this experiment is evaluated with accuracy for classifying three patterns of event sequences (Label A, B, and C) and time for completing the task. To capture the fluctuation of time used for each task due to internal computer operation system, we run each 1-NN test for each similarity measure 15 times to compute the error bars.
Using seven similarity measures carried out with 1-NN classification for the dataset mentioned above, Figure 16 shows the comparison of accuracy and time elapsed to complete the given task. The effectiveness of different similarity measures can be seen by comparing the accuracy and time required to complete the task. While the same accuracy can be achieved with trJacDist/trJacDist-cat and Edit Distance for classifying this small dataset, the time required with trJacDist measure is about 5 times less than Edit Distance measure. Euclidean, Manhattan and Minkowski Distance algorithms show a time advantage over trJacDist/trJacDist-cat, but slightly lower accuracy. We note that Cosine Distance has similar accuracy but a slightly better time performance. mono-categorical event (0, 1) distribution.
We should note that the binary data (0, 1) can represent either two categories or actual values of 0 and 1. Therefore, both category-based and value-based similarity measures can be applied to this dataset. In this evaluation experiment, the category-based measures include Edit Distance and time-restricted Jaccard Distance for category data (trJacDist-cat) developed in this paper, and the value-based distance measures are Euclidean, Manhattan, Minkowski, and Cosine Distance. When running 1-NN classification test, the dataset with three patterns is first randomized and then divided into 70% training and 30% test set for the experimental setup. Hence, there are 70 training event sequences and 30 test sequences on which classification was performed. The effectiveness of a similarity measure in this experiment is evaluated with accuracy for classifying three patterns of event sequences (Label A, B, and C) and time for completing the task. To capture the fluctuation of time used for each task due to internal computer operation system, we run each 1-NN test for each similarity measure 15 times to compute the error bars.
Using seven similarity measures carried out with 1-NN classification for the dataset mentioned above, Figure 16 shows the comparison of accuracy and time elapsed to complete the given task. The effectiveness of different similarity measures can be seen by comparing the accuracy and time required to complete the task. While the same accuracy can be achieved with trJacDist/trJacDist-cat and Edit Distance for classifying this small dataset, the time required with trJacDist measure is about 5 times less than Edit Distance measure. Euclidean, Manhattan and Minkowski Distance algorithms show a time advantage over trJacDist/trJacDist-cat, but slightly lower accuracy. We note that Cosine Distance has similar accuracy but a slightly better time performance.

Synthetic dataset 2:
This dataset contains 100 records (event sequences) with 128 timestamped fields of real values. As shown in Figure 17, there are three types of patterns in this dataset: sine, box, and ramp-cliff, each function of which has high level of white noise as the background noise. We excluded the Edit distance in this test as it is inappropriate for real valued data. We compared trJacDist with Euclidean, Manhattan, Minkowski, and Cosine distance-based similarity measures for evaluating the efficiency and accuracy of classification with 1-NN classifier. The dataset was also randomized and then split into 70% training and 30% test sub-datasets when running 1-NN classification. From the results shown in Figure 18 we can see that while trJacDist shows a time disadvantage against these methods it shares the same accuracy with Euclidean, Manhattan, and Cosine distance.  Figure 17, there are three types of patterns in this dataset: sine, box, and ramp-cliff, each function of which has high level of white noise as the background noise. We excluded the Edit distance in this test as it is inappropriate for real valued data. We compared trJacDist with Euclidean, Manhattan, Minkowski, and Cosine distance-based similarity measures for evaluating the efficiency and accuracy of classification with 1-NN classifier. The dataset was also randomized and then split into 70% training and 30% test sub-datasets when running 1-NN classification. From the results shown in Figure 18 we can see that while trJacDist shows a time disadvantage against these methods it shares the same accuracy with Euclidean, Manhattan, and Cosine distance.

Application Example
We examined the feasibility of the proposed framework in the real-world application of monitoring precipitation events obtained from observation stations distributed along Figure 18. The bar graph for accuracy and times for 1-NN using five different similarity measures applied on synthetic dataset 2 with three classes. Note: error bars are based on 15 times of computation for the same task.

Application Example
We examined the feasibility of the proposed framework in the real-world application of monitoring precipitation events obtained from observation stations distributed along the Maine coast. Here we demonstrate the specific steps of eventization and similarity measures developed in this study and we address the question: Do STES that are closer in space show higher similarity measures?
The Maine Department of Marine Resources (DMR) manages the shellfish growing areas in coastal Maine based on the fecal pollution situations observed from more than 2000 monitoring stations. Precipitation events can trigger high levels of fecal coliform in shore waters and are thus of concern. Grouping of similar stations in terms of heavy rain or high precipitation events is useful for allocating the limited labor pool for long term water sampling. We used the similarity measures developed in this study to conduct clustering analysis with the high precipitation event sequences (≥1 in daily) of selected monitoring stations for 5 years.
Considering the daily precipitation is very close between nearby monitoring stations we selected 43 monitoring stations for this experiment in the shellfish growing areas that are well distributed along the Maine coast ( Figure 19). With daily precipitation data of 5 years, we have an initial 43 × 1826 matrix of precipitation raw data (Table S1).
The dimensions of the raw data matrix is reduced through the eventization steps developed in this research. In this specific example, we extracted event sequences of either ≥1" or ≥2" precipitation for each monitoring station. Based on Equation (3) we computed the data in Table S1 with R script (STS.eventize1.R) and created the event sequence matrix of 43 × 192 (≥1" precipitation) (Table S2) or 43 × 52 (≥2" precipitation) (Table S3). Taking ≥1" precipitation event sequences as an example (Table S2) and using the STES similarity measure (STES.sim1.R) from this paper, we created the similarity matrix of 43 × 43 (Table S4) between selected test monitoring stations. We transformed these similarity data into distance data to conduct hierarchical clustering analysis [38] using the hclust R function with linkage method Ward.D2. Figure 20 shows the clustering results from using STES similarity on event sequences of ≥1 in precipitation during 5 years in 43 locations (monitoring stations) as a heatmap and distance-based cluster dendrogram. clustering analysis with the high precipitation event sequences (>=1 in daily) of selected monitoring stations for 5 years.
Considering the daily precipitation is very close between nearby monitoring stations we selected 43 monitoring stations for this experiment in the shellfish growing areas that are well distributed along the Maine coast ( Figure 19). With daily precipitation data of 5 years, we have an initial 43 × 1826 matrix of precipitation raw data (Table S1). The dimensions of the raw data matrix is reduced through the eventization steps developed in this research. In this specific example, we extracted event sequences of either >=1″ or >=2″ precipitation for each monitoring station. Based on Equation (3) we computed the data in Table S1 with R script (STS.eventize1.R) and created the event sequence matrix of 43 × 192 (>=1″ precipitation) (Table S2) or 43 × 52 (>=2″ precipitation) (Table S3). Taking >=1″ precipitation event sequences as an example (Table S2) and using the STES similarity measure (STES.sim1.R) from this paper, we created the similarity matrix of 43 × 43 (Table  S4) between selected test monitoring stations. We transformed these similarity data into distance data to conduct hierarchical clustering analysis [38] using the hclust R function with linkage method Ward.D2. Figure 20 shows the clustering results from using STES similarity on event sequences of >=1 in precipitation during 5 years in 43 locations (monitoring stations) as a heatmap and distance-based cluster dendrogram.  The results show the emergence of five clusters (groupings of event sequences that are most similar). The heatmap and cluster dendrogram indicate that these clusters are in fact spatial clusters indicating that for this case, sequences that are close in space tend to be more similar. These results can provide decision makers with more information for arranging the labor within each region (cluster) along the Maine coast to collect water samples for fecal coliform measurements from selected stations. The results show the emergence of five clusters (groupings of event sequences that are most similar). The heatmap and cluster dendrogram indicate that these clusters are in fact spatial clusters indicating that for this case, sequences that are close in space tend to be more similar. These results can provide decision makers with more information for arranging the labor within each region (cluster) along the Maine coast to collect water samples for fecal coliform measurements from selected stations.

Conclusions
In this paper, we have demonstrated a matrix-based representation of spatiotemporal event sequences for unifying punctual and interval events. These similarity measures along with the univariate spatiotemporal event matrices for event data storage discussed above provide a novel method and an alternative foundation for further event sequence pattern discovery. A comparison of event sequence similarity is important for detecting co-occurrence patterns and investigating the influence of event sequences of interest. We assume that similar event sequences indicate a similar process structure and potential shared causal mechanisms.
Based on the analysis of sequence properties for four situations and one special case that consider event co-occurrences and event levels, we have proposed corresponding similarity measures for pairwise comparisons for punctual and interval events and for whole or long duration sequences or their subsequences. The experimental results with simulated datasets showed that these similarity scores between spatiotemporal event sequences reasonably represent perceived closeness.
A comparative evaluation against other similarity algorithms shows the same or better accuracy results. Our method shows a time disadvantage against the real valued methods but a substantial time advantage over the qualitative Edit Distance. Overall, our approach has the advantages of flexibility in that it can accommodate both qualitative and quantitative event values as well as both punctual and interval events.
We recognize some limitations in the current research. This research establishes a framework of matrix representations and similarity development for univariate event sequences of different types. It does not yet handle similarity assessment for multivariate event sequences. Such an extension requires some modification of the matrix representation and similarity measures which will be addressed in future work. In the current work we demonstrate fixed matrix sizes which can be chunked into smaller subsequence sets for local versus global similarity computations. For future work, an extension that addresses streaming events from monitoring stations would be a useful addition. The addition of temporal logic operations and extensions to consider lagged sequence alignment similarity rather than the time locked case are other considerations for future work. Furthermore, we have not tested the current methods on big data. Future work will focus on the evaluation extensive real datasets from environmental monitoring or other domains. Currently our STES representation includes the intervals between event occurrences. For sequences in which event occurrences may be sparse with long intervening intervals we are considering approaches for sparse matrices. Lastly, we also consider extensions to detect complex events of interest, and incorporation of our methods into Complex Event Processing (CEP) systems.