An Effective Method for Mining Negative Sequential Patterns From Data Streams

Traditional negative sequential patterns(NSPs) mining algorithms are used to mine static dataset which are stored in equipment and can be scanned many times. Nowadays, with the development of technology, many applications produce a large amount of data at a very high speed, which is called as data stream. Unlike static data, data stream is transient and can usually be read only once. So, traditional NSP mining algorithm cannot be directly applied to data stream. Briefly, the key reasons are: (1) inefficient negative sequential candidates generation method, (2) one-time mining, (3) lack of real-time processing. To solve this problem, this paper proposed a new algorithm mining NSP from data stream, called nsp-DS. First, we present a method to generate positive and negative sequential candidates simultaneously, and a new negative containment definition. Second, we use a sliding window to store sample data in current time. The continuous mining of entire data stream is realized through the continuous replacement of old and new data. Finally, a prefix tree structure is introduced to store sequential patterns. Whenever the user requests, it traverses the prefix tree to output sequential patterns. The experimental results show that nsp-DS may discover NSPs from data streams.


I. INTRODUCTION
Sequential pattern mining aims to discover regular sequential patterns from a dataset of ordered events. Sequential pattern mining has been widely used in the field of group behavior analysis [1], [2], [3], optimization strategy [4], classification and clustering problem [5], [6], phenotypic structure learning [7], comparative behavior analysis [8], abnormal behavior detection [9], business intelligence [10], [11], education [10], recommendation system [12] and so on. In traditional sequential pattern mining research, sequence data are mostly in static form, but in reality, sequence data are mostly presented in a continuous dynamic ''stream''. Data stream [13], [14], [15] is a set of continuous sequence information, such as the user's network click stream, call data, sensor network data, scientific data, online retail transaction data, real-time stock transaction data, and network color data. Sequential pattern The associate editor coordinating the review of this manuscript and approving it for publication was Vlad Diaconita . mining in data streams is an important research branch of sequential patterns mining.
However, the current research on sequential patterns mining in data streams only focuses on positive sequential patterns(PSPs), and no relevant research on NSPs mining has been found. Meanwhile, traditional NSP mining algorithms only target static datasets and cannot be applied directly to data streams. The data stream-oriented sequential pattern mining algorithm needs to take more into account the continuous, fast, real-time, massive, changing and orderly characteristics of the data stream. So, it is challenging to apply total algorithms in static datasets to data streams. The reasons are as follows: 1) Inefficient Negative Sequential Candidates Method. Current NSPs mining algorithms first mine PSPs, and then generate and obtain NSPs based on PSPs. This segmental method will produce a lot of intermediate results and affect the mining efficiency.
2) One-time Mining. Traditional NSPs mining is based on static datasets. All sequences are stored in memory simultaneously. So, traditional algorithms process all data at one time. But, NSPs mining in data streams is based on continuous, rapid, and massive data. It is difficult to keep an entire data stream in memory, so it becomes impossible to process all data at one time.
3) Lack of Real-time Processing. Mining in data streams has higher requirements for speed. The real-time arrival and processing of the data stream are not available in traditional NSPs mining.
Based on the traditionl sequential pattern mining algorithms, the purpose of this paper is to propose a sequential pattern mining algorithm that can be adapted to data stream mining scenario. In this article, we propose an efficient algorithm, named nsp-DS, to mine NSPs from data streams. nsp-DS introduces ideas such as sliding windows, prefix trees, etc. The main idea is as follows.
First, we propose a method to generate positive and negative sequential candidates simultaneously, by improving the S-Step process in SPAM [16]. At the same time, we present a new negative containment definition suitable for mining PSPs and NSPs simultaneously. nsp-DS uses a bitmap to store data and uses bitwise operations to calculate support while generating candidates, which requires each item to be represented on the bitmap in a one-to-one correspondence.
Second, nsp-DS uses a sliding window to store sample data at the current time. When sliding window is first full, the algorithm mines the dataset in the window for the first time. When new data arrives, it replaces the oldest data by overwriting to update the sliding window. Then, we continue to mine the current window according to new data.
Third, we design a prefix tree structure to store sequential patterns. When the sliding window is first full, we create a prefix tree to store NSPs. With the arrival of new data, we mine the current window only by the new data and update the prefix tree using the mined sequential patterns. This operation can avoid repeated mining of old data in the sliding window and improve mining efficiency. Whenever the user requests, it traverses the prefix tree to output sequential patterns.
Finally, we propose the corresponding algorithm, called nsp-DS, for mining NSPs from data stream, and conducte some experiments in four real-world datasets. The experimental results show that nsp-DS can mine NSPs from data stream efficiently.
The rest of this paper is organized as follows. Section II discusses related work. In Section III, we introduce fundamental concepts about mining sequential patterns in data streams. Section IV implements the proposed method in detail. Section V describes the experiments and explains the experimental results. Section VI concludes this work.

