# CvAMoS--Event Abstraction Using Contextual Information
## 4 Approach
### Step 2: Replacement of the Motifs in the Event Log  
Once obtained a list of verified motifs, i.e., a list of candidate motifs that fulfill the requirements of the parameter provided such as distances, quorum, cost, and attribute maps, they can be replaced in the event log. The replacement of the motifs allows the abstraction of the events in the log into more abstract structures. Each motif can be labeledwith an activity name. In order to replace a verified motif, we need to check all the instances of the motif inside the traces (still considering the distances, the cost relation, and the attribute map). Once the instance is identified and verified, it is replaced by the abstracted activity label. A simplified version of the algorithm is reported in Algorithm 2. Please note that the index handling in line 8 is simplified for space reasons, but should handle the case of multiple motifs on the same trace as well as multiple instances of one motif on the same trace.  
Additionally, in this case, the algorithm has linear complexity, given by the number of events in the event log multiplied by the size of the set of verified motifs. The complexity of this algorithm can be considered acceptable for offline processing of the data. The current implementation of CvAMoS allows saving the abstracted event log as an XES file.  
```
Input:\(E_{L}\): the original event log \(M\): a set of verified motifs \(d_{act}\), \(d_{attr}\): the max distance values \(cost_{act}\): the activity cost relation \(\mathcal{R}\): the attribute map \(\mathit{abs}\): the name of the activity to abstract Output: the log with the motifs \(M\) replaced
1 Define \(E^{\prime}_{L}\) as empty multiset
2 foreach\(c\in\mathit{C}\)do
3 foreach\(t\in E_{L}\)do
4\(t^{\prime}\gets t\)\(\triangleright\) A copy of the original trace is acquired foreach\(i\in[1,|t|-|c|]\)do
5 if\(dist_{act}(t[i,|c|],c,cost)\leq d_{act}\)and \(dist_{att}(t[i,|c|],c,\mathcal{R})\leq d_{attr}\)then
6\(t^{\prime}\gets t^{\prime}[0,t]\cdot\langle abs\rangle\cdot t^{\prime}[i+| c|,|t|-i-|c|]\)\(\triangleright\) Replace the events of the verified motif with the activity axis. Actual indexes should handle multiple motifs on the same trace, omitted here for simplicity
7\(E^{\prime}_{L}\gets E^{\prime}_{L}\cup\{t^{\prime}\}\)\(\triangleright\) The union of multiset is applied in this context, i.e., if the element is already in \(E^{\prime}_{L}\), then frequency incremented
8 return\(E^{\prime}_{L}\)
```  
**Algorithm 2**Replacement of verified motifs.  
To recap, CvAMoS is an event abstraction technique able to handle contextual variables during the identification of the motifs. A motif is a recurrent pattern inside the event log and it is composed of a list of events and a list of attributes that characterize the execution. The procedure for the identification of the motifs takes into account several parameters provided by the user. The parameters include a maximum distance value for the activities, a maximum distance value for the attributes, a cost map to define the interchange cost between activities, an attribute map to define the aggregation operator and the tolerance value for the attributes, and a quorum value. The approach first derives a set of candidate motifs starting from the observed sub-traces. Each sub-trace is then verified and eventually returned as a verified motif. The verified motif can be labeled and replaced in the event log. In this last phase, the instantiation of each motif is verified in the traces and, when found, it is replaced with the activity label.