# CvAMoS--Event Abstraction Using Contextual Information
## 4 Approach
### Step 1: Construction of the Set of Motifs
The motif must appear in a given percentage of traces (quorum), up to a certain dissimilarity (distance), according to the interchangeability relations provided by the user (costs), and according to the context defined by the attributes. The activity cost is a relation indicating the similarity (or dissimilarity) between pairs of activities: the cost value can be used to indicate whether two activities can be performed interchangeably or not (i.e., whether one is an acceptable replacement of the other). **Definition 8** (Activity Cost Relation). : _The relation \(cost_{act}:\mathcal{A}\times\mathcal{A}\rightarrow[0,1]\) indicates the extent of the interchangeability of two activities. For example, given two activities \(a_{1},a_{2}\in\mathcal{A}\) if \(cost_{act}(a_{1},a_{2})\) is close to 0, then \(a_{1}\) and \(a_{2}\) are interchangeable (i.e., they are equivalent); if the value is close to 1 it means they are not._  
The _cost_ relation is expected to be provided by the user since it is heavily domain dependent. If the user does not specify a cost for a certain pair of activities, a cost of 1 is assumed. The capability of setting activity costs is particularly relevant every time an activity is mapped by, for example, two proximity sensors that are physically very close to each other. In this setting, these will usually be triggered simultaneously and therefore could be considered interchangeable. Another example of how this concept can be applied is to consider two activities that are completely unrelated and cannot be performed in the same context. In this case, it would be appropriate to assign a cost value close to 1 to reflect that these activities cannot be interchanged. The cost relation is used to compute the distance. The distance function quantifies the similarity between two traces. The distance is firstly computed in terms of activities and then in terms of attributes. The activity distance can be defined as follows:  
**Definition 9** (Activity distance). : _Given two traces \(t_{1}\) and \(t_{2}\) with the same length (i.e., \(|t_{1}|=|t_{2}|\)) and given the \(cost_{act}\) relation, the activity distance between \(t_{1}\) and \(t_{2}\) is defined as the sum of the costs for each pair of activities of the respective traces:_  
\[dist_{act}(t_{1},t_{2},cost_{act})=\sum_{i=0}^{|t_{1}|}cost_{act}(t_{1}(i),t_{ 2}(i)).\]To check the similarity between the activities in the motif and the activities in the subtrace, CvAMoS implements the Hamming distance as a distance function, by computing the number of positions at which the corresponding activities are different. The cost map is used by this function to evaluate the similarity. The activity distance tackles the problem of the variability of the behaviors, meaning that there could be a slightly different configuration in how the same behavior appears in different instances, and this difference is tolerated by the distance. If the activity distance is within an acceptable threshold, the attribute distance is checked. **Definition 10** (Attribute Distance). : _Given two traces \(t_{1}\) and \(t_{2}\) and given an attribute map \(\mathcal{R}:\mathcal{N}\rightarrow(\mathcal{O},\sigma)\). Let us call \(o(n,t)\) with \(o\in\mathcal{O}\) and \(n\in\mathcal{N}\) the application of operator \(o\) on the attribute values names \(n\) of trace \(t\). The attribute distance between the two traces is defined as:_  
\[dist_{attr}(t_{1},t_{2},\mathcal{R})=\sum\{|\mathcal{R}^{n}_{\mathcal{O}}(n,t_ {1})-\mathcal{R}^{n}_{\mathcal{O}}(n,t_{2})|\ |\ \forall n\in\mathcal{R}_{\mathcal{N}} \cdot|\mathcal{R}^{n}_{\mathcal{O}}(n,t_{1})-\mathcal{R}^{n}_{\mathcal{O}}(n,t_{2})|>\mathcal{R}^{n}_{\sigma}\} \tag{1}\]  
The attribute distance between two traces is calculated by comparing the values of their set of attributes, and quantifying the difference between these values. To simplify, the distance between two attribute values, sharing the same attribute name, is computed as the absolute difference between these values, but considering the maximum approximation tolerance.