II. RELATED WORK
Currently, we only find relevant studies on PSP mining in data streams, but not on NSP mining. The relevant research on NSP mining is focused on static datasets. So, in this section, we introduce works related to NSPs mining in static datasets and PSPs mining in data streams.

A. NSPS MINING IN STATIC DATASETS
NSPs refer to a frequent sequence that contains both occurring and unoccurring events. However, it is much more difficult to discover NSPs than PSPs due to the complexity of the problem caused by unoccurring behavior. But, it is obvious that mining NSPs will find more valuable information. According to different requirements, researchers have proposed corresponding definitions and algorithms [17], which are wildly used in medical education, behavior analysis,and other fields [7], [8], [9]. Hsueh. et al. proposed PNSP algorithm, which converts frequent positive elements to negative elements and then generates negative sequential candidates by concatenation [17]. Zheng et al. proposed NegGSP [18] algorithm based on GSP [19], which scans the dataset to get NSPs. Cao et al. proposed a very innovative and efficient theoretical framework: the set theory-based NSP mining (ST-NSP) and the corresponding algorithm e-NSP [20]. It identifies NSPs only by PSPs discovered without re-scanning the database, which makes e-NSP performs particularly well on datasets with a small number of elements in the sequence, a large number of itemsets, and low minimum support. However, when the dataset becomes dense, the key process of obtaining the support of negative sequence candidates in e-NSP becomes very time-consuming. To solve the problem, Dong et al. proposed f-NSP [11] algorithm, which uses a bitmap to store the information of PSP, and then obtains the support degree of negative candidate sequences only through bit operation, and is much faster than the hash method in e-NSP. To mine the expected number of NSP, Dong et al. proposed a TopK-NSP algorithm [12] to mine k common NSP. Gao et al. proposed sc-NSP [21]. sc-NSP improves PrefixSpan algorithm and increases negative candidate sequences by relaxing constraints conditions, which makes more interesting candidate sequences found.

