# Boosting the Learning for Ranking Patterns
## 4 AHP-Based Learning Approach for Ranking Patterns
### AHPRank Algorithm  
We propose Algorithm 2 to implement the AHPRank function (Algorithm 1) to learn a weight vector in a passive/active mode. The algorithm takes as input a set of measures \(\mathcal{M}\), a set of user-ranked patterns \(\mathcal{S}\), and a triplet of parameters \(\langle\mathcal{P},\theta,T\rangle\). Here, \(\mathcal{P}\) is a collection of patterns, \(\theta\) is a sample parameter used in the query generator for active learning, and \(T\) is the maximum number of iterations used as a stopping criterion in the algorithm. AHPRank initializes the vector of pair comparisons to zero in line 1. If AHPRank is called with a non-empty \(\mathcal{S}\), it runs in passive mode by calling the learnWeights function on the given user-ranked patterns \(\mathcal{S}\) (lines 3-6). This produces a weight vector \(w\). Otherwise, it runs in active mode by submitting \(T\) queries to the user (lines 7-15). In the active mode, the user is asked to rank a subset of patterns proposed by a query generator. Our query generator is based on a heuristic that exploits the quality of the weights learned from the previous iterations. The active learning mode follows the following iterative steps:  
1. As a first step, a subset of patterns is sampled from the global set of patterns \(\mathcal{P}\) using a random sampling approach. At line 10, the function SamplePatterns is called, which returns a sample \(\mathcal{P}^{\prime}\) of \(\theta\) patterns. 2. The SensitivityBasedHeuristic function is used to select a pair of patterns. This heuristic is designed to select a high-quality pair of patterns to accelerate the convergence of the learning process (see Algorithm 3 in Section 4.5 for details). 3. Interacting with the user obtains feedback through a ranking query (line 12). 4. AHP-based learning of the user ranking function is performed by calling the learnWeights function on the user-provided ranking query (line 13). The proposed method is designed to handle large sets of patterns, which can be computationally expensive to process. To address this issue, we introduce two steps in the active learning mode. First, we randomly sample a subset of patterns from the global set \(\mathcal{P}\), which reduces the complexity of the second step as well as introduces a diversity factor. Second, we use a sensitivity-based heuristic to select pairs of patterns that are of high-quality and diverse. It is important to determine when to stop the learning process. Our method allows for a custom stopping criterion, but we also consider the case where a fixed number of iterations \(T\) is used. This simulates the scenario where the user can stop at any time based on their satisfaction with the learned ranking function. ```
1 foreach\(\Delta_{ij}\in\Delta\)do\(\Delta_{ij}\gets 0\);
2 if\(\mathcal{S}\
eq\emptyset\)then
3 foreach\(S_{k}\in\mathcal{S}\)do
4\(w^{t}\leftarrow\texttt{Learn weights}(\langle\Delta,k\rangle,S_{k},\mathcal{M})\) ; // Learn weights
5
6 end if
7
8 end for
9
10 else
11\(w^{0}\leftarrow\texttt{1}\) ; // Weight vector
12 for\(t=1,2\dots T\)do
13\(\mathcal{P}^{\prime}\leftarrow\texttt{SamplePatterns}(\mathcal{P},\theta)\) ; // Step 1
14\(Q_{t}\leftarrow\texttt{SensitivityBasedHeuristic}(\mathcal{P}^{\prime},w^{t-1}, \mathcal{M})\) ; // Step 2
15\(S_{t}^{*}\leftarrow\texttt{AskRanking}(Q_{t})\) ; // Step 3
16\(w^{t}\leftarrow\texttt{Learn weights}(\langle\Delta,t\rangle,S_{t}^{*}, \mathcal{M})\) ; // Step 4
17
18 end for
19
20 end for return\(w^{t}\)
```  
**Algorithm 2**\(\texttt{AHPRank}(\mathcal{M},\mathcal{S},\langle\mathcal{P},\theta,T\rangle)\). ```
1 foreach\(\Delta_{ij}\in\Delta\)do\(\Delta_{ij}\gets 0\);
2 if\(\mathcal{S}\
eq\emptyset\)then
3 foreach\(S_{k}\in\mathcal{S}\)do
4\(w^{t}\leftarrow\texttt{Learn weights}(\langle\Delta,k\rangle,S_{k},\mathcal{M})\) ; // Learn weights
5
6 end if
7
8 end for
9
10 end for return\(w^{t}\)
```  
**Algorithm 3**\(\texttt{Sensitivity}-\texttt{basedheuristic}(\mathcal{P},w,\mathcal{M})\).