scieee AI-readable full text Open interactive document viewer

Online algorithms for change detection in information systems and web environments

Nikolic Fraguela, Ivan

Abstract

El projecte té com objectiu dissenyar algorismes online basats en técniques de data streaming i mètodes formals per monitoritzar el comportament dels processos que governen un sistema d'informació o una web.

Full text

Títol: Online algorithms for change detection in information systems and web environments Volum: 1 Alumne: Iván Nikolic Fraguela Director: Josep Carmona Vargas Codirector: Ricard Gavaldà Mestre Departament: Llenguatges i Sistemes Informátics Data: 21/06/2013 DADES DEL PROJECTE Títol del Projecte: Online algorithms for change detection in information systems and web environments Nom de l'estudiant: Iván Nikolic Fraguela Titulació: Enginyeria Informática Crèdits: 37,5 Director: Josep Carmona Vargas Codirector: Ricard Gavaldà Mestre Departament: Llenguatges i Sistemes Informátics MEMBRES DEL TRIBUNAL (nom i signatura) President: Enric Rodriguez Carbonell Vocal: Maria Angela Grau Gotes Secretari: Josep Carmona Vargas QUALIFICACIÓ Qualificació numèrica: Qualificació descriptiva: Data: Contents 1 Introduction 9 1.1 ProcessMining............................ 9 1.2 Concept Drift Example . . . . . . . . . . . . . . . . . . . . . . . 11 2 Preliminaries 16 2.1 Logs .................................. 16 2.2 ParikhVectors ............................ 17 2.3 Abstract Interpretation . . . . . . . . . . . . . . . . . . . . . . . 19 2.4 Adaptive Windowing . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.4.1 Adwin............................. 23 2.4.2 Overview of the ADWIN algorithm . . . . . . . . . . . . . 24 2.5 PetriNets............................... 24 3 Online Concept Drift detection 27 3.1 Learningthemodel.......................... 27 3.2 Estimation .............................. 28 3.3 Monitoring .............................. 29 3.4 MultipleAdwin............................ 29 3.5 Drift detector for websites . . . . . . . . . . . . . . . . . . . . . . 31 3.5.1 Weblogger .......................... 32 3.5.2 Server............................. 32 3.6 Modelgenerator ........................... 33 4 Design & Specification 35 4.1 Goalsoftheproject ......................... 35 4.2 SystemOverview........................... 37 4.3 Online Drift Detection Algorithm . . . . . . . . . . . . . . . . . . 39 4.4 ModelGenerator ........................... 39 4.5 MainModule ............................. 40 4.6 Drift detector for websites . . . . . . . . . . . . . . . . . . . . . . 41 5 5 Implementation 44 5.1 Online concept drift detection algorithm . . . . . . . . . . . . . . 44 5.1.1 Model related functions . . . . . . . . . . . . . . . . . . . 44 5.1.2 Core of the algorithm . . . . . . . . . . . . . . . . . . . . 45 5.2 ModelGenerator ........................... 50 5.3 Main.................................. 50 5.4 WebServer............................... 51 5.5 WebClient............................... 51 6 Experimentation 52 6.1 Driftdetector............................. 52 6.1.1 TestLogs ........................... 52 6.1.2 Results Single Adwin . . . . . . . . . . . . . . . . . . . . . 53 6.1.3 False drifts with single Adwin . . . . . . . . . . . . . . . . 56 6.1.4 Results Multiple Adwin . . . . . . . . . . . . . . . . . . . 57 6.1.5 False drifts with multiple Adwin . . . . . . . . . . . . . . 58 6.2 Driftdetectorweb .......................... 59 6.2.1 TestWebsite ......................... 59 6.3 ModelGenerator ........................... 64 6.3.1 TestModel .......................... 65 7 Conclusions & future work 67 7.1 Personal Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . 67 7.2 FutureWork ............................. 68 8 Cost Study 70 9 Appendix 73 A Libraries Used 73 A.1 ParmaPolyhedra........................... 73 A.1.1 Convex Polyhedron . . . . . . . . . . . . . . . . . . . . . . 73 A.1.2 Octagons ........................... 74 6 A.2 AdwinMethods............................ 74 A.3 Swig.................................. 75 A.3.1 Example of Swig usage . . . . . . . . . . . . . . . . . . . . 76 A.4 PythonSnakes ............................ 78 A.4.1 Example............................ 78 A.5 Flask.................................. 79 A.5.1 Example............................ 79 A.6 JQuery ................................ 79 A.6.1 Examples ........................... 80 B Instructions 81 C Drift Detector Python 82 D Example of a PNML file 90 7 1 Introduction The development process for information systems starts by having a set of requirements that the final implementation must cover. Then the design of the system starts, and a formal model is built in order to specify each one of the components of the system. This can be done using formal languages such as UML. The programmers that write the implementation use that model to guide the development of the system. The process does not stop there, usually a system is modified a lot of times after it’s first implementation. This can be to fix bugs of the first iteration, or to add new functionalities to the system. The problem here is that during one of this iterations an unexpected and unwanted change could happen to the system, where the programmers inadvertently changed something in the system that makes it differ from the original specification. This kind of changes could be very hard to detect in some cases, and they have to be detected as soon as possible since the system is not doing what it is supposed to do. In this project we will explain how to detect this changes quickly and in an automatic way. The tools used are part of a discipline called Process Mining. A set of algorithms are going to be used to reach this goal and an implementation of those algorithms will be provided. 1.1 Process Mining Process mining is a recent discipline. It has two main components, the first one sits between data mining and computational intelligence, and the second one is centered in process modeling and analysis. The main idea of process mining is to analyze and discover processes. The information extracted from it can be used to improve the analyzed process. The information to do such things is 9 the events in order, separated in traces. The order of can be extracted from the time of each event. A trace is a list of this ordered events, where the first event is the start of the interaction of a user with the system, and the last event is the ending of this interaction. A simple example of processed log can be: •OpenGame ChooseLevel1 Play Win CloseGame •OpenGame ChooseLevel2 Play Lose CloseGame •OpenGame ChooseLevel2 Play Win ChooseLevel3 Play Lose CloseGame •... This is an example of a preprocessed log of a generic game. 2.2 Parikh Vectors Definition 1 (Parikh vector).Given a trace σ∈ {t1, t2, ..., tn}∗, the Parikh vector of σis defined as ˆσ= (#(σ, t1),#(σ, t2), ..., #(σ, tn)). From each trace σof size nin a log, we can extract nprefixes. We can then use each of the prefixes to obtain a Parikh vector. To do so we need to convert each event into a dimension(a position in the vector). For example, from the trace OpenGame ChooseLevel1 Play Win CloseGame It is possible to extract 6 prefixes • 16 •OpenGame •OpenGame ChooseLevel1 •OpenGame ChooseLevel1 Play •OpenGame ChooseLevel1 Play Win •OpenGame ChooseLevel1 Play Win CloseGame If this game has only 3 levels, a possible mapping from event to dimension can be: •Dimension 1: OpenGame 1 •Dimension 2: ChooseLevel1 •Dimension 3: ChooseLevel2 •Dimension 4: ChooseLevel3 •Dimension 5: Play •Dimension 6: Win •Dimension 7: Lose •Dimension 8: CloseGame Each Parikh vector represents a point in a multidimensional space. From each trace in a log it is possible to extract nsuch points, one for each prefix. Each point has the form ˆσ= (#(σ, t1),#(σ, t2), ..., #(σ, tn)). Then each Parikh vector of the prefixes stated before would be: •(0,0,0,0,0,0,0,0) •(1,0,0,0,0,0,0,0) 17 •(1,1,0,0,0,0,0,0) •(1,1,0,0,1,0,0,0) •(1,1,0,0,1,1,0,0) •(1,1,0,0,1,1,0,1) But also, each point can be seen as a polyhedron Pˆσ=Tn i=1(xi= #(σ, ti)). This means that for each prefix of a trace σthere exists a polyhedron that represents it. 2.3 Abstract Interpretation Abstract interpretation is useful to generate an approximated model of the data that is being analyzed. There are different ways to represent such an approximation. 18 12345 1 2 3 4 5 (0,0) (2,2) (3,5) x y Exact set 12 3 4 5 1 2 3 4 5 (0,0) (2,2) (3,5) x y Interval 12345 1 2 3 4 5 (0,0) (2,2) (3,5) x y Octagon 1 2 3 4 5 1 2 3 4 5 (0,0) (2,2) (3,5) x y Convex polyhedron Figure 3: Approximating a set of values with several abstract domains The difference between them is that they allow more or less values as part of the model, the area representing the model is bigger or smaller. A bigger area means that the model is going to contain more errors, since there are points outside the real model that are part of this approximation. In figure 3 you can see some of the possibilities. The one that fits the best is Convex polyhedron, as it has a smaller area than the others and still contains the points of the set. The problem is that a Polyhedron is more complex than the other representations, because more constraints are needed to define it. This is clear in table 1. 19 Interval Octagon Convex polyhedron 0≤x≤3 0 ≤x≤3y−x≥0 0≤y≤5 0 ≤y−x≤2 3x−y≤4 y−5/3x≤0 Table 1: Constraints (inequations) of the different models In this work the models used to represent the data (in this case is the behavior of the system) are two, Convex Polyhedron and Octagon. Basically the algorithm will use polyhedra whenever it’s possible and if the data is too complex then it will use octagons, so it doesn’t take too long to do the calculations. This is because is more difficult to obtain all the constraints that are needed to represent the polyhedron, and as the complexity of the system being analyzed grows, the number of constraints needed for the model that represent the system also grows. The are certain operations that can be done with Polyhedra and Octagons. In this Project we only need two: Meet(∩): Given convex polyhedra P and Q, their meet is the intersection P∩Q. Notice that this operation is exact, e.g., the meet or intersection of two convex polyhedra is always a convex polyhedron. PQ P∩Q Figure 4: Meet 20 Join(∪): Given convex polyhedra P and Q, we would like to compute the union of P and Q. Unfortunately the union of convex polyhedra is not necessarily a convex polyhedron. Therefore, the union of two convex polyhedra is approximated by the convex hull, the smallest convex polyhedron that includes both operands, denoted by P∪Q. The example on the left shows P∪in gray. P Q P∪Q Figure 5: Meet From a log we can extract a set of Parikh vectors. Each Parikh vector can represent a Polyhedron. Then we have a way to use Abstract interpretation to represent the log of the system. 2.4 Adaptive Windowing One of the most difficult problems in data and process mining is dealing with changes that happen in the data that is being analyzed. To mine or learn such data, one needs strategies for the following three tasks, at least: 1) detecting when change occurs 2) deciding which examples to keep and which ones to forget and 3) revising the current model when a significant change has been detected. The standard way of dealing with this is to keep a window with a portion of the data, normally you keep the most recent examples and drop the old ones. The contents of the window can be used for the three tasks above: 1) to detect change, 2) to obtain updated statistics from the recent examples, and 3) to have data to rebuild or revise the model. 21 Normally you have to choose the size of the sliding window, and you have to decide if you want a small window to have an accurate version of the current distribution, or if you want a large window to have more examples to work on and have more accuracy in stability periods. The importance of Adaptive Windowing is that the user does not have to specify a size for the window, the window will grow and shrink automatically to have a better representation of the distribution. In periods of stability the window becomes large, therefore obtaining accuracy, and if the distribution is changing the window becomes small to have a good representation of the last change of the distribution. 2.4.1 Adwin Adwin[2] is an implementation of adaptive windowing (ADaptive WINdowing). The algorithm has a sliding window that has a dynamic size, this means that the size is recomputed according to the rate of changes observed in the data of the window itself. If the data remains stable for a long period then the window will become large to have more precision, but if changes are taking place in the distribution of the data then the window shrinks so it’s able to discard old data. The creators of Adwin provide rigorous guarantees of performance as rates of false positives and false negatives. The algorithm is time and memory efficient. The input for the algorithm is a confidence value δ∈(0,1) and a (possibly infinite) sequence of real values x1, x2...xt..., where each xiis a real number between 0 and 1. Each xtis only available at time tand they are generated according to a distribution Dt. The fact that each xthas to be between 0 and 1 does not limit the algorithm since a simple rescaling is enough to be able to use it. Other values of the distribution such as µtor σ2 tare unknown for all t 22 Adwin 00011001010001001000100010101110101001010 00000000000000000000000000000010000000000 Adwin 1 0 Figure 6: Adwin Exampe 2.4.2 Overview of the ADWIN algorithm The algorithm keeps a window W and it keeps getting larger while µtremains constant in W. To check if this condition holds true the window is divided in two ”large enough” consecutive windows W0and W1. A value µWis calculated for each of the windows and when the difference between those to values is greater than a threshold, then the older part of the window W, W0is dropped. To decide the threshold for the difference or when a window is ”large enough” an appropriate distribution has to be chosen, so that the values are precise. This decision often involves the value δ. To get a more deep explanation of the algorithm and its proof look at [2]. 2.5 Petri Nets Definition 2 (Petri Net).A Petri net is a tuple (P,T,F,M0) where P and T represent finite sets of places and transitions, respectively, and F: (P×T)∪ (T×P)→Nis the weighted flow relation. The initial marking M0∈N|P| defines the initial state of the system. Petri nets are used to model a distributed system. The representation of a Petri net is a directed bipartite graph. There are two type of nodes in the graph, 23 there are nodes that represent places and nodes that represent transitions. Each node contains a number of tokens and each transition consumes tokens from n different places and produces tokes towards mdifferent places each time it is fired. A transition can never be fired if the required tokens are not available at a given time. The firing of a transition is atomic. If there are different transitions available then either of them can be fired, the order in this case is not defined and is representing parallel execution. Therefore they are well suited to represent concurrent distributed systems. This different kinds of nodes are connected by arcs, and depending on this arcs a transition gets tokens from a subset of places or puts tokens to other subset. Any given distribution of the tokens on the Petri net is called a marking. Example of a Petri Net: P1 T1 P2 P3 T2 P4 In this example we ca see 4 places (P1,P2,P3,P4) and 2 transitions (T1,T2). The arcs define the connection between them. The black balls inside each place represent the tokens. In this case we can see that P1 has 1 token, P2 has no tokens, P3 has 3 and P4 has 1 token. For T1 to be available (i.e. it is possible to fire T1) we need to have at least one token in P1, since there is an arc from P1 to T1 that represents the dependency. After T1 is executed P2 would have 1 token and P3 3 tokens, since there is an arc from T1 to P2 and to P3. 24 P1 T1 P2 P3 T2 P4 At the beginning it was only possible to fire T1 since T2 didn’t have all the tokens to be fired. Now, after firing T1 its possible to fire T2 since the tokens are now available. We can use this kind of modeling to represent the systems that are being analyzed. Part of the project is simple program that uses the Abstract Interpretation model as a source to generate a Petri Net. 25 until the end of it is found, then it goes to the next one. This loop works great for websites, because the logs here are asynchronous, so while you wait until one log gets more traces you can work with other logs. You could also have an instance of the algorithm program for each log, but then with a lot of websites the amount of memory needed to have all the models at once would be a lot. 3.6 Model generator In this project the main work is the concept drift detection algorithm, but there is also a small algorithm[4] for the process discovery part in process mining. This algorithm generates a more complete model from the abstract interpretation model of the drift detection algorithm. The model generated is a Petri net. Petri net are a really useful way to represent systems. It’s easy to have concurrent and distributed systems written as a Petri net. The information extracted from the abstract interpretation model comes from the constraints of each model. From each constraint you can generate a place, you can know the number of tokens needed from each place and the distance between the transition and the places. Not all the information that can be extracted from this is useful, and then we have to deal with a lot of not relevant information inside the model. To improve this, the algorithm filters the constraints that are not important for the final model, and uses only the important information. For each constraint of the abstract interpretation model a transition is created. Each constraint is an inequation, for example: e1−3e2+ 2e5≤3 If we split the coefficients into positive and negative coefficients, constraint 32 ican be represented in the following way: P aij >0 aijxj+P aij <0 aijxj≤bi that can be transformed into: P aij >0 aijxj−bi≤P aij <0 −aijxj A constraint iis a causality constraint if the following conditions hold: •There is at least one positive coefficient, and •bi ≤0 Hence causality constraints can be described as: P aij >0 aijxj−ci≤P aij <0 −aijxj with ci=bi≥0. The intuition behind causality constraints is that they represent real causalities observed in the log which can be explicit in the derivedPN. Hence if we assume indexes n1, ..., nkrange over the indexes of variables with negative coefficients and p1, ..., plrange over the variables with positive coefficients, it can be modeled in a PN as: T1 T2 P1 T3 T4 . . .. . . ci ain1aink aip1aipk where ciinside the place denotes citokens, and aij in an arc represents the weighted flow relation F for the arc. 33 4 Design & Specification 4.1 Goals of the project The goal of this project is to have a functional implementation of the online drift detection algorithm, with it’s web version. Also, an implementation of the model generator algorithm will be written to, which can be used to generate the models for the system both after and before a drift. The requirements are: •A program or script that can create a model from a log, do an estimation of this model and then monitor it until it finds a drift in the log •A web client that can send events to a server to create new logs •A web server that stores the events from each user of each website being tracked, and then creates a big log merging all the finished traces. This web server must be able to call the program or script that detects drifts to search for them in the new created logs. •An implementation of the model creator algorithm that can be used for the web or normal version of the drift detector algorithm. It has to create valid Petri nets from the abstract interpretation model used in the drift detection algorithm. Decisions: •For creating the abstract interpretation model the PPL library will be used. This library offers all the operations needed to work with polyhedrons and octagons, that are the models which will represent the system. 34 •Adwin will be used to detect a drift from the distribution of binary values that represent which points are inside a model and which are not. Using this library there is no need to predefine the size of the window in which to check for changes and there is mathematic proof of it’s correctness. •To represent the final model, before and after a drift, Petri nets will be used. This allows the representation of concurrent and distributed systems. 35 4.2 System Overview Online Drift Detection Algorithm Parma Polyhedra Library Model Generator Model AdwinFile Adwin Petri net kn Model Constraints [1...*] Petri net k1 ... System Log Main Use Read Write 36 This is the structure of the project. It all starts with the system being analyzed. This system generates a Log full of traces from the operations it does. The log is simply a file where there are multiple lines, each line representing a trace, and each trace contains 1 or more events. When a log is available then the Main program is executed. The main program is the one that coordinates the online drift detection algorithm with the model generator. This Main program starts by calling the drift detection algorithm, with the name of the log file. The drift detection algorithm then does as explained before. It creates a new model from the log, does the estimation and then starts monitoring. To create the new polyhedrons or check if a polyhedron is inside the other it uses the Parma Polyherda Library. The Parma Polyhedra Library has two files, one containing the model generated after the first step of the algorithm, and the other containing the constraints of the model. This files are generated using PPL functions. The drift detection algorithm also has one or more Adwin objects. It will have one in the simple version, and multiple Adwins in the version that check each constraint separately. Each Adwin object has a file where all the information is saved. This file is only created if the program has to be stopped, so it’s possible to resume it from the same point. The Main program has to wait until the drift detection algorithm finishes, and then it calls the Model generator to create a model of the new version of the system. To do so, the model generator reads the constraints created by PPL. This constraints represent the polyhedron used for the abstract interpretation and also can be used to extract a Petri net. The model generator then creates n different Petri nets, depending on the distance of the nodes. The most relevant one will be Petri net k1. 37 4.3 Online Drift Detection Algorithm This part of the program is the one that have all the logic to do the three steps of the drift detection algorithm. The functions are: setLogFile ( logPath ) i n i t i a l i z e ( ntraces , polyhedronFolder ) setMultipleAdwin( active) estimate ( preci s i on , npoints ) monitor() load ( polyhedronFolder ) save () The first function is to set the log file that will be analyzed. There are three functions representing each step of the algorithm, initialize, estimate and monitor. With that functions you can control the algorithm and change it’s parameters. There is also the function setMultipleAdwin that lets you change between the version with only one Adwin or the version with multiple Adwins. There are also the save and load functions, to save the state of the algorithm to disk. These functions will also call the save operations for each Adwin object used and for the polyhedron or octagon of PPL. 4.4 Model Generator The model generator can work independently of the other components, since it is not needed to check the log for drifts, and it doesn’t need to know when a drift has happened. However, it is useful to have the Petri net for each model, before and after a drift. This program only needs the constraints of the abstract interpretation model 38 as an input and then it generates a set of Petri nets. This is because a lot of the information extracted from the constraints is not really useful, and it makes the final Petri net harder to read. The separation in different Petri nets is basically depending on the number of tokens of each place. The places with only one token give much more information than the places with say 10 tokens. Each Petri net kn represents the constraints that define places with n tokens. 4.5 Main Module The program has a Main component that is in charge of doing the coordination between the other modules and is the one that starts and stops the algorithms. This is the program that the user is going to interact with, the user has to set up a log to be analyzed, the folder to keep all the files for the polyhedron and the Adwins. The folder for the Petri nets has to be specified here too. 39 4.6 Drift detector for websites Online Drift Detection Algorithm Parma Polyhedra Library Model Generator Model AdwinFile Adwin Petri net kn Model Constraints [1...*] Petri net k1 ... Log Main Use Read Write Web Logger Web Server Cron 40 The web version is almost the same as the other one, but with a few changes. To generate the log the web version needs traces representing the events that each user visiting a website has done. To get those traces we use a WebLogger that is executed in the computer of the users, in the browser. It has events such as the url that an user is visiting, or if they click some menu button. All that information is then sent to the main WebServer that sorts the events so each user has its own trace. After the trace of a user is complete it is added to the end of the main log of the website, the one that will be analyzed. The Main program is executed on a regular schedule, for example each hour, so it can process the data gathered during that time. Since the traces here may take a longer time to get to the main log this is a good approach so the program is not executing while it is not needed. The Main program here is also a bit different. When it starts it lists the folders from all the websites being tracked and when it finds some website with data in its log then it starts processing. If there is previous data to be loaded (Adwins and a model) then it loads it and continues as usual. In case there is no such data it waits until the log has at list the number of traces needed to initialize a polyhedron. If it’s not long enough it skips the folder and the same will be done on the next iteration. After the Main program finishes processing a Log it saves all the data again (Adwins and Model) so it can continue next time. All this information is saved in a folder structure, each website has the structure: / website log data/ model constraints 41 r e s u l t = heapq . heappop ( r e s u l t s ) d r i f t = adwins [ 0 ] . update ( r e s u l t [ 1 ] ) i f not drift : print ” (M) Estimation = ” + s t r ( adwins [ 0 ] . getEstimation ( ) ) + ” t race = ” + s t r ( totalTrace ) + erase r + ”\r ” , #p ri nt r e s u l t nextPoint += 1 pool sema . r e l e a s e ( ) def monitorMultipleDrift(contained ): global nextPoint , d r i f t , monTrace , er ase r , r e s u l t s , t ot al Tra ce heapq . heappush ( r e s u l t s , co ntained ) while len ( r e s u l t s ) >0and r e s u l t s [ 0 ] [ 0 ] == nextPoint and not drift : r e s u l t = heapq . heappop ( r e s u l t s ) d r i f t s = [ ] d r i f t = False for iin range ( len ( r e s u l t [ 1 ] ) ) : d r i f t s . append ( adwins [ i ] . update ( r e s u l t [ 1 ] [ i ] ) ) i f d r i f t s [ i ] : d r i f t = True i f not drift : print ” (M) Estimation = Multiple t ra ce = ” + s t r ( totalTrace ) + e ra s e r + ”\r ” , #p ri nt r e s u l t nextPoint += 1 pool sema . r e l e a s e () 48 This functions order the results and the check for a drift. This allows the algorithm to run faster in a multicore computer. The structure used here is very important since at the beginning of the project, multiprocessing was not a goal, but it was clear that it will be really useful to process a lot faster the logs. The code here is just a part of it but it gives the basic idea of how the parts are connected and how it is possible to calculate different results in parallel while keeping the final result the same. A lager version of the important bits of the code is attached in appendix C. 5.2 Model Generator This class uses a python library called snakes to generate the Petri nets. This library is able to export the Petri net to different formats, in this case the one used is PNML. A set of files .pnml are created, each one containing a different Petri net depending on the number of tokens on each place. This .pnml files can the be visualized using external programs or further analyzed with specialized tools. The model generator class has files dependencies also, since it reads the Model Constraints file generated by PPL. This is not a problem though, the file generated by PPL is a simple text file containing one dependency inequation per line, so no special treatment is required. 5.3 Main The Main file is the one in charge of executing each algorithm, control them and set the folders for the log file and for the outputs of the algorithms. There are two different Main files, one for analyzing an information system and another one for websites. The first one only has a few lines to set the parameters and execute each 49 step of the drift detection algorithm. After each drift it restarts the algorithm and creates a Petri model of the system after each initialization. The web version is called by Cron, and it iterates over different folders containing the logs of different websites. It first updates the website log by adding the new finished traces that were added since the last execution. After that it tries to load the model of the system and continue the execution until it reaches the end of the log. In case that a model does not exist it will wait until there are enough traces to create a new model, and then begin the initialization. 5.4 WebServer The web server is programmed in python.Flask is used in order to create an HTTP service to receive the traces of each user visiting the websites being analyzed. Since the requests are crossdomain requests, a special decorator is needed in Flask so it allows requests that are not from the same domain of the server itself. 5.5 WebClient The webclient is a simple javascript file that uses JQuery[5] to detect some events that the user visiting the webpage triggers. This events can be clicks in specific parts of the webpage or also the event of leaving the webpage. This script also detects the url that the user is visiting and sends that too. Depending on the type of webpage that is being analyzed, this kind of event can be too descriptive and may not be a good event at all, but the server is the one that decide which events to use and which not to. 50 6 Experimentation In this section there is the description and results of the experiments done for each of the modules developed in this project. Those modules are the drift detection algorithm module and the model generator module.The experiments will be centered in each one separately, since the results are independent. Since there are two versions of the drift detection algorithm, one for analyzing information systems and another one for websites, there are also two sets of experiments. The first set of experiments is for the single information system version. The execution of this tests are simpler since only require one computer and the system analyzed is local. 6.1 Drift detector The aim of these tests is to see how well the algorithm perform. What the experiments will try to find is: •Is the algorithm able to detect drifts? •How much time does the algorithm need? •How many false positives does it find? 6.1.1 Test Logs For this experiments there are a group of logs, each one with a different set of events and a different length for each trace. For each of these logs a set of changes are made. •rem: Remove some events in a set of traces 51 •conc: Some events that where sequential now are concurrent. •conf: A conflict is created between events that were sequential before. •switch: There are switched events from different traces. The experiments will try to answer the questions stated before for each pair of log and change. 6.1.2 Results Single Adwin Normal Log Log with a change Test Log Figure 11: Concatenation of logs The first test will be done using only one adwin.For this test the logs will be the concatenation of the normal log and the log with changes. For each log there will be 4 concatenations, one for each change of the ones described above. The result will be if the algorithm is able to detect a change and if a drift is detected how many traces were needed to detect it. Being L the number of traces in the log and N the average number of events per line, the initialization of the model is set to L/4 traces, and the stabilizations is set to a precision of 0.01 and a number of points of (L/8)*N 52 log conc conf rem switch a12f0n00 - 31 39 48 a22f0n00 38 22 28 62 a32f0n00 74 86 40 78 a42f0n00 - 63 75 - cycles4 2 x x x x cycles5 2 x x x x kmg8 2 88 92 91 99 kmg9 2 98 98 97 - prodcons8 5 5 x x x x prodcons9 6 6 x x x x sharedres6 3 25 - 19 40 sharedres8 5 77 51 54 57 t32f0n00 - x x x - Means no drift x Means no stabilization In this results there are cases where the drift was detected quickly and some other cases where it couldn’t detect the drift. This is because in those logs the stabilization took too long and the end of the file was reached before having a good estimation. Some other times the estimations was done with only a few traces left of log, and there was not enough traces to detect a drift. If the parameters of the algorithm are readjusted to let the algorithm stabilize faster then the result obtained is: 53 log conc conf rem switch a12f0n00 20 31 39 48 a22f0n00 38 22 28 62 a32f0n00 74 86 40 78 a42f0n00 66 63 75 80 cycles4 2 78 79 85 92 cycles5 2 79 82 88 99 kmg8 2 88 92 91 99 kmg9 2 85 87 89 95 prodcons8 5 5 82 85 90 93 prodcons9 6 6 79 83 91 95 sharedres6 3 25 27 19 40 sharedres8 5 77 51 54 57 t32f0n00 77 88 92 92 The main conclusion here is that the parameters depend on the type of log that is being analyzed, and a single small change can be really important in order to obtain good results. To obtain this improved results the logs with problems were analyzed by hand trying to see the difference. For example some logs had more variability than others, then a good value to change is the precision of the estimation. Some others had drifts that were not very drastic, and then a good way to detect them is to increase the precision of the Adwin library. In order to analyze a system with the drift detection algorithm we first need to know some parameters of the system itself that can be learnt from the log. This parameters are the ones that describe how much an estimation change during time and how much the estimation change during a drift. Using those values the algorithm can be tuned to have a better performance for that specific system. 54 6.1.3 False drifts with single Adwin Normal Log False drift test Log Normal Log Figure 12: Concatenation of logs for false drift test In order to detect false drifts the same test will be done to the logs but this time concatenating the same log twice, without any changes. If a drift is detected then this will be considered a false drift in this case. log false drift a12f0n00 no a22f0n00 no a32f0n00 no a42f0n00 no cycles4 2 no cycles5 2 no kmg8 2 no kmg9 2 no prodcons8 5 5 no prodcons9 6 6 no sharedres6 3 no sharedres8 5 no t32f0n00 no 55 We can see in this results that the algorithm does not detect any false drift. 6.1.4 Results Multiple Adwin The first time the test were executed using multiple adwins a problem was found with the estimation. Since the estimation was considered stable once all the adwin objects were stable, the algorithm had a hard time stabilizing, and some times it wouldn’t stabilize at all. After realizing that some changes were done to the algorithm so not all of the adwins needed to be stable, but only a percentage of them. After that change the tests were executed again, obtaining this results. Being L the number of traces in the log and N the average number of events per line, the initialization of the model is set to L/4 lines, and the stabilizations is set to a precision of 0.01 and a number of points of (L/8)*N log conc conf rem switch a12f0n00 - 38 39 48 a22f0n00 20 12 17 31 a32f0n00 4 6 5 10 a42f0n00 18 16 29 15 cycles4 2 31 31 30 30 cycles5 2 44 44 - 71 kmg8 2 91 71 83 x kmg9 2 51 47 81 51 prodcons8 5 5 47 49 49 48 prodcons9 6 6 46 47 49 46 sharedres6 3 12 5 5 6 sharedres8 5 5 5 5 5 t32f0n00 17 19 16 16 56 We can see in the results that using multiple Adwins the drifts are detected, in average, faster than with only one Adwin. This is because having more Adwins the algorithm is more sensitive to subtle changes that only affect a small amount of the constraints. The algorithm performs a lot better using multiple Adwins. There are a lot less cases where the algorithm couldn’t find the drift here, and as before it is possible to do adjustments to the log in particular where there are problems. After such adjustments the results are: log conc conf rem switch a12f0n00 23 38 39 48 a22f0n00 20 12 17 31 a32f0n00 4 6 5 10 a42f0n00 18 16 29 15 cycles4 2 31 31 30 30 cycles5 2 44 44 53 71 kmg8 2 91 71 83 85 kmg9 2 51 47 81 51 prodcons8 5 5 47 49 49 48 prodcons9 6 6 46 47 49 46 sharedres6 3 12 5 5 6 sharedres8 5 5 5 5 5 t32f0n00 17 19 16 16 6.1.5 False drifts with multiple Adwin The same as before is done in order to detect false drifts, a concatenation of the log without changes. 57 6.3.1 Test Model The model used is the one from the log a12f0n00.tr. This is a simple model so it does not have a lot of constraints. The constraints of the model are: −A>=−1, I−J−L>= 0 , A−C−I>= 0 , L−M>= 0 , C−D>= 0 , J−K + M >= 0 , D−F>= 0 , J>= 0 , C−E>= 0 , A−B + C + D + E + F + G + I + J + K + L + M >= 0 , M>= 0 , E−G>= 0 , F−G>= 0 , B−C−D−E−F−G−H−I−J−K−L−M>= 0 , H>= 0 , G>= 0 , G−H + K >= 0 , K>= 0 . This is basically the input file for the model generator algorithm. Using this constraints it will create a Petri net that represents the system being analyzed, the one that created the log. The algorithm generates different files, each one with different constraints. In each file Petri-n a Petri net is represented where all the places have exactly n tokens. Since the input constraints all have 0 tokens, only one file is created where all places have 0 tokens. 64 This Petri net can be visualized with programs such as Woped. Figure 14: Petri net created by the model generator The file .pnml generated that represents this Petri net is in the appendix D, which was generated using the model generator from the constraints listed above. 65 7 Conclusions & future work Process mining is a fairly new discipline that is rapidly evolving and I think is a great moment to start making progress in it’s different areas. This work intends to add new tools to use for process mining, and also add a different point of view so it does not only works with local systems but also with a group of webpages. During this project tests we found out that the web version of the algorithm is not as useful as it seemed at first. However this does not mean that this work cannot be applied to that area, but it does mean that maybe there are some changes that have to be done first. There are also some really good results, we found out that the multiple Adwin version of the algorithm is a lot more precise and requires less adjustments in order to detect drifts. Overall, the goals of the project had been reached, the algorithms are all implemented and the new approaches that we wanted to try at first were also tested. There is still a long path ahead with a lot of room for improvement, but I hope that the work done here can add some information to direct the search to the right places. 7.1 Personal Conclusions Thanks to this project I learnt about Process Mining, a discipline that I didn’t even know before. The first I had to do was read papers about the research being done in this field, and it was my first contact with research reading too. I think Process Mining has a huge potential and a lot of room for improvement and new tools to be developed. It is something common nowadays to have a lot of system logs that are not being used, and being able to actually extract 66 useful information from them is really important. During my degree I never had a class that talked about Process Mining, and neither heard of it from other sources until my project director introduced me to it. I hope this document can help other students to discover this discipline. Thanks to this project I learnt new algorithms, which is always really useful since it means I have some new ways of thinking future problems I could encounter as a programmer. Also I added new tools to my toolbelt, just as swig, python-snakes, PPL... It has been a really enriching experience, and I hope it can offer the same experience to the people that read this document. 7.2 Future Work Since Process Mining is a big discipline, it will always have a lot of improvements that can be done to the current methods and algorithms used. This project is not an exception. All the algorithms and implementations described her can be improved. The drift detector algorithm can improve by finding new ways of detecting a drift (e.g. calculating the difference between centers of polyhedrons). It is also possible to automate more the values that now the user is responsible for (i.e. number of traces for the initialization, precision, etc). It is also possible to improve the current implementation to be a little bit faster in a multicore system. This implementation already uses multiple processes but it happens sometimes that one core has a little bit less work than others. The model generator algorithm can be improved so the Petri nets contain more useful information, by filtering states or transitions that are not really important. Also it will be useful to have the weights of each part of the Petri 67 net, since int can be the case that only one part of it is really used, and the other ones are just used once in a while. 68 8 Cost Study This project started in September of 2012. I spent the first two weeks reading about process mining and the drift detection algorithm. Then I also started reading the documentation of PPL to understand how the library works. I also had an example of usage of the Adwin library. After those few weeks learning how every tool I would use for the project worked, I started programming the first version of the algorithm. The coding started being only the algorithm in C++, since the libraries were in that language, but then it expanded to Python to integrate the tools with other environments. During the coding phase a Git repository was used to keep track of the changes. Month Work Hours September 2012 Read documentation 50h October 2012 50h November 2012 Implementation of the 30h December 2012 drift detection algorithm 30h January 2013 and model generation algorithm 100h February 2013 100h March 2013 Implementation of the web version 120h April 2013 Experiments 140h May 2013 and report 100h 720h Table 2: Time study Assuming that the price per hour is 30e, the total cost of the hours worked is 21.600e. 69 Tools used to develop the project: Software Cost Debian Wheezy Free Parma Polyhedra Library Free Adwin Free Swig Free Gummi Free Table 3: Software cost study The computer used for this project has a value of 700e. A cheaper computer could be used, but the experiments would have taken longer. This price is used only as a guide. Cost Hours of work 21.600e Sofware 0e Hardware 700e Table 4: Total cost 70 References [1] W. M. P. van der Aalst et al., “Process mining manifesto,” in Business Process Management Workshops (1), pp. 169–194, 2011. [2] A. Bifet and R. Gavald`a, “Learning from time-changing data with adaptive windowing,” in SDM, 2007. [3] J. Carmona and R. Gavald`a, “Online techniques for dealing with concept drift in process mining,” in IDA, pp. 90–102, 2012. [4] J. Carmona and J. Cortadella, “Process mining meets abstract interpretation,” in ECML/PKDD (1), pp. 184–199, 2010. [5] “Jquery.” http://jquery.com/. [6] T. Murata, “Petri nets: Properties, analysis and applications,” Proceedings of the IEEE, vol. 77, pp. 541–574, Apr. 1989. [7] “Parma polyhedra library.” http://bugseng.com/products/ppl/. [8] “Swig.” http://www.swig.org. [9] “Python-snakes.” https://code.google.com/p/python-snakes. [10] “Flask.” http://flask.pocoo.org/. 71 9 Appendix A Libraries Used A.1 Parma Polyhedra Parma Polyhedra Library(PPL)[7] is a library for working with multidimensional objects such as Convex Polyhedrons and Octagons. This is the library in which all the abstract interpretation is based. It has interfaces for different languages, but in this work the one used is the C++ one. It also has different versions, some of them are in linux distribution repositories, and you can build the last version from the source code that is available in the website. Since the changes in the last versions don’t affect the work that is being done here, the version used is the one in Debian testing (wheezy) repositories. The version is libppl0.11-dev. The implementation of the algorithm uses both Convex Polyhedron and Octagon from this library. They are pretty similar, the difference is the one stated in section 2.3. The operations needed for the algorithm to work are available in both models. A.1.1 Convex Polyhedron Convex polyhedrons are the implementation of multidimensional polyhedrons in the Parma Polyhedra Library. This implementation allows the creation of new polyhedrons, specifying all it’s coordinates, and also allow the merging of two polyhedrons, doing the convex hull of them both. The implementation of the drift detection algorithm also uses another function to know whether a polyhedron is inside another polyhedron or not. This are the only operations used from this model. The problem is that with complex logs doing the convex 72 hull takes too long, and online analysis becomes unfeasible under that circumstances. When this happens the algorithm uses Octagons, since the calculations are faster than with polyhedrons A.1.2 Octagons Octagons are the implementation of multidimensional octagons in the Parma Polyhedra Library. The operations used by the drift detector algorithm are almost the same as in the case of polyhedrons, the only difference is that they defer in name. With this model you can create new octagons giving the full coordinates of the octagon, and you can merge two octagons into one. There is also a function to know whether an octagon is inside another octagon or not. Since the calculations are faster than with polyhedrons, octagons allow the algorithm to work online even in hard cases where it cannot do it with polyhedrons. The drawback in this case is the precision, since octagons will have a bigger area as a representation of the model. This means that there will be cases where polyhedrons would have detected drifts but octagons fail to do so. A.2 Adwin Methods Adwin( int M ) ; double getEstimation () const ; bool update ( const double &value ) ; void save ( std : : s t r i n g path ) const ; void load ( std : : s t r i n g path ) ; The first one is to initialize the Adwin object with a number of maximum buckets. 73 $ ( ”#weather−temp” ) . html ( ”<strong >” + data + ”</ strong>degrees ” ) ; } }) ; B Instructions First you need to prepare the environment to use the project. You need: •Python 2.6 •Flask •python-snakes •libppl •Swig •g++ •make Using the repository of your linux distribution you should be able to download most of them, the only one that wasn’t in my Debian repository was pythonsnakes. To download it you should go to https://code.google.com/p/pythonsnakes/ Once you have all the tools, you should compile the files under driftdetector. There is Makefile available, so you only have to do make in that folder.After that you only have to set the file to analyze in the pddMain.py file. 80 To use the web version you need to start the server first. Go to the server folder and run ”python server.py”. You may need to open your ports if you want to use the server from outside your local network. Then the server is ready to receive new traces. To use the javascript client add the logger.js and jquery library under the a js/ folder and paste this code in the website you want to analyze: <!−− driftDetector code −−> <s c r i p t type=”te xt / j a v a s c r i p t”> var t rac king code = ”somecode” </script > <s c r i p t type=”te xt / j a v a s c r i p t ” s r c=”j s / jquery −1.8.3. min . j s”></script > <s c r i p t type=”te xt / j a v a s c r i p t ” s r c=”j s / l og g er . j s ”></ script > <!−− end of driftDetector code −−> C Drift Detector Python def evalPoint ( point , npoint ) : global dd , ndim parikh = d r i f t d e t e c t o r . VectorInt (ndim , 0) for iin range ( len ( point ) ) : parikh [ i ] = point [ i ] contained = dd . modelContains ( parikh ) return ( npoint , contained ) def evalPointConstraints ( point , npoint ) : 81 contained = ev alC onstraints ( point ) return ( npoint , contained ) def evalConst rai nts ( point ) : global constraints res = [ ] for constraint in constraints : val = 0 for iin range ( len ( point ) ) : val = val + point [ i ] ∗c o n s t r a i n t [ i ] i f val <constraint [ len ( constraint ) −1]: res . append ( False ) else : res . append ( True ) return res def updateEstimation ( contained ) : global nextPoint , estTrace , eraser , estStable , r e s u l t s , total Tr ac e , adwins , es tim ati ons , acceptedError , wantedStable heapq . heappush ( r e s u l t s , co ntained ) while len ( r e s u l t s ) >0and r e s u l t s [ 0 ] [ 0 ] == nextPoint and not estStable : r e s u l t = heapq . heappop ( r e s u l t s ) adwins [ 0 ] . update ( r e s u l t [ 1 ] ) estimation = adwins [ 0 ] . getEstimation ( ) i f estimations [0] != −1and math . fabs ( est imation s [0] −estimation) <= acceptedError : 82 currentStable [0] += 1 else : currentStable [0] = 1 estima tions [ 0 ] = estimation estStable = ( currentStabl e [ 0 ] >= wantedStable) print ” (E) Estimation = ” + s t r ( estimation ) + ” tra ce = ” + s t r ( to talTrace ) + ” ( ”+s t r ( currentStabl e [ 0 ] )+” ) ” +e ra s e r + ”\r ” , #p ri nt r e s u l t nextPoint += 1 pool sema . r e l e a s e () def updateMultipleEstimation ( contained ) : global nextPoint , estTrace , eraser , estStable , r e s u l t s , total Tr ac e , adwins , es tim ati ons , acceptedError , wantedStable heapq . heappush ( r e s u l t s , co ntained ) while len ( r e s u l t s ) >0and r e s u l t s [ 0 ] [ 0 ] == nextPoint and not estStable : r e s u l t = heapq . heappop ( r e s u l t s ) stableAux = True countStable = 0 for iin range ( len ( r e s u l t [ 1 ] ) ) : adwins [ i ] . update ( r e s u l t [ 1 ] [ i ] ) estimation = adwins [ i ] . getEstimation () i f estimations [ i ] != −1and math . fabs ( estimations [ i ] −estimation) <= acceptedError : currentStable [ i ] += 1 83 else : currentStable [ i ] = 1 estima tions [ i ] = estimation i f not (currentStable [ i ] >= wantedStable) : stableAux = False else : countStable += 1 i f f l o a t ( countStable ) / f l o a t ( len ( r e s u l t [ 1 ] ) ) < 0.8: estStable = False else : estStable = True print ” (E) Estimation = M ultiple t ra ce = ” + s t r ( totalTrace ) + e ra s e r + ”\r ” , #p ri nt r e s u l t nextPoint += 1 pool sema . r e l e a s e () def monitorDrift ( contained ) : global nextPoint , d r i f t , monTrace , e ras er , r e s u l t s , totalTrace heapq . heappush ( r e s u l t s , co ntained ) while len ( r e s u l t s ) >0and r e s u l t s [ 0 ] [ 0 ] == nextPoint and not drift : r e s u l t = heapq . heappop ( r e s u l t s ) d r i f t = adwins [ 0 ] . update ( r e s u l t [ 1 ] ) i f not drift : print ” (M) Estimation = ” + s t r ( adwins [ 0 ] . getEstimation ( ) ) + ” t rac e = ” + s t r ( 84 totalTrace ) + e ra s e r + ”\r ” , #p ri nt r e s u l t nextPoint += 1 pool sema . r e l e a s e () def monitorMultipleDrift(contained): global nextPoint , d r i f t , monTrace , e ras er , r e s u l t s , totalTrace heapq . heappush ( r e s u l t s , co ntained ) while len ( r e s u l t s ) >0and r e s u l t s [ 0 ] [ 0 ] == nextPoint and not drift : r e s u l t = heapq . heappop ( r e s u l t s ) d r i f t s = [ ] d r i f t = False for iin range ( len ( r e s u l t [ 1 ] ) ) : d r i f t s . append ( adwins [ i ] . update ( r e s u l t [ 1 ] [ i ] ) ) i f d r i f t s [ i ] : d r i f t = True i f not drift : print ” (M) Estimation = Multiple t ra ce = ” + s t r ( totalTrace ) + e ra s e r + ”\r ” , #p ri nt r e s u l t nextPoint += 1 pool sema . r e l e a s e () def i n i t i a l i z e ( traces , f o l d e r ) : global ndim , dimensions , dd , baseFolder , totalTrace totalTrace = 0 85 i f ( f o l d e r [ le n ( f o l d e r ) −1 ] != ”/” ) : f o l d e r += ”/” baseFolder = f o l d e r dd = d r i f t d e t e c t o r . d r i f t D e t e c t o r ( ) #Cal cul ate Dimensions dimensions = dic t () nextDim = 0 log = [ ] for iin range ( trac e s ) : tra ce = readTrace () log . append ( t race ) for jin range ( len ( trac e ) ) : i f not trace [ j ] in dimensions : dimensions [ trace [ j ] ] = nextDim nextDim += 1 ndim = len ( dimensions ) dd . createModel ( ndim ) #I n ser t n u l l p r e f i x only once n ul lP re fi x = d r i f t d e t e c t o r . VectorInt (ndim , 0) dd . i ns e rt Pa rik h ( n u l l P r e f i x ) #I n se r t parikh vectors for iin range ( len ( log ) ) : parikh = d r i f t d e t e c t o r . VectorInt (ndim , 0) for jin range ( len ( log [ i ] ) ) : dimIndex = dimensions [ log [ i ] [ j ] ] parikh [ dimIndex ] += 1 dd . inser tPari kh ( parikh ) def estimate ( vacceptedError , vwantedStable ) : 86 global p , estTrace , estStable , pool sema , dimensions , madwin , wantedStable , currentStable , acceptedError p = Pool ( nthreads ) acceptedError = vacceptedError wantedStable = vwantedStable tra ce = readTrace () npoint = 1 estTrace = 1 estStable = False setMultipleAdwin(madwin) print ” I n i t Estimation : ” while tra ce != [ ’ ’ ] and not estStable : parikh = [ 0 ] ∗ndim for event in tra ce : pool sema . acquire () i f not estStable : dimIndex = dimensions [ event ] parikh [ dimIndex ] += 1 i f madwin : p . apply async ( evalPointConstraints , args=( l i s t ( parikh ) , npoint ) , call b ack= updateMultipleEstimation) else : p . apply async ( evalPoint , args=( l i s t ( parikh ) , npoint ) , call b ack= updateEstimation) npoint += 1 else : 87 pool sema . r e l e a s e () tra ce = readTrace () estTrace += 1 p . c l o s e ( ) p . j o i n ( ) i f estStable : i f madwin : print ”\nEstimation done , tr ac e = ” + s t r ( totalTrace) else : print ”\nEstimation done , s t ab l e at ” + s t r ( adwins [ 0 ] . getEstimation ( ) ) + ” t race = ” + str(totalTrace) else : print ”\nThe estimation didn ’ t s t a b i l i z e ” def monitor ( ) : global p , d r i f t , monTrace , pool sema , nextPoint , r e s u l t s , madwin , dimensions p = Pool ( nthreads ) tra ce = readTrace () npoint = 1 d r i f t = False monTrace = 1 nextPoint = 1 r e s u l t s = [ ] print ” I n i t Monitoring : ” while tra ce != [ ’ ’ ] and not drift : parikh = [ 0 ] ∗ndim 88 for event in tra ce : pool sema . acquire () i f not drift : dimIndex = dimensions [ event ] parikh [ dimIndex ] += 1 i f madwin : p . apply async ( evalPointConstraints , args=( l i s t ( parikh ) , npoint ) , call b ack= monitorMultipleDrift) else : p . apply async ( evalPoint , args=( l i s t ( parikh ) , npoint ) , call b ack= monitorDrift) npoint += 1 else : pool sema . r e l e a s e () tra ce = readTrace () monTrace += 1 p . c l o s e ( ) p . j o i n ( ) i f drift : print ”\nD rift d etec ted at t ra ce ” + s t r ( totalTrace) else : print ”\nNo d r i f t detected ” D Example of a PNML file <?xml version=” 1.0 ” encoding=” utf −8”?> 89