B. PSPS MINING IN DATA STREAMS
The initial research work on data streams was first carried out by Alon et al. in 1996 [22]. Data stream model was proposed by Henzinger et al. in 1998. Later algorithms on data streams proliferate. These algorithms are generally based on traditional sequential pattern algorithms, combined with window models commonly used for data stream mining to extend and optimise the algorithms to obtain new algorithms. Chedi et al. proposed SPEED [23] which uses a novel treereg data structure to store useful information. On the basis of SPEED algorithm, Lei et al. proposed the Seq-Stream algorithm [24]. Shih-Yang Yang et al. designed an incremental mining algorithm IAspam [25] to mine sequential patterns in interaction streams. Meanwhile, Shih-Yang Yang et al. also proposed the ICspan [25] algorithm to mine closed sequences in data streams. Referring to the two algorithms proposed by Shih-Yang Yang, Guanling Lee et al. proposed PAlgorithm VOLUME 11, 2023 and PSAlgorithm [26] to mine sequential patterns in data streams, and these two algorithms use the data structure Path-Tree to effectively integrate some of the mining results. CI Ezeife et al. proposed the SSM (Sequential Stream Mining) algorithm [27], which decomposes the data stream into blocks of variable size. Mendes, J.Han et al. proposed the SS-BE (Stream Sequence miner using Bounded Error) algorithm [28] and SS-MB (Stream Sequence miner using Memory Error) algorithm [28], both of which decompose the data stream into data blocks, and then mine sequential patterns in each data block. He Xingxing et al. proposed an efficient pruning-based sequential pattern mining algorithm SSPM(Stream Sequential Pattern Mining). Raissi and Poncelet [29] proposed a sampling-based algorithm for approximating global patterns. Tanbeer   If the sequence of α = ⟨α 1 , α 2 , . . . , α n ⟩ for the sequence β = ⟨β 1 , β 2 , . . . , β n ⟩ or β is a supersequence of α, it needs to satisfy the requirement of 1 ≤ j 1 ≤ j 2 ≤. . . ≤j n ≤m and α 1 ⊆β j 1 , α 2 ⊆β j 2 ,. . . , α n ⊆β j n , denoted as α⊆β(β includes α). For example, a subsequence of ⟨a, b, c, e⟩ is ⟨ce⟩, and ⟨a, b, c, e⟩ is a supersequence of ⟨c, e⟩.
Sliding Window(SW = {S 1 , S 2 , S 3 , . . . , S w }), constitutes an instantaneous sample of DS. w, the width of SW , is the number of sequences contained in SW . w is set by the user. For all sequences in a given window SW of a data stream, the support of sequence s is defined as sup(s) = f (s)/w where f (s) is the number of sequences in which s occurs. min_sup is a user defined value to determine if sequence s is frequent or not. If sup(s) ≥ min sup, the sequence s is frequent.
Definition 1 (Positive Sequential Pattern, PSP): If the support degree of a positive sequence is bigger than or equal to min_sup, the positive sequence is a PSP.
Definition 2 (Negative Size): The number of negative elements in the sequence ns is negative size denoted as negsize(ns). If negative(ns)=n, ns is an n-negsize sequence. For example, ns=⟨¬a, b, ¬e, f ⟩, ns is a 2-negsize sequence, denoted as negsize(ns)=2.
Definition 3 (Positive Matching): For elements, Positive Matching refers to transforming negative elements into positive elements. For example, Positive Matching of negative elements ¬a is a, denoted as p(¬a)=a; For sequences, Positive Matching is the transformation of all negative elements in the sequence into their corresponding positive elements, denoted as p (ns) = {⟨s 1 ′,

Definition 4 (Maximum Positive Subsequence, MPS):
The maximum positive subsequence of a sequence is the subsequence that includes all positive elements in this sequence. S is a subsequence of ns=⟨s 1 , s 2 , . . . , s m ⟩. If S includes and only includes all positive elements in ns, then S is the maximum positive subsequence of ns. denoted as MPS(ns).
The definition of negative containment in e-NSP is MPS (ns) ⊆ ds; ∀1-negMS∈1-negMSS ns , p(1 − negMS) ̸ ⊂ ds, that is, there is no need for a negative element in ns correspond with a certain element in ds in position. Assuming ns = ⟨a, ¬b, c⟩, ds 1 = ⟨a, c, e⟩, ns ⊆ ds 1 under the definition of e-NSP negative containment, that is, there is no need for an element corresponding to ¬b between elements a and c in ds(the element can be one or more). However, nsp-DS uses a bitmap to store data, which requires each element/item (including negative element/item) to be represented on the bitmap in a one-to-one correspondence. For example, ds 2 = ⟨a, d, c, e⟩, element d between a and c can correspond to ¬b, then ns ⊆ ds 2 . The definition of negative containment in e-NSP can not satisfy this requirement.
We try to extend the bitmap in SPAM [16] by adding a 0 between each item. Taking the sequence ⟨b, a, b⟩ as an example, the bitmap of item a is shown in Fig. 1. Among them, the left side of Table 1 represents the original bitmap of item a, and the right side represents the expanded bitmap. The bold font represents the 0 or 1 in the original bitmap, and the usual represents the added 0. However, this will make the bitmap sparse, which will reduce the efficiency of the algorithm. Therefore, in nsp-DS algorithm, we use a new definition of negative containment.
Definition 5 (Negative Containment): If the negative sequence ns=⟨e 1 , e 2 , . . . , e k ⟩ is contained in sequence ds= d 1 , d 2 , . . . , d m (m>k), for any negative element e i , there are p, q, r(p<q<r) that need to meet the following two conditions: (1)MPS(ns) ⊆ ds (2) 1) For negative sequence ns = ⟨b, ¬b, d⟩, ns is contained in ds. That is because the element b does not appear between b and d in ds. 2) For negative sequence ns = ⟨b, ¬c, d⟩, ns is not contained in ds. That is because the element c appears between b and d. 3) For negative sequence ns = ⟨¬a, b⟩, ns is not contained in ds. That is because there is no element before b in ds. 4) )For negative sequence ns = ⟨d, ¬a⟩, ns is not contained in ds. That is because there is no element after d in ds.
NSP has no unified definition. Thus, if the form of NSPs is not constrained, the number of negative sequential candidates will explode. Most of these candidates are meaningless, which brings difficulties to the mining process. Different constraints are used in different NSPs mining algorithms. The negative sequential constraints adopted in this paper are as follows: Constraint 1(Size Constraint): The maximum size of the negative sequence should not be greater than the data sequence size.

Constraint 2(Frequency Constraint):
The positive element corresponding to each negative element in negative candidate sequences must be frequent.

Constraint 3(Format Constraint):
No consecutive negative elements are allowed in a negative sequence.

Constraint 4(Negative Element Constraint):
The smallest negative unit in a sequence is an element.
Definition 6 (Negative Sequential Pattern, NSP): If the support degree of a negative sequence is bigger than or equal to min_sup, the negative sequence is a NSP.

IV. NSP-DS ALGORITHM
In this section, we propose a novel and efficient algorithm, called nsp-DS, to obtain NSPs in a data stream. We introduce data structures used in nsp-DS in Section IV-A. The methods of generating candidate and support calculations are discussed in Section IV-B. The idea of nsp-DS algorithm is described by an example in Section IV-C.
A. DATA STRUCTURE nsp-DS algorithm mainly includes three data structures, which are used to store timely datasets in sliding windows, sequence information, and NSP mining results.

1) BITMAP MATRIX
In SPAM algorithm, for the sequences whose size is between 2 k + 1 and 2 (k+1) , it needs to be complemented. The vacant position is filled with 0 in the bitmap, which makes the length of each bitmap equal. For example, Fig.2 is the bitmap of item a in the sequence ⟨b, a, b⟩. 0 in the fourth bit is a complement. We follow the method representing negative items in SPAM: the occurrence position is represented by 1 and the absence of occurrence is represented by 0. Then, from Fig.2, we can see ¬a appears in the first, third, and fourth elements of the sequence ⟨b, a, b⟩, but there are only three elements in the sequence ⟨b, a, b⟩, no fourth element. To sum up, according to the original filling method, an error will appear in the bitmap of the negative item.
Therefore, in nsp-DS, the complement operation is not performed. The length of the bitmap of each item is equal to the size of the current sequence. nsp-DS converts the dataset in a window into a bitmap matrix(BM), using 1 or 0 to represent if an item shows in a sequence. Specifically, nsp-DS creates a vertical bitmap for each item that appears in the window, and each bit in the bitmap corresponds to the position of each element in the window. If item i appears in a sequence, the bit corresponding to the position of item i in this sequence is set to 1; otherwise, the bit is set to 0. At the same time, we divide the bitmap, and the length of each part is the size of the corresponding sequence. Taking the data in Table 1 as an example, the vertical bitmap of each item is shown in Fig.3. Using this idea to negative single items, the position where a negative single item can appear is set to 1, and 0 otherwise. It can be found that the bitmap of the negative single item is complementary to the bitmap of the corresponding positive single item. Therefore, in nsp-DS, the bitmap of the negative single item is obtained by inverting the bitmap of the positive single item. Sequences can also be represented by bitmaps according to the above idea. If the last element of a sequence is j, and all other elements or items of the sequence appear before j, then the bit corresponding to j will be set to 1; otherwise, it will be set to 0. Define B(s) to represent a bitmap of the sequence s.

2) TABLE OF SEQUENCE INFORMATION
The conversion method of the sequence s in SPAM is to avoid the situation that the subsequent element α appears before s and in s. Set to 1 is to ensure that statistics can be performed as long as the element α appears later. This method only considers whether the subsequent element α appears and does not consider the position of α. But a NSP needs to take into account the position of α and the position where s starts at the time of conversion. In nsp-DS, we use a new data structure to show sequence information, including a sequence bitmap, a negative element bitmap, the set of sequence start position pointers, and support. The negative element bitmap is the bitmap of the last negative element in the sequence. Hash table sidHash ⟨id, position⟩ is the set of sequence starting position pointers. Suppose e is the last positive element of the sequence s. sid is the sid number of the sequence containing e, and position is the first position where e shows in each bitmap. Taking the dataset in Table 1 as an example, the information of negative sequences ⟨b, ¬b⟩ and ⟨b, ¬b, c⟩ are shown in Fig. 4.

3) SEQUENCE PATTERN TREE
A sequence pattern tree(SPT) is used to maintain sequential patterns in each sliding window. It is essentially a prefix tree. Attributes of nodes include item(element) name and sup of sequence which consists of items in the path from the root to the node. If node Root is layer 0, the path from Root to a node at layer k represents k − size sequence. Due to NSPs' dissatisfaction with the downward closure property, there may be some infrequent negative sequences in SPT. We mark infrequent negative sequences which consists of items in the path from the root to a node by setting sup of the node to 0. The structure of SPT is shown in Fig.5.

B. CANDIDATE GENERATION AND SUPPORT CALCULATION METHOD
SPAM algorithm records the position of the first occurrence in each bitmap of the existing sequence s as k, stores the position of k in the table, and then converts it once (the bitmap before k and k is set to 0, and the element after k is set to 1), and finally does AND operation with the subsequent element α. If we use the same method as SPAM does, there will be some problems. Take the dataset in Table 1 as an example. the bitmap of ⟨b, ¬b⟩ is shown in Fig.6, where b s represents the bitmap transformed by b. According to the support calculation method in SPAM, if a bitmap partition contains 1, add one to sup; otherwise, this partition has no contribution to sup. In Fig.6, the sup of ⟨b, ¬b⟩ is 3, that is, ⟨b, ¬b⟩ appears in the 2 nd , 3 rd , and 5 th sequences. We can find that in the 2 nd sequence ⟨b, a, b⟩ and 3 rd sequences ⟨b, d, b, c⟩, b appears after the first element b. Therefore, this method is not suitable for calculating the support of negative sequences in nsp-DS. Next, we will show how to complete the S-Step process with the structure mentioned above. The S-Step is to recursively expand the sequence of positive and negative elements, and the result is a logical sequence tree. In other words, S-Step is the process of creating a sequence tree by traversing. In S-Step, we extend sequence s by adding an extended element e after the last element of s. The S-Step includes three types: PP, PN, and NP. PP means that the last element of s and e are both positive, PN is that the last element of s is positive and e is negative, and NP is that the last element of s is negative and e is positive.
Suppose there is a dictionary sequence in the dataset, if item i occurs before item j, we denote i ≤ j. If s a is a subsequence of s b , this ordering can be extended to the sequence definition s a ≤ s b . The root is marked as null in sequence tree T. Recursively down, if n is a node of the tree, then all children nodes of n are n ′ , such that n ≤ n ′ and ∀m ∈ T : n ′ ≤ m ⇒ n ≤ m. Trees are infinite in this definition. Since NSP does not satisfy the property of downward closure, in practice, the sequence tree is also infinite. Therefore, we need to limit the size of the tree. According to the definition and negative constraint conditions, the size of PSPs and NSPs cannot exceed the size of the largest sequence in data streams. Assuming the size of the largest data sequence is k, for ∀m ∈ T : n ′ ≤ m ⇒ n ≤ m, m ≤ k, the sequence tree is finite. Fig.7 is the result of extending two elements (a and b). Assume that the maximum size of sequences after extending is 4. The top of the tree is ∅. k − size sequence is in k layer. Sequences are arranged in lexicographic order in each layer. if there is a 1, sup is increased by one. If an element appears multiple times in a certain data sequence, that is, 1 appears more than once in a certain partition, sup of this partition is only recorded as 1.
Take the generation process of the extended sequence

2) PN GENERATION
Assume that the last element of sequence s a is positive, and the extended element e is negative. The generation method of the extended sequence s b bitmap is consistent with that of PP. But the sup calculation method is different. Suppose that the position where 1 first appears in a partition of B(s a ) is k, the element corresponding to position k should be the last element j of s a , and j is positive. If 0 appears after k in the corresponding partition of B(e), it means that the positive element corresponding to e appears after j. According to Definition 5, s b is not included in this sequence. Therefore, sup of s b is to judge whether 0 appears in position after k in B(e). If 0 does not appear, as long as 1 appears in the corresponding partition in B(s b ), sup is increased by one; otherwise, sup is unchanged.
Take the example of generating the extended sequence ⟨b, ¬b⟩. As shown in Fig.9, the transpose position k of the sequence ⟨b⟩ is marked red, and the position where B (¬b) appears 0 in this partition is represented by the arrow. We can find that 1 appears in 2 nd and s nd partition in B (⟨b, ¬b⟩). However, 1 in these two partitions does not influence sup because of the appearance of 0 in B (¬b) after k. sup of ⟨b, ¬b⟩ is only 1. At the same time, the sequence starting position in sidHash ⟨id, position⟩ of ⟨b, ¬b⟩ is modified, and the transpose position k of each partition containing 1 is stored.

3) NP GENERATION
Assuming that the last element of sequence s a is negative, and the extended element e is positive, the generation method of the extended sequence s b bitmap is more complicated than the first two. First, AND the transposed bitmap of s a with B (e) to get a new bitmap. Secondly, we denote the starting position recorded in the table of s a information as p and denote the position where 1 first appears in each partition in the new bitmap as j. Judge whether 0 appears between p and j in the negative element bitmap. If not appear, bit 1 in position j is reserved. If appear, the bit in position j is set to 0, and bit 1 in position after j in this partition is also set VOLUME 11, 2023  to 0. At the same time, if all 1 are reserved, sup is increased by one. This operation is to ensure that a negative element that occurs between two positive elements of the extended sequence s b does not appear at the corresponding position in the data sequence. If we do not make the above operation, subsequent sequence extensions may have some misjudgment. For a sequence, ds = ⟨a, b, d, a, b, d, a, c, d⟩, B (⟨a, ¬b, d⟩) is shown as Fig.10. ⟨a, ¬b, d⟩ is the extension sequence of sequence ⟨a, ¬b⟩. According to B (⟨a, ¬b, d⟩), we can infer that element d may appear in 6 th and 9 th position. But, in ds, there is an element b between a in 1 st position and d in 6 th position. In the same way, this b is also between a in 1 st position and d in 9 th position. According to Definition 5, ⟨a, ¬b, d⟩ is not contained in ds. If we extend ⟨a, ¬b, d⟩ to ⟨a, ¬b, d, ¬b⟩, it is obviously wrong that ⟨a, ¬b, d, ¬b⟩ is contained in ds according to the sup calculation method used in PN Generation. Take the generation of the extended bitmap B (⟨b, ¬b, c⟩) as an example, as shown in Fig.11. The red indicates the starting position k recorded in the table of the sequence ⟨b¬b⟩ information. j is the position where bit 1 first shows in each partition of B (⟨b, ¬b, c⟩). The arrow points to the position where bit 0 occurs between k and j. Because bit 0 appears on position 3 in 3 rd partition of B (⟨¬b⟩), all bit 1 after position 3 in 3 rd partition of are set to 0.

4) PRUNING STRATEGY
nsp-DS algorithm generates k − size candidate sequences by extending (k − 1) − size sequences, so the number of candidate sequences will be very large. It makes it difficult to search for meaningful sequential patterns. In order to improve the performance of the algorithm, we need to remove some candidates during S-Step. This is called Pruning Strategies which are divided into the pruning strategy of positive candidate sequence and the pruning strategy of negative candidate sequence.
The pruning strategy of positive candidate sequences is removing infrequent positive sequences generated during extension according to the downward closure property. For example, the sequence ⟨c, d⟩ extends to ⟨c, d, e⟩ during S-Step. If ⟨c, d, e⟩ is infrequent, its extension sequences are also infrequent. Therefore, delete ⟨c, d, e⟩ directly and no longer extend it. The pruning strategy of negative candidate sequences is that two adjacent negative elements are not allowed in a NSP according to Constraint 3. For example, for the negative sequence ns = ⟨e 1 , e 2 . . . e n ⟩, when e n is a negative element, and the following element α is a negative element, we prune it and do not perform the following steps. The algorithm is explained in detail as follows: 1) Traverse each element e in Sn, and combine the sequence s with e to generate a new extended sequence s ′ , as shown in Line 3. 2) If element e is negative and the last element of the sequence s is also negative, stop the current loop (Lines 3-5). 3) If the extended sequence s ′ is positive and frequent, s ′ is a PSP, and the element e is stored in S temp (Lines 8-11). 4) If the extended sequence s ′ is negative, judge whether s ′ and s are frequent. If neither is frequent, stop the current loop, otherwise store element e in S temp (Lines 13-17). 5) Merge elements in S temp with sequence s to generate a new sequence and perform the next recursion with the new sequence and S temp . if s′ is positive sequence then 8: if s′ is frequent then 9: s′ is stored in PSPs; 10: S temp = temp ∪ e; 11: end if 12: else 13: if s and s′ are infrequent then 14: Continue; 15: else 16: S temp = S temp ∪ e; 17: end if 18: end if 19: end for 20: for each element e in S temp do 21: sequence s′ ← s = ⟨e 1 , e 2 , . . . , e n ⟩ ∪ e 22: DFS of Sequence Tree(s′,Sn); 23: end for C. IDEA OF NSP-DS ALGORITHM When the window is full(the number of sequences in a window is equal w) for the first time, mine PSPs and NSPs, and store these patterns to SPT. After the window slides, the new sequence S new replaces the oldest sequence S old . SPT is updated according to elements in S old . And then, sequential pattern mining is performed for S new . Finally, update the prefix tree again. When the user makes a request, scan SPT to get PSPs and NSPs in the current period. VOLUME 11, 2023 Take the data stream shown in Table 2 as an example to introduce the nsp-DS algorithm, and set min_sup=0.5 and w=6.

1) WHEN WINDOW IS FIRST FULL
At first, the window W is empty(w = 0). When the number of sequences in W is equal to w, W is full. At this time, we convert the dataset in W into a bitmap matrix and mine PSPs and NSPs in the dataset of W .
Take the data stream in Table 2 as an example. When W is filled for the first time, there are six sequences in W . So, the dataset in W will be converted into a bitmap matrix(BM), as shown in Fig.12. Then, mine dataset in W to get PSPs and NSPs. The  sequential patterns a , a, d , a, d, ¬b , a, d, ¬b, g , a, d,  g , a, g , b , b, d , b, d, ¬b , d , d, ¬b , d, ¬b, g , d, f ,  d, g , ¬b , ¬b, f , ¬b, f , g , ¬b, g , f , f , ¬b , f , g , g is obtained. These patterns are stored in SPT, as shown in Fig.13.

2) WHEN WINDOW STARTS SLIDING
When W is filled, the newly arrived sequence overrides the oldest sequence in the window, completing a window sliding. Sid old = Sid new · · · · · · w. Sid old is the Sid of replaced sequence, and Sid new is the Sid of the newly arrived sequence.
Step 1: updating BM. The new sequence Sid = 7 replaces the old sequence Sid = 1. Set the bit of each column of the row Sid=1 in BM to 0, and re-assign the bit to the row with the sequence Sid=7. The process and result are as shown in Fig.14. Update sup of the corresponding node of SPT. 1 − size patterns associated with Sid = 1 are ⟨a⟩ , ⟨b⟩ , ⟨d⟩ , ⟨f ⟩ , ⟨g⟩ , ⟨¬b⟩ . So, sup of nodes ⟨a, b, d, f , g, ¬b⟩ in SPT are decremented by 1. This is shown in Fig.15.
Step 2: mining sequential patterns for S new . S new = S Sid=7 = ⟨a, b, e, g⟩. In this step, sequential pattern mining is conducted only for the elements a, b, e, g, ¬b, ¬c, ¬d, ¬e, ¬f . These negative elements are the ones that change during the alternation of the old and new sequences. Because the number of items contained in each sequence is far less than the total number of items in the whole data stream, the efficiency of nsp-DS is improved.
Scan the BM after updating, and count the number of 1 in columns a, b, e, g, ¬b, ¬c, ¬d, ¬e, and ¬f .
Step 3: responding to the request of the user. When the user requests, scan SPT to get sequential patterns in the current window. Traverse SPT. If sup of for all nodes on the path from a node to its leaf node are less than min_sup, delete those nodes from SPT. After pruning, SPT is shown as Fig.16 insert k − size PSPs and NSPs to SPT; 8: end for 9: else 10: while sequence s is not the last sequence of DS do 11: get 1 − size PSPs and NSPs associated with the oldest sequence in the current window; 12: update SPT(the frequency of all nodes containing 1 − size PSPs and NSPs in SPT are reduced 1); 13: replace the oldest sequence with sequence s; 14: get 1−size PSPs and NSPs associated with sequence s; 15: update SPT(1−size PSPs and NSPs associated with sequence s); 16: for each sequence s in 1 − size PSPs and NSPs do 17: k − size PSPs and NSPs←DFS of sequence Tree(e,1 − size PSPs and NSPs); 18: update SPT(k − size PSPs and NSPs); 19: end for 20: end while 21: end if 22: return SPT;

V. EXPERIMENTS ANALYSIS
We conduct experiments on four real-world datasets downloaded from https://www.philippe-fournier-viger.com/spmf/. Table 3 shows the features of four datasets. nsp-DS are implemented in Eclipse, running on a Windows 11 PC with 16 GB memory, and an Intel Core i5 2.4 GHz CPU. All the programs are written in Java.
Unfortunately, we find no algorithm suitable for a comparison algorithm. The reasons are as follows: 1) A traditional sequential patterns mining algorithm is not suitable for a comparison algorithm. The dataset used in traditional sequential pattern mining algorithms is completely different in nature from the dataset used in nsp-DS. In traditional sequential pattern mining algorithms, all data are stored in memory simultaneously. But data streams are generated continuously over time. In other words, datasets in traditional algorithms are static, but in nsp-DS they are dynamic. If comparing nsp-DS with a traditional sequential patterns mining algorithm, we cannot find a dataset that is suitable for both algorithms. Thus, nsp-DS cannot be compared with a traditional sequential patterns mining algorithm. 2) A PSPs mining algorithm in data streams is not suitable for a comparison algorithm. In order to improve the efficiency of the algorithm and to conform to the transient characteristics of the data stream, nsp-DS generates positive and negative candidate sequences simultaneously. If compared with PSPs mining algorithms in data streams, the new method of producing candidates in nsp-DS will become meaningless. So, no PSPs mining algorithm in data streams can be a comparison algorithm.

A. NUMBER OF NSPs AND PSPs GENERATED BY NSP-DS
In this section, we analyze the number of NSPs and PSPs generated by nsp-DS with various min_sup. From Fig.18, we can find that the number of NSPs and PSPs decreases as min_sup increases when w is fixed. For the same window size, as min_sup gets larger, the number of candidates that can meet the support gets smaller so fewer NSPs and PSPs are produced.

B. RUNTIMES ON NSP-DS
In this section, we analyze runtimes on nsp-DS. The results are shown in Fig.19. It is clear that the runtime increases as the support decreases. When min_sup is decreased, a large number of NSPs are discovered so that the runtime is increased.

C. SCALABILITY TEST ON NSP-DS
In this section, we perform scalability experiments on each four datasets with increasing number of sequences. Specially, the selected window sizes are 5,000 in BMSWebView1, 5,000 in BMSWebView2, 1,000 in FIFA, and 10,000 in MSNBC, with various low minimum supports min_sup 0.11 and 0.12 on BMSWebView1, 0.04 and 0.05 on BMSWebView2, 0.40 and 0.41 on FIFA, and 0.78 and 0.79 in MSNBC, respectively. Fig.20 shows the results of nsp-DS on each dataset in terms of different number of sequences: from 5,000 to 25,000 sequences of BMSWebView1, from 5,000 to 25,000 sequences of BMSWebView2, from 1,000 to 5,000 sequences of FIFA, from 1,0000 to 3,0000 sequences of MSNBC. Abscissa represents number of sequences, the ordinate represents the running time of the algorithm, and each point represents the running time of the algorithm in different support degrees when window size is fixed under the current dataset.
The experimental results show that the runtime has a roughly linear relationship with number of sequences increase under various minimum supports and window size. Therefore, nsp-DS has good scalability in terms of runtime with respect to number of sequences.

VI. CONCLUSION AND FUTURE WORK
Because of the characteristics of data streams, traditional NSPs mining algorithms cannot be directly applied to data streams. At the same time, the existing algorithms in the data stream only mine PSPs, and no algorithm mining NSPs is found. Mining NSPs in data streams is a challenging task. In this paper, we propose nsp-DS algorithm, which introduces a sliding window and a prefix tree structure to mine NSPs in data streams. Firstly, different from the method of two-step negative candidate generation, nsp-DS generates positive and negative candidates simultaneously. In particularly, it uses bit operations to generate negative candidates and calculate sup of negative candidates. Secondly, a prefix tree structure that can store NSPs is designed. During data replacement, we only need to update the prefix tree, not create another tree. Finally, experiments show that nsp-DS algorithm can mine NSPs in the data stream.
Although nsp-DS can be applied to mining NSPs in data streams, it is only applicable to sequences whose element is 1−size in data streams. Work still remains to accurately mine sequences with k−size element(k > 1) in data streams. Then, since NSPs do not have the downward inclusion property, there may be infrequent nodes in the prefix tree. We need to find a better structure to store NSPs.