Efficiently Learning Probabilistic Logical Models by Cheaply Ranking Mined Rules

## Abstract

Abstract Probabilistic logical models are a core component of neurosymbolic AI and are important models in their own right for tasks that require high explainability. Unlike neural networks, logical models are often handcrafted using domain expertise, making their development costly and prone to errors. While there are algorithms that learn logical models from data, they are generally prohibitively expensive, limiting their applicability in real-world settings. In this work, we introduce precision and recall for logical rules and define their composition as rule utility – a cost-effective measure to evaluate the predictive power of logical models. Further, we introduce SPECTRUM, a scalable framework for learning logical models from relational data. Its scalability derives from a linear-time algorithm that mines recurrent structures in the data along with a second algorithm that, using the cheap utility measure, efficiently ranks rules built from these structures.
Moreover, we derive theoretical guarantees on the utility of the learnt logical model.
As a result, SPECTRUM learns more accurate logical models orders of magnitude faster than previous methods on real-world datasets.

## 1 Introduction

#### Motivation.

*Neurosymbolic AI* combines neural networks with (probabilistic) logical models, to harness the strengths of both approaches (d’Avila Garcez et al., ; ). Neurosymbolic frameworks outperform neural networks in several areas (Manhaeve et al., ; Gu et al., ; Mao et al., ), particularly in interpretability (Mao et al., ) and in reducing the need for data (Feldstein et al., ). Unlike neural networks, which are fully trained from data, logical models are typically handcrafted. Thus, developing logical models requires domain expertise, in both the data and the inference task. This process is costly and prone to errors. As a result, there has been increased attention on learning logical models from data. This task is known as *structure learning*.

#### Limitations of state-of-the-art.

Examples of probabilistic logical models include *Markov logic networks* (MLNs) (Richardson & Domingos, ), *probabilistic soft logic* (PSL) (Bach et al., ) and *probabilistic logical programs* (PLPs) (Poole, ; Sato, ; De Raedt et al., ). Numerous structure learning techniques for MLNs (Mihalkova & Mooney, ; Kok & Domingos, ; Khot et al., ; Feldstein et al., ) and especially PLPs (Quinlan, ; Muggleton, ; Evans & Grefenstette, ; Schüller & Benz, ; Qu et al., ; Cheng et al., ) have been proposed. However, an overarching limitation of structure learning remains the limited scalability to large datasets. The underlying difficulty is the exponential nature of the problem with respect to the length of possible rules and the number of relations in the data. State-of-the-art structure learning algorithms aim to reduce the complexity of the problem by splitting the task into two steps: 1) *Pattern mining* - which identifies frequently occurring substructures in the data. 2) *Optimisation* - an iterative process during which the best logical formulae are chosen from a set of candidates identified within the patterns. Any structure learning algorithm must make approximations to tackle scalability. Existing methods proceed by finding *approximate* patterns but perform *exact* inference.

#### Contributions.

Our key idea is to flip the aforementioned paradigm: find *exact* patterns but perform *approximate* ranking of candidate formulae to create the final logical model. By eliminating a combinatorial explosion of inference steps, this strategy effectively improves scalability by orders of magnitude.
Specifically, we present three contributions to tackle scalability:

- 1.
*Cheap utility measure*: We introduce *utility*, a criteria for measuring the predictive power of individual rules and logical theories. The utility relates to the degree to which a rule or logical model is satisfied in the data (*precision*) as well as how often the rules predict data points (*recall*). This measure can be computed cheaply, without requiring exact inference.
- 2.
*Linear-time pattern mining*: We present a linear-time algorithm (linear in the size of the dataset) that finds and counts the number of occurrences of different patterns in the data. The algorithm is approximate, yet we provide theoretical guarantees on the computational cost required for a certain error bound on the utility estimates. These guarantees are dataset-independent.
- 3.
*Quadratic-time optimisation*: We present a greedy optimisation algorithm (quadratic in the number of rules of the final model). The algorithm finds the best rules and sorts them by their utility. Since the utility measure is cheap to evaluate, compared to prior art this optimisation step is no longer a bottleneck for scalability.

#### Empirical results.

In addition to the theoretical contributions, we present SPECTRUM, a parallelised C++ implementation of our structure learning framework. As expected from our theoretical results, we show on different relational datasets that SPECTRUM improves scalability by orders of magnitude, consistently reducing runtimes to $<1\%$ compared to the previous state-of-the-art. Despite minor restrictions on mined logical formulae (see below), we find logical models that improve accuracy by up to $19\%$ compared to prior art.

#### Restrictions.

Our pattern-mining algorithm is restricted to datasets containing only unary and binary relations. This is a minor limitation since many real-world databases fit within this restriction. In addition, our utility measure is only well defined for Datalog theories (Abiteboul et al., ), a language
that has been extensively used in data management (Barceló & Pichler, ; Moustafa et al., ) and neurosymbolic learning (Huang et al., ).

## 2 Preliminaries

#### First-order logic.

In first-order logic, constants represent objects in the domain (e.g. $\mathtt{alice}$, $\mathtt{bob}$). Variables range over the objects (e.g. $X$, $Y$, $Z$). A *term* is a constant or a variable.
A predicate p represents a relation between objects (e.g. Friends). The *arity* of p is the number of related objects. An *atom* has the form ${\textsc{p}(t_{1},\dots,t_{n})}$, where p is an $n$-ary predicate, and ${t_{1},\dots,t_{n}}$ are terms. A *fact* is an atom for which each term $t_{i}$ is a constant (e.g. $\textsc{Friends}(\texttt{alice},\texttt{bob})$).
A *relational database* $\mathcal{D}$ is a set of facts.
A Datalog rule $\rho$, or simply *rule*, is a first-order logic formula of the form

$$ $\forall\mathbf{X}.\bigwedge_{i=1}^{n}\textsc{p}_{i}(\mathbf{X}_{i})\to\textsc{ p}(\mathbf{Y}),$ (1) $$

where $\bigwedge_{i=1}^{n}\textsc{p}_{i}(\mathbf{X}_{i})$ is a *conjunction* of atoms, $\to$ denotes logical *implication*,
$\mathbf{X}$, $\mathbf{X}_{i}$, and $\mathbf{Y}$ are tuples of variables, $\mathbf{Y}\subseteq\bigcup_{i=1}^{n}\mathbf{X}_{i}$, where
$\mathbf{X}_{i}\subseteq\mathbf{X}$. Quantifiers are commonly omitted.
The left-hand and the right-hand side of a rule are its *body* and
*head*, respectively, and are denoted by $\mathsf{body}(\rho)$ and $\mathsf{head}(\rho)$. The length of a conjunction is the number of its conjuncts. The length of a rule $L(\rho)$ is the length of its body plus the length of its head.
A *grounding* of an atom is the atom that results after replacing each occurrence of a variable with a constant.
*Groundings* of conjunctions and rules are defined analogously.
A *theory* $\bm{\rho}$ is a set of rules. In probabilistic logic models, the rules would be associated with a weight, where the weight is connected to the likelihood of the rule being satisfied (Richardson & Domingos, ; Bach et al., ).

###### Example 1 .

Let us consider recommender systems, where the goal is to predict whether a user will like an item based on user and item characteristics and previous user ratings for other items. Let us assume the following background knowledge in first-order logic:

$$ $\displaystyle\rho_{1}:\textsc{friends}(U_{1},U_{2})\wedge\textsc{likes}(U_{1}, I)\rightarrow\textsc{likes}(U_{2},I).$ $$

Rule $\rho_{1}$ states that if two users $U_{1}$ and $U_{2}$ are friends and one user liked an item $I$, then the other user will also like the same item.

###### Example 1 .

#### Hypergraphs.

A *hypergraph* ${\mathcal{G}}$ is a pair of the form $(V,E)$, where $V$ is a set of nodes and $E$ is a set of edges with each element of $E$ being a set of nodes $\{v_{1},\dots,v_{n}\}$ from $V$. A hypergraph ${\mathcal{G}}$ is *labelled* if each edge $e$ in ${\mathcal{G}}$ is labelled with a categorical value denoted by $\mathsf{label}(e)$. A *path* in a hypergraph is an alternating sequence of nodes and edges, $(v_{1},e_{1},\dots,e_{l},v_{l+1})$, where each edge $e_{i}$ contains $v_{i}$ and $v_{i+1}$. The *length* of a path is the number of edges in the path.
A hypergraph is *connected* if there exists a path between any two nodes.
The *distance* between two nodes is the length of the shortest path that connects them.
A relational database $\mathcal{D}$ can be represented by a hypergraph $\overline{\mathcal{G}}_{\mathcal{D}}=(V,E)$
where, for each constant $\mathtt{c}_{i}$ occurring in $\mathcal{D}$, $V$ includes a node,
and, for each fact ${\textsc{p}(\mathtt{c}_{1},\dots,\mathtt{c}_{n})}$ in $\mathcal{D}$, $E$ includes an edge ${\{\mathtt{c}_{1},\dots,\mathtt{c}_{n}\}}$ with label p.
Two graphs $\mathcal{G}_{1}$ and $\mathcal{G}_{2}$ are *isomorphic* if there exists a one-to-one mapping $I$
from the nodes of $\mathcal{G}_{1}$
to the nodes of $\mathcal{G}_{2}$ so that for each edge $\{v_{1},\dots,v_{n}\}$ in $\mathcal{G}_{1}$, $\{I(v_{1}),\dots,I(v_{n})\}$ is an edge in $\mathcal{G}_{2}$ and vice versa.
For brevity, from now on, we refer to hypergraphs simply as graphs.

## 3 Patterns

In this section, we introduce the concept of patterns - commonly recurring substructures within a database graph. From now on, we assume that $\mathcal{D}$ is fixed and clear from context. As stated in the introduction, we restrict our discussions to graphs with only unary and binary edges.
We use $\mathsf{u}_{\mathcal{G}}(v)$ and $\mathsf{b}_{\mathcal{G}}(v)$ to denote the set of unary and binary edges in the graph $\mathcal{G}$ that are incident to $v$. Further, we use $\bm{\alpha}$ to denote the set of atoms that have a grounding in $\mathcal{D}$ and $\alpha\in\bm{\alpha}$ to denote a particular atom. We use $\bm{\overline{\alpha}}$ to denote the set of all possible groundings of $\alpha$ in $\mathcal{D}$ and $\overline{\alpha}\in\bm{\overline{\alpha}}$ to denote a particular grounding.

Similarly to how we can view relational databases as graphs, we can also view conjunctions of atoms as graphs. For a conjunction of atoms $\varphi\vcentcolon=\bigwedge_{i=1}^{n}\textsc{p}_{i}(\mathbf{t}_{i})$, the pattern of $\varphi$, denoted as $\mathcal{G}_{\varphi}=(V,E)$, is the graph where, for each term $t_{i}$ occurring in $\varphi$, $V$ includes a node $t_{i}$, and, for each atom $\textsc{p}(t_{1},\dots,t_{n})$ occurring in $\varphi$, $E$ includes an edge
${\{t_{1},\dots,t_{n}\}}$ with label p. The length of a pattern $\mathcal{G}_{\varphi}$ is the number of atoms in $\varphi$. Given a rule $\rho$, the patterns corresponding to its head and body are denoted by $\mathcal{G}_{\mathsf{head}(\rho)}$ and $\mathcal{G}_{\mathsf{body}(\rho)}$, respectively. We call $\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ the *rule pattern* of $\rho$.
Rule $\rho$ is *connected* if $\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ is connected; it is *body-connected* if $\mathcal{G}_{\mathsf{body}(\rho)}$ is connected.

A *ground pattern* of a conjunction $\varphi$ is
the graph corresponding to a grounding of $\varphi$ that is satisfied in $\mathcal{D}$.
We denote by $\bm{\overline{\mathcal{G}}}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ the set of all
ground patterns of $\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)$ in $\mathcal{D}$.
For a fact $\overline{\alpha}$ that is a grounding of $\alpha=\mathsf{head}(\rho)$,
we use $\bm{\overline{\mathcal{G}}}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}^{
\mathsf{head}(\rho)={\overline{\alpha}}}$ to denote the subset of $\bm{\overline{\mathcal{G}}}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ which contains only groundings of patterns of the form $\mathcal{G}_{\mathsf{body}(\rho)\wedge\overline{\alpha}}$.

## 4 Rule Utility

In this section, we introduce a measure, that we call *utility*, for assessing the ”usefulness” of a theory without requiring inference. The utility itself depends on various criteria, which we present below.
The following definitions hold for connected rules that are also body connected.

###### Definition 1 (Precision) .

The precision of a rule $\rho$ is defined as

$$ $\mathsf{P}(\rho)\colonequals\frac{|\bm{\overline{\mathcal{G}}}_{\mathsf{body}( \rho)\wedge\mathsf{head}(\rho)}|}{|\bm{\overline{\mathcal{G}}}_{\mathsf{body}( \rho)}|}.$ $$

Intuitively, $\mathsf{P}(\rho)$ is thus the fraction of times that the head and body of a rule are both true in the data when the body is true in the data. If one considers cases where the body and head are both true as true positives (TP, i.e. the rule is satisfied), and cases where the body is true and the head is false as false positives (FP, i.e. the rule is not satisfied), then the definition of precision is analogous to the definition of precision in classification tasks, i.e. $\mathsf{P}(\rho)=TP/(TP+FP)$. Useful rules should make claims that are often true, and thus have high precision.

One issue with precision, as defined above, is that it underestimates how often a rule is satisfied if there are symmetries in the rule. We fix this issue by multiplying the precision by a symmetry factor:

###### Definition 2 (Symmetry factor) .

The symmetry factor of a rule $\rho$, denoted by $\mathsf{S}(\rho)$, is defined as the number of subgraphs in $\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ that are isomorphic to $\mathcal{G}_{\mathsf{body}(\rho)}$.

###### Example 2 .

Continuing with Example 1, assume that the training data $\mathcal{D}$ includes the facts:
$\textsc{likes}(\mathtt{alice},\mathtt{starwars})$, $\textsc{friends}(\mathtt{alice},\mathtt{bob})$, $\textsc{likes}(\mathtt{bob},\mathtt{starwars})$. Then, there are two ground
patterns of ${\textsc{likes}(U_{1},I)\wedge\textsc{friends}(U_{1},U_{2})}$, and one ground pattern of ${\textsc{likes}(U_{1},I)\wedge\textsc{friends}(U_{1},U_{2})\wedge\textsc{likes
}(U_{2},I)}$ in $\mathcal{D}$. Hence, for rule $\rho_{1}$, we obtain $\mathsf{P}(\rho_{1})=\frac{1}{2}$ despite that the rule correctly predicts that $\mathtt{alice}$ likes $\mathtt{starwars}$ given that $\mathtt{bob}$ likes $\mathtt{starwars}$ as well as vice versa. However, this rule has a symmetry factor of $2$, (as illustrated by Figure 1) and once the precision is corrected, we get $\mathsf{P}(\rho_{1})\cdot\mathsf{S}(\rho_{1})=1$, as expected since the rule is always satisfied.

Figure: Figure 1: Datagraph $\overline{\mathcal{G}}_{\mathcal{D}}$ representing Example 2. Constants $\mathtt{alice}$, $\mathtt{bob}$, and $\mathtt{starwars}$ are abbreviated as $\mathtt{a}$, $\mathtt{b}$, and $\mathtt{s}$.

The second issue with precision, as defined above, is that, if the facts in $\mathcal{D}$ are unbalanced (i.e. facts of different predicates occur with different frequencies), then certain rules can still have high precision even if the facts are uncorrelated. We illustrate this issue with an example below.

###### Example 3 .

Continuing with Example 1, and consider, in addition to rule $\rho_{1}$, rule $\rho_{2}$:

$$ $\rho_{2}:\textsc{likes}(U_{1},I)\wedge\textsc{friends}(U_{1},U_{2})\rightarrow \textsc{dislikes}(U_{2},I).$ $$

Assume also that the facts $\mathcal{D}$ abide by the following statistics:
(i) if a user $U_{1}$ likes an item $I$, then a friend of theirs $U_{2}$ likes $I$
with probability 50% and dislikes $I$ with probability 50%, and
(ii) the number of dislikes-facts is ten times larger than the number of
likes-facts.
From assumption (i) and Definition 1, it follows that $\mathsf{P}(\rho_{1})=\mathsf{P}(\rho_{2})=\frac{1}{2}$ since
for each grounding of the body
${\textsc{likes}(\mathtt{u_{1}},\mathtt{i})\wedge\textsc{friends}(\mathtt{u_{1}
},\mathtt{u_{2}})}$ in $\mathcal{D}$,
there is either a fact ${\textsc{likes}(\mathtt{u_{2}},\mathtt{i})}$ or a fact
${\textsc{dislikes}(\mathtt{u_{2}},\mathtt{i})}$ in $\mathcal{D}$ and each fact has a probability of 50%. If there were no correlations in the facts (i.e. assumption (i) does not hold), then we would assume, from assumption (ii), that the head is ten times more likely to be dislikes than likes. Therefore, the result $\mathsf{P}(\rho_{1})=\mathsf{P}(\rho_{2})=\frac{1}{2}$ is misleading, since $\rho_{1}$ is correct over five times more often than random chance ($1/2$ vs $1/11$) and $\rho_{2}$ is correct less often than random chance ($1/2$ vs $10/11$).

The above example demonstrates how in unbalanced datasets, precision underestimates correlations of underrepresented facts. We fix this issue by dividing the precision by a Bayesian prior:

###### Definition 3 (Bayesian Prior) .

The Bayesian prior of a rule $\rho$ is defined as

$$ $\mathsf{B}(\rho):=\frac{|\bm{\overline{\mathcal{G}}}_{\mathsf{head}(\rho)}|}{ \sum_{\alpha\in\mathcal{A}}|\bm{\overline{\mathcal{G}}}_{\alpha}|},$ $$

where $\mathcal{A}$ is the set of all atoms constructable over all predicates occurring in $\mathcal{D}$ that have the same tuple of terms as $\mathsf{head}(\rho)$.

###### Example 3 (continued) .

For rules $\rho_{1}$ and $\rho_{2}$, the head predicate in both cases contains a user and an item term, thus, $\mathcal{A}=\{\textsc{likes}(U,I),\textsc{dislikes}(U,I)\}$ for both rules (Definition 3). The Bayesian priors of rules $\rho_{1}$ and $\rho_{2}$ are given by:

$$ ${\mathsf{B}(\rho_{1})=\frac{|\bm{\overline{\mathcal{G}}}_{\textsc{likes}(U,I)} |}{|\bm{\overline{\mathcal{G}}}_{\textsc{likes}(U,I)}|+|\bm{\overline{\mathcal {G}}}_{\textsc{dislikes}(U,I)}|}=\frac{1}{10+1},\quad\mathsf{B}(\rho_{2})= \frac{|\bm{\overline{\mathcal{G}}}_{\textsc{dislikes}(U,I)}|}{|\bm{\overline{ \mathcal{G}}}_{\textsc{likes}(U,I)}|+|\bm{\overline{\mathcal{G}}}_{\textsc{ dislikes}(U,I)}|}=\frac{10}{10+1}}.$ $$

Notice that these are exactly the probabilities of $\rho_{1}$ and $\rho_{2}$ being true if the facts in $\mathcal{D}$ were uncorrelated. Precision of the rules, corrected for this uniform prior, would then be $\frac{\mathsf{P}(\rho_{1})}{\mathsf{B}(\rho_{1})}=\frac{11}{2}$ and $\frac{\mathsf{P}(\rho_{2})}{\mathsf{B}(\rho_{2})}=\frac{11}{20}$. Since the first ratio is larger than one, rule $\rho_{1}$ successfully predicts a correlation. In contrast, for rule $\rho_{2}$, since this ratio is smaller than one, the rule
makes a prediction that is worse than a random guess.
Hence, by this metric, rule $\rho_{1}$ is correctly identified as more useful than $\rho_{2}$.

The symmetry and prior-corrected precision is then the product $\frac{\mathsf{P}(\rho)\cdot\mathsf{S}(\rho)}{\mathsf{B}(\rho)}$. Note that a useful rule should have a symmetry-corrected precision, $\mathsf{P}(\rho)\cdot\mathsf{S}(\rho)$, that is better than random chance, $\mathsf{B}(\rho)$, i.e. $\frac{\mathsf{P}(\rho)\cdot\mathsf{S}(\rho)}{\mathsf{B}(\rho)}>1$.

In addition to being precise, useful rules should account for many diverse observations in the data. Below, we introduce a metric to count how often a rule pattern recalls facts in the data.

###### Definition 4 (Recall) .

The recall of a rule $\rho$ is defined as

$$ $\mathsf{R}(\rho)\colonequals\sum_{\overline{\alpha}\in\bm{\overline{\alpha}}} \ln(1+|\bm{\overline{\mathcal{G}}}_{\mathsf{body}(\rho)\wedge\mathsf{head}( \rho)}^{\mathsf{head}(\rho)={\overline{\alpha}}}|),$ $$

where $\bm{\overline{\alpha}}$ is the set of all groundings of $\alpha\colonequals\mathsf{head}(\rho)$ in $\mathcal{D}$.

Intuitively, $|\bm{\overline{\mathcal{G}}}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}^{
\mathsf{head}(\rho)={\overline{\alpha}}}|$
says how many different instantiations of $\rho$ entail $\overline{\alpha}$, and the logarithm reflects the diminishing returns of repeatedly recalling the same fact. Note that, while recalling the same fact increases the utility logarithmically, recalling different facts increases the utility linearly.

Longer rules are biased to have more groundings in the data than shorter rules, due to a combinatorial explosion. Therefore, an issue with recall, as defined above, is that it biases towards longer rules. Longer rules increase computational costs, forcing logical solvers to make more approximations during inference, which reduces accuracy. To address this, we introduce a complexity factor that penalises longer rules:

###### Definition 5 (Complexity factor) .

The complexity factor of $\rho$ of length $L(\rho)$ is defined as

$$ $\mathsf{C}(\rho)\colonequals e^{-L(\rho)}.$ $$

The complexity-corrected recall, $\mathsf{R}(\rho)\cdot\mathsf{C}(\rho)$, discourages using longer rules if they do not have a correspondingly larger recall, thus favouring the simplest explanation for the data (Occam’s razor).

Useful rules should exhibit both high precision (corrected for symmetry and prior probabilities) and high recall (corrected for rule complexity). This leads to a natural metric for quantifying the “usefulness” of a rule:

###### Definition 6 (Rule utility) .

The utility of a rule $\rho$ is defined as

$$ $\mathsf{U}(\rho)\colonequals\frac{\mathsf{P}(\rho)\mathsf{S}(\rho)}{\mathsf{B} (\rho)}\cdot\mathsf{R}(\rho)\mathsf{C}(\rho).$ $$

Finally, we extend the notion of utility to a theory $\bm{\rho}$. Different rules can recall the same fact. The recall for a set of rules should be analogous to Definition 4 but include contributions from all rules:

###### Definition 7 (Complexity-corrected rule-set recall) .

For a set of rules $\bm{\rho}_{\alpha}$ having the same head $\alpha$, the complexity-corrected rule-set recall is defined as the product $\mathsf{R}(\bm{\rho}_{\alpha})\cdot\mathsf{C}(\bm{\rho}_{\alpha})$, where

$$ $\mathsf{R}(\bm{\rho}_{\alpha})\colonequals\sum_{\overline{\alpha}\in\bm{ \overline{\alpha}}}\ln\left(1+\sum_{\rho\in\bm{\rho}_{\alpha}}|\bm{\overline{ \mathcal{G}}}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}^{\mathsf{head}( \rho)={\overline{\alpha}}}|\right)\quad\text{and}\quad\mathsf{C}(\bm{\rho}_{ \alpha})\colonequals\left(\prod_{\rho\in\bm{\rho}_{\alpha}}\mathsf{C}(\rho) \right)^{\frac{1}{|\bm{\rho}|}}.$ $$

Intuitively, $\sum_{\rho\in\bm{\rho}_{\alpha}}|\bm{\overline{\mathcal{G}}}_{\mathsf{body}(
\rho)\wedge\mathsf{head}(\rho)}^{\mathsf{head}(\rho)={\overline{\alpha}}}|$ counts the number of different instantiations of *all* rules in the set $\bm{\rho}_{\alpha}$ that entail a particular fact $\overline{\alpha}$, whereas $\mathsf{C}(\bm{\rho}_{\alpha})$ is simply the geometric average of the complexity factor for all rules in set $\bm{\rho}_{\alpha}$.
We are now ready to introduce the notion of theory utility:

###### Definition 8 (Theory utility) .

The utility of a theory $\bm{\rho}$ is defined as

$$ $\mathsf{U}(\bm{\rho})\colonequals\sum_{\alpha\in\bm{\alpha}}\left(\sum_{\rho \in\bm{\rho}_{\alpha}}\frac{\mathsf{P}(\rho)\mathsf{S}(\rho)}{\mathsf{B}(\rho) }\right)\cdot\mathsf{R}(\bm{\rho}_{\alpha})\mathsf{C}(\bm{\rho}_{\alpha}),$ $$

where $\bm{\alpha}=\{\mathsf{head}(\rho)\,|\,\rho\in\bm{\rho}\}$ and $\bm{\rho}_{\alpha}=\{\rho\in\bm{\rho}\,|\,\mathsf{head}(\rho)=\alpha\}$.

The outer sum in Definition 8 runs over the different atoms
occurring in the heads of the rules in $\bm{\rho}$, while the inner sum runs over the different rules with the same head atom. Computing rule utility requires enumerating all
ground patterns of a rule, its body, and its head in the data. In the next section, we outline how we find these groundings efficiently.

###### Definition 1 (Precision) .

###### Definition 2 (Symmetry factor) .

###### Example 2 .

###### Example 3 .

###### Definition 3 (Bayesian Prior) .

###### Example 3 (continued) .

###### Definition 4 (Recall) .

###### Definition 5 (Complexity factor) .

###### Definition 6 (Rule utility) .

###### Definition 7 (Complexity-corrected rule-set recall) .

###### Definition 8 (Theory utility) .

## 5 Pattern Mining

In this section, we present our technique for
mining rule patterns from relational data, i.e. finding subgraphs in a relational database graph. Since finding all subgraphs is generally a hard problem with no known polynomial algorithm (Bomze et al., ), we adopt an approach similar to PRISM (Feldstein et al., ). In particular, we present a non-exhaustive algorithm that has only linear-time complexity in the dataset size but that allows us to compute estimates of utility that are close, in a precise sense, to their true values.

### 5.1 Algorithm

The steps of our technique are outlined in Algorithm 1. The algorithm
mines ground patterns by calling a recursive function (NextStep) from each node $v_{0}$ in the datagraph $\overline{\mathcal{G}}_{\mathcal{D}}$ (lines 1-1). Intuitively, the algorithm searches for ground patterns by rolling out paths in parallel from a starting node. The recursion stops at a user-defined *maximum depth* $D$, rolling out up to a *maximum number of paths* $N$.

In each call of NextStep, the algorithm visits a node $v\in V$ of $\overline{\mathcal{G}}_{\mathcal{D}}$. At node $v$, unary relations $\mathsf{u}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v)$ are grafted onto previously found ground patterns $\bm{\mathcal{\overline{G}}}_{\textnormal{previous}}$ (lines 1-1). We use $\overline{\mathcal{G}}\circ e$ to denote the graph that results after adding edge $e$ and the nodes of $e$ to graph $\overline{\mathcal{G}}$. The resulting ground patterns are stored in $\bm{\mathcal{\overline{G}}}_{\textnormal{new}}$ (line 1). If the maximum recursion depth has not been reached (line 1), a subset of the binary edges of node $v$ is then selected (lines 1-1). The algorithm avoids mining patterns corresponding to tautologies by excluding previously visited binary edges (line 1). To keep the complexity linear, we enforce $N$ to be the maximum number of paths by setting the maximum number of selected binary edges $n$ to be $N$ divided by the number of binary edges selected at each previous stage (lines 1, 1). We graft each chosen binary edge onto the ground patterns in $\bm{\mathcal{\overline{G}}}_{\textnormal{new}}$ (lines 1-1), store the new ground patterns in $\bm{\mathcal{\overline{G}}}_{\textnormal{final}}$ (line 1), and pass $\bm{\mathcal{\overline{G}}}_{\textnormal{final}}$ on to the subsequent call (line 1). $\bm{\mathcal{\overline{G}}}_{\textnormal{final}}$ is passed to the next recursive call to continuously extend previously mined patterns. In the next recursive call, the recursion depth $d$ is increased by $1$, thereby expanding the search of grounds patterns to include nodes up to a distance $d$ away from $v_{0}$. At each depth $d\in\{0,\dots,D-1\}$ the algorithm grafts up to one unary and one binary onto the patterns previously discovered along that path. At depth $d=D$, the algorithm only grafts up to one unary onto the patterns, since it terminates before grafting binaries (line 1). Thus, the patterns found by Algorithm 1 are of maximum length $2D+1$.

As a special case, the algorithm also mines patterns that consist of two unary edges on a single node in line 1, to
allow constructing rules of the form ${\textsc{p}_{1}(X)\rightarrow\textsc{p}_{2}(X)}$. DoubleUnaryPatterns creates all possible patterns that consist of all pairings of distinct unary edges from the set $\mathsf{u}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v_{0})$.

###### Remark 1 .

For simplicity, in Algorithm 1, we presented $\bm{\mathcal{\overline{G}}}_{\textnormal{global}}$ as a set of ground patterns. However, in a later stage of our structure-learning algorithm, we will also need knowledge of the corresponding non-ground patterns to compute rule utility (Section 4). In our implementation, $\bm{\mathcal{\overline{G}}}_{\textnormal{global}}$ is thus in fact a map from patterns to every corresponding ground pattern that was found in $\overline{\mathcal{G}}_{\mathcal{D}}$. This map is generated on the fly, where everytime a new ground pattern is mined, we obtain its corresponding pattern by variabilising its constants (up to isomorphism) and then adding it to the map.

Figure: Algorithm 1 $\textsc{{MinePatterns}}(\overline{\mathcal{G}}_{\mathcal{D}},D,N)$

###### Example 4 .

We illustrate how Algorithm 1 mines patterns from the graph $\overline{\mathcal{G}}_{\mathcal{D}}$ shown in Figure 2. We
follow a recursive call from node $v_{0}$ with parameters $N=4$ and $D=2$. To ease the presentation, we denote ground patterns as sets of edges.

Since $e_{0}$ is the only unary edge of $v_{0}$, Algorithm 1 stores the pattern
$\{e_{0}\}$ in $\bm{\mathcal{\overline{G}}}_{\textnormal{global}}$. Algorithm 1 then finds two binary edges $e_{1}$ and $e_{2}$ and, since $2\leq N$, it considers both edges in turn. Algorithm 1 then grafts these two edges onto the previous pattern which by default contains the empty pattern $\emptyset$. In particular, for $e_{1}$, we graft $\emptyset\circ e_{1}=\{e_{1}\}$ and $\{e_{0}\}\circ e_{1}=\{e_{0},e_{1}\}$. The resulting patterns along with $\mathcal{E}_{\textnormal{previous}}=\{e_{1}\}$ are passed as

$$ $\bm{\mathcal{\overline{G}}}_{\textnormal{final}}=\begin{Bmatrix}\{e_{1}\}\\ \{e_{0},e_{1}\}\end{Bmatrix}$ $$

to the next recursive call and are stored in $\bm{\mathcal{\overline{G}}}_{\textnormal{global}}$.
Algorithm 1 then proceeds analogously along $e_{2}$. After visiting node $v_{2}$, $\bm{\mathcal{\overline{G}}}_{\textnormal{global}}$ has as follows:

$$ $\displaystyle\bm{\mathcal{\overline{G}}}_{\textnormal{global}}=\begin{Bmatrix} \begin{subarray}{c}\{e_{0}\}\end{subarray}\\ \begin{subarray}{c}\{e_{1}\}\\ \{e_{2}\}\end{subarray}\\ \begin{subarray}{c}\{e_{0},e_{1}\}\\ \{e_{0},e_{2}\}\end{subarray}\\ \end{Bmatrix}.$ $$

Both new recursions are started with updated $n=4/2$ and $d=1$. At $v_{1}$, since $n=2$ and since there are two, previously unvisited, edges $e_{4}$ and $e_{5}$, the algorithm continues the recursion along $e_{4}$ and $e_{5}$ with updated $n=2/2$ and $d=2$. In contrast, at $v_{2}$, since $n=2$ but there being three, previously unvisited, edges $e_{7}$, $e_{8}$, and $e_{9}$, the algorithm will choose at random two out of the three edges and continue the recursion with $n=2/2$. Since, $d=2$ in the next recursive calls, the algorithm terminates. Notice that if $N$ was set to six, then Algorithm 1 would have found all ground patterns $\overline{\mathcal{G}}_{\mathcal{D}}$.

Figure: Figure 2: Graph $\overline{\mathcal{G}}_{\mathcal{D}}$ from Example 4. The graph contains three types of labelled edges: red unary edges $\textsc{p}_{1}$, dashed black binary edges $\textsc{p}_{2}$, and solid black binary edges $\textsc{p}_{3}$.

###### Remark 1 .

###### Example 4 .

### 5.2 Theoretical Properties

In this section, we show the complexity of Algorithm 1 and provide
completeness guarantees, as well as guarantees on the uncertainty of the mined patterns.
Proofs of all theorems can be found in Appendix A.

###### Theorem 5 (Completeness) .

Let $v$ and $v^{\prime}$ be two nodes in $\overline{\mathcal{G}}_{\mathcal{D}}$ that are distance $l$ apart, for some $l\geq 0$.
We say that
$v^{\prime}$ is *$N$-close* to $v$ if, for each path $(v_{i_{0}},e_{i_{0}},\dots,e_{i_{l-1}},v_{i_{l}})$ of length $l$ between $v$ and $v^{\prime}$ in $\overline{\mathcal{G}}_{\mathcal{D}}$, where $v_{i_{0}}=v$ and
$v_{i_{l}}=v^{\prime}$, the following holds:

$$ $\frac{N}{|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v_{i_{0}})|\prod \limits_{j=1}^{l-1}(|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v_{i_{j }})|-1)}\geq 1.$ $$

Then, for each $N\geq 0$, each $D\geq 0$, and each $v\in\overline{\mathcal{G}}_{\mathcal{D}}$, Algorithm 1 mines *all* ground patterns involving $v$ and nodes that are $N$-close to $v$ and a distance $\leq D$ from $v$;
all remaining ground patterns involving $v$ and nodes within distance $D$ are found with a probability larger than when running $N$ random walks from $v$.

When mining patterns, Algorithm 1 runs at most $N$ paths from $|V|$ nodes up to a maximum recursion depth $D$. Below, we provide a tighter bound on the complexity.

###### Theorem 6 (Complexity) .

The maximum number of recursions in Algorithm 1 is given by

$$ $\displaystyle\sum_{v\in\overline{\mathcal{G}}_{\mathcal{D}}}\min\left(\left(| \mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v)|+\sum_{i=1}^{D-1}\sum_{v^ {\prime}\in\mathcal{N}_{i}(v)}(|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D }}}(v^{\prime})|-1)\right),ND\right),$ $$

where $\mathcal{N}_{i}(v)$ is the set of nodes, that are reached within $i$ steps of recursion from $v$. The runtime complexity is thus, worst case, $\mathcal{O}(|V|ND)$, but can be significantly lower for graphs $\overline{\mathcal{G}}_{\mathcal{D}}$ with low binary degree.

For any conjunction $\varphi$, Algorithm 1, in general, finds only a subset of its ground patterns in $\overline{\mathcal{G}}_{\mathcal{D}}$. Thus,
the utility measures computed based on the mined patterns will be estimates of the actual values.
We quantify these utility estimates by means of $\varepsilon$-*uncertainty*, in line with Feldstein et al. ().

###### Definition 9 ( $\varepsilon$ -uncertainty) .

An estimate $\hat{s}$ of a scalar $s$ is $\varepsilon$-uncertain, for ${\varepsilon\in[0,1)}$, if ${{|\hat{s}-s|}/{s}<\varepsilon}$.

###### Definition 10 (Pattern occurrence distribution) .

The pattern occurrence distribution $P_{\mathcal{D}}$, subject to $\mathcal{D}$, is the function that maps each connected pattern to the number of its groundings in $\mathcal{D}$.

Theorem 7
provides a bound on the maximum number of paths $N$ needed by Algorithm 1 to guarantee $\varepsilon$-uncertainty utility estimates. This quantifies the trade-off between accuracy and runtime.

###### Theorem 7 (Optimality) .

Let $\bm{\rho}$
be a set of rules whose patterns are of length $\leq 2D+1$, where for each $\rho\in\bm{\rho}$, patterns $\mathcal{G}_{\mathsf{body}(\rho)}$, $\mathcal{G}_{\mathsf{head}(\rho)}$, and $\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ are among the $M$ patterns with the highest number of groundings in $\overline{\mathcal{G}}_{\mathcal{D}}$.
If $P_{\mathcal{D}}$ is Zipfian, then
to ensure that $\mathsf{U}(\bm{\rho})$
is $\varepsilon$-uncertain,
the upper bound on $N$ in Algorithm 1 scales as

$$ $\displaystyle N\propto\mathcal{O}\left(\frac{MD}{\varepsilon^{2}}\right).$ $$

###### Remark 2 .

Theorem 7 is a worst-case upper bound. For instance, for homogeneous data, the upper bound scaling is $N\propto\mathcal{O}\left(\frac{MD}{|V|\varepsilon^{2}}\right)$. In our experiments (Section 7), we find that setting $N=\frac{MD}{|V|\varepsilon^{2}}$ performs well when all nodes in the data have roughly the same binary degree.

###### Theorem 5 (Completeness) .

###### Theorem 6 (Complexity) .

###### Definition 9 ( ε 𝜀 \varepsilon italic_ε -uncertainty) .

###### Definition 10 (Pattern occurrence distribution) .

###### Theorem 7 (Optimality) .

###### Remark 2 .

#### Comparison to random walks

Prior work mined motifs, objects similar to ground patterns, using random walks (Kok & Domingos, ; Feldstein et al., ). Intuitively, Algorithm 1 can be seen as running random walks in parallel, while avoiding repeating the same walk twice and thereby wasting computational effort. Running $N$ random walks of length $D$ from $|V|$ nodes requires $|V|ND$ steps, which is the same as the *worst-case* computational cost of Algorithm 1 (Theorem 6). Another advantage of Algorithm 1 over random walks is that it results in more accurate utility estimates:

- 1.
Random walks might backtrack, therefore, finding ground patterns of tautologies. Algorithm 1 avoids this issue by neglecting any previously encountered edge.
- 2.
Random walks may revisit paths that have already been walked before. In contrast, in each call to NextStep, Algorithm 1 either visits a previously unvisited edge in the graph or it terminates. Therefore each new computation provides new information.
- 3.
Random walks can miss ground patterns since they randomly sample a subset. In contrast, Algorithm 1 is guaranteed to mine all ground patterns involving nodes that are $N$-close to the source node $v_{0}$, while ground patterns that involve nodes that are not $N$-close are mined with a higher probability than with random walks (Theorem 5).

## 6 Utility-based structure learning

We now introduce our structure learning pipeline, which we call SPECTRUM (Structural Pattern Extraction and Cheap Tuning of Rules based on Utility Measure), presented in Algorithm 2. In summary, SPECTRUM begins by mining patterns, then checks each mined pattern whether it is a pattern of a “useful” rule, and finally sorts the useful rules in a greedy fashion.

### 6.1 Restrictions on the mined rules

As we stated in the introduction, SPECTRUM focuses on learning Datalog rules (as opposed to general first-order logic formulae).
In addition, the algorithms restrict the shape of the mined rules:

- (1)
Algorithm 1 only mines patterns (and by extension rules) where each term occurs in at most two binary predicates and one unary predicate, except for the special case ${\textsc{p}_{1}(X)\rightarrow\textsc{p}_{2}(X)}$ (line 1 in Algorithm 1).
- (2)
Algorithm 2 restricts to rules that are body-connected and *term-constrained*, where a rule $\rho$ is term-constrained if every term occurs in at least two atoms of the head or the body of the rule.

For example, the rule $\textsc{friends}(U_{1},U_{2})\rightarrow\textsc{likes}(U_{2},I)$ is not term-constrained, since neither $U_{1}$ nor $I$ appear twice in the rule, but $\textsc{likes}(U_{1},I)\wedge\textsc{friends}(U_{1},U_{2})\rightarrow\textsc{
likes}(U_{2},I)$ is term-constrained.

Restriction (1) helps to restrict the complexity of the framework. Additionally, we recommend setting the terminal depth $D$ in Algorithm 1 to a small number, as $N$ scales with a factor of $D$ (Theorem 7), and thus Algorithm 1 scales with a factor of $D^{2}$.
In our experiments (Section 7), we set $D=3$ (i.e. a maximum of three binary predicates per rule). This is not a severe limitation, as we have empirically seen that many useful rules can be expressed within this restriction.

Restriction (2) is a requirement of useful rules, since, for any term in the rule and for any atom that we try to predict, there is at least one other atom that we know that term belongs to. This is useful for link prediction. Utility calculations require rules to be body-connected.

### 6.2 Algorithm

SPECTRUM requires three parameters $M$, $\varepsilon$, and $D$: $M$ is the maximum number of rules of the final theory; $D$ sets a limit to the length of the mined rules as the pattern length is limited to $2D+1$; $\varepsilon$ balances the trade-off between accuracy in the utility measures and computational effort.
Given these parameters, SPECTRUM computes an optimal $N$ for pattern mining (Theorem 7), and, using Algorithm 1, mines patterns which are stored in
a map $\bm{\mathcal{\overline{G}}}_{\textnormal{global}}$ of patterns to their groundings in $\overline{\mathcal{G}}_{\mathcal{D}}$.

Figure: Algorithm 2 SPECTRUM

Each pattern $\mathcal{G}_{\varphi}$ in the keys of the map $\bm{\mathcal{\overline{G}}}_{\textnormal{global}}$ is considered in turn. Each rule that could have resulted in this pattern, i.e. a rule from the set $\mathcal{R}\vcentcolon={\{\rho\mid\mathcal{G}_{\mathsf{body}(\rho)\wedge
\mathsf{head}(\rho)}=\mathcal{G}_{\varphi}\}}$, is considered. If a rule $\rho\in\mathcal{R}$ is term constrained and satisfies $\frac{\mathsf{P}(\rho)\mathsf{S}(\rho)}{\mathsf{B}(\rho)}>1$, i.e. the rule is a better predictor than a random guess (Section 4), then $\rho$ is added to the set of candidate rules $\bm{\rho}_{\textnormal{candidates}}$.

From the set of candidate rules $\bm{\rho}_{\textnormal{candidates}}$, a subset of $M$ rules is chosen with the highest individual utility (Definition 6). Notice that the utility of each rule $\rho$ is directly calculated from $\bm{\mathcal{\overline{G}}}_{\textnormal{global}}$; since this is a map from patterns $\mathcal{G}_{\varphi}$ of a conjunction $\varphi$ to its groundings in $\overline{\mathcal{G}}_{\mathcal{D}}$, i.e. $\bm{\overline{\mathcal{G}}}_{\varphi}$. The quantity $|\bm{\overline{\mathcal{G}}}_{\varphi}|$ can be looked up in the map. The conjunction $\varphi$ can be $\mathsf{body}(\rho)$, $\mathsf{head}(\rho)$, or $\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)$. The complexity and symmetry factor can be computed for each $\rho$ directly from its length, rule pattern and body pattern.

SPECTRUM then orders the remaining $M$ rules
in order of their contribution to the theory utility (Definition 8).
The algorithm starts by finding the rule with the highest utility and stores it in a vector $\bm{\rho}_{\textnormal{final}}$. Then, in each iteration of the while-loop, SPECTRUM finds the rule out of the remaining ones that provides the highest increase in theory utility when added to the current rules in $\bm{\rho}_{\textnormal{final}}$.

After SPECTRUM, the rules $\bm{\rho}_{\textnormal{final}}$ can be passed to any probabilistic logical model framework (e.g. PSL or MLN) to learn the weights of the rules (i.e. the likelihood of the rule being satisfied) for a given dataset $\mathcal{D}$. We recommend adding one rule at a time to the logical model (in the order they were added to the vector $\bm{\rho}_{\textnormal{final}}$) when learning the weights. One can then validate the different theories by checking when the accuracy drops, as more rules may not imply a better theory.

## 7 Experiments

We compare SPECTRUM on computation time and accuracy of the mined logical theories against state-of-the-art MLN structure learners. Additionally, to test whether the scalability bottleneck of structure learning algorithms has been removed by SPECTRUM, we tested it on large real-world datasets using PSL. Given a dataset with incomplete observations, our goal is to predict the truth values for the missing data. This problem can be framed as missing link prediction in graphs.

#### Experiment Setup:

For SPECTRUM, we set $N=\frac{MD}{|V|\varepsilon^{2}}$, $M=30$, $\varepsilon=0.1$ and $D=3$. We ran the experiments on a Linux machine with 32Gb of RAM and a 12-core 2.60GHz i7-10750H CPU.

### 7.1 MLN Experiments

#### Datasets:

To compare our work to state-of-the-art structure learners, we perform experiments on two benchmark datasets adopted for MLNs (Richardson & Domingos, ):

- 1.
IMDB: The dataset is subsampled from the IMDB.com database and describes relationships among movies, actors and directors.
- 2.
WEBKB: The dataset consists of web pages and hyperlinks collected from four computer science departments.

Each dataset has five splits. One split is used to test the learnt theories, while the other four are used to train the models. The reported results are the average over all permutations.

#### Baselines:

We compared against LSM (Kok & Domingos, ), BOOSTR (Khot et al., ), and PRISM (Feldstein et al., ), using the parameters as suggested by the respective authors. Since PRISM only mines motifs, we used LSM for the remaining steps of the pipeline, in line with Feldstein et al. ().

#### Results:

We used Alchemy (Kok et al., ) – an implementation of an MLN framework – to perform predictions using the learnt theories. We report in Table 1 the balanced accuracy (ACC) and runtimes. SPECTRUM improves on all fronts: the runtime is reduced to $<1\%$ compared on both IMDB and WEBKB when compared to the most accurate prior art, while also improving accuracy by over 16% on both datasets.

**Table 1: Balanced accuracy (ACC) and runtime comparisons of PRISM, LSM, BOOSTR, and SPECTRUM on MLN experiments.**
|  | Algorithm | ACC | RUNTIME (s) |
| --- | --- | --- | --- |
| IMDB | LSM | 0.55 $\pm$ 0.01 | 430 $\pm$ 20 |
| BOOSTR | 0.50 $\pm$ 0.01 | 165.7 $\pm$ 129 |  |
| PRISM | 0.58 $\pm$ 0.01 | 320 $\pm$ 40 |  |
| SPECTRUM | 0.74 $\pm$ 0.02 | 0.8 $\pm$ 0.05 |  |
| WEBKB | LSM | 0.65 $\pm$ 0.005 | 220 $\pm$ 10 |
| BOOSTR | 0.12 $\pm$ 0.09 | 9.3 $\pm$ 0.4 |  |
| PRISM | 0.65 $\pm$ 0.005 | 102 $\pm$ 5 |  |
| SPECTRUM | 0.81 $\pm$ 0.01 | 0.5 $\pm$ 0.02 |  |

### 7.2 PSL Experiments

#### Datasets:

To assess the scalability of SPECTRUM, we also perform experiments on large PSL benchmarks:

- 1.
Citeseer (6.8k relations): This dataset consists of research papers, categories the papers fall under, and links between papers. Citeseer has the relations $\textsc{HasCat}(\mathtt{P},\mathtt{C})$ (describing whether a paper $\mathtt{P}$ is of a specific category $\mathtt{C}$) and $\textsc{Link}(\mathtt{P}_{1},\mathtt{P}_{2})$ (describing whether two papers are linked). The dataset has six paper categories.
- 2.
Cora (6.9k relations): Cora is also a citation network of papers, equivalent to Citeseer except having seven categories.
- 3.
CAD (110k relations): The collective activity detection dataset (CAD) contains relations about people and the actions (waiting, queuing, walking, talking, etc.) they perform in a sequence of frames. $\textsc{frame}(\mathtt{B},\mathtt{F})$ states whether a box $\mathtt{B}$ (drawn around an actor in a frame) is in a specific frame $\mathtt{F}$; $\textsc{flabel}(\mathtt{F},\mathtt{A})$ states whether most actors in a frame perform action $\mathtt{A}$; $\textsc{doing}(\mathtt{B},\mathtt{A})$ states whether an actor in a box $\mathtt{B}$ performs action $\mathtt{A}$; $\textsc{close}(\mathtt{B}_{1},\mathtt{B}_{2})$ states whether two boxes in a frame are close to each other; $\textsc{same}(\mathtt{B}_{1},\mathtt{B}_{2})$ states whether two bounding boxes across different frames depict the same actor.
- 4.
Yelp (1.14M relations): The Yelp 2020 dataset contains user ratings on local businesses, information about business categories and friendships between users. We used the pre-processing script proposed by Kouki et al. () to create a dataset consisting of similaritems, similarusers, friends, averageitemrating, averageuserrating, and rating, describing relations between users and items.

Each dataset has seven splits. One split is used to test the learnt theories, while the other six are used to train the models. The reported results are the average over all permutations.

#### Baselines:

The first problem with finding baselines is that SPECTRUM is the first complete structure learner that integrates with PSL. Secondly, the baselines used to evaluate SPECTRUM on MLNs do not scale to datasets of the size considered in this section. For these reasons, we instead compare against the hand-engineered logical theories provided by PSL authors for these datasets. We used pslpython(^1^11https://pypi.org/project/pslpython/) to perform predictions using the learnt theories.

#### Citeseer and Cora:

For each category, we introduce the following relation $\textsc{HasCatX}(\mathtt{P})$, where X refers to the category. This allows us to find different rules for different categories. For each dataset, SPECTRUM finds the following rules:

$$ $\displaystyle\begin{split}\textsc{HasCat}(\mathtt{P}_{1},c)\wedge\textsc{Link} (\mathtt{P}_{1},\mathtt{P}_{2})\rightarrow\textsc{HasCat}(\mathtt{P}_{2},c),\\ \end{split}$ $$

for every $c\in\{1,\dots,6\}$ for Citesser and $c\in\{1,\dots,7\}$ for Cora.
Importantly, the engineering back to constants for the categories, e.g. $\textsc{HasCat1}(\mathtt{P})$ to $\textsc{HasCat}(\mathtt{P}_{1},1)$, is implemented in SPECTRUM, and can be applied for any categorical value. This automatic translation is very useful in classification tasks.

#### CAD:

We perform pre-processing akin to Citeseer and Cora and introduce $\textsc{doingX}(\mathtt{B})$ relations for each action X. SPECTRUM then finds the same 21 rules as hand-engineered by London et al. (). Namely, we get the following three rules for every action $a\in\{\textnormal{crossing, waiting, queuing, walking, talking, dancing,
jogging}\}$:

$$ $\displaystyle\begin{split}&\textsc{frame}(\mathtt{B},\mathtt{F})\wedge\textsc{ flabel}(\mathtt{F},a)\rightarrow\textsc{doing}(\mathtt{B},a)\\ &\textsc{doing}(\mathtt{B}_{1},a)\wedge\textsc{close}(\mathtt{B}_{1},\mathtt{B }_{2})\rightarrow\textsc{doing}(\mathtt{B}_{2},a)\\ &\textsc{doing}(\mathtt{B}_{1},a)\wedge\textsc{same}(\mathtt{B}_{1},\mathtt{B} _{2})\rightarrow\textsc{doing}(\mathtt{B}_{2},a)\\ \end{split}$ $$

#### Yelp:

We split the rating relations into ratinghigh and ratinglow to see whether SPECTRUM identifies differences between how high and low ratings are connected.
We find the following six rules:

$$ $\displaystyle\begin{split}&\textsc{ratingX}(\mathtt{U}_{1},\mathtt{I})\wedge \textsc{similarusers}(\mathtt{U}_{1},\mathtt{U}_{2})\rightarrow\textsc{ratingX }(\mathtt{U}_{2},\mathtt{I})\\ &\textsc{ratingX}(\mathtt{U},\mathtt{I}_{1})\wedge\textsc{similaritems}( \mathtt{I}_{1},\mathtt{U}_{2})\rightarrow\textsc{ratingX}(\mathtt{U},\mathtt{I }_{2})\\ &\textsc{ratingX}(\mathtt{U}_{1},\mathtt{I})\wedge\textsc{friends}(\mathtt{U}_ {1},\mathtt{U}_{2})\rightarrow\textsc{ratingX}(\mathtt{U}_{2},\mathtt{I}),\end {split}$ $$

where $X\in\{\textnormal{high},\textnormal{low}\}$.
The only rules hand-engineered by Kouki et al. () that SPECTRUM cannot find are

$$ $\displaystyle\begin{split}\textsc{averageitemrating}(\mathtt{I})& \leftrightarrow\textsc{rating}(\mathtt{U},\mathtt{I})\\ \textsc{averageuserrating}(\mathtt{U})&\leftrightarrow\textsc{rating}(\mathtt{ U},\mathtt{I})\;,\end{split}$ $$

since these rules are not term-constrained.

#### Scaling:

We report the structure learning times for each dataset in Table 2.
As expected, the runtime increases roughly linearly with the dataset size. Note that for the CAD experiments, we used $M=60$ instead of $M=30$ because of the proportionally larger number of different predicates in that dataset. Importantly, note that SPECTRUM can process $\sim 10^{6}$ facts in the same time that PRISM and LSM can process only $\sim 10^{3}$ facts (Table 1). This demonstrates how SPECTRUM successfully overcomes the scalability issues of prior art.

**Table 2: Comparison of runtime across datasets of varying size.**
|  | CITESEER | CORA | CAD | YELP |
| --- | --- | --- | --- | --- |
| Dataset Size | 6800 | 6950 | $\sim$ 110k | $\sim$ 1.14M |
| Training Time(s) | 2.08 $\pm$ 0.02 | 2.44 $\pm$ 0.02 | 84 $\pm$ 0.5 | 348 $\pm$ 2 |

## 8 Related work

#### Markov logic networks.

State-of-the-art structure learning approaches proceed in two steps - identification of patterns and optimisation. The different structure learning techniques for MLNs can be split into two groups: (1) methods for which patterns are user-defined and (2) methods for which patterns are identified automatically in the data.
The first technique proposed in group (1) was *bottom-up structure learning* (Mihalkova & Mooney, ).
This technique relied on user-defined patterns to form simple formulae that compose to form more complex ones.
Another technique in this group is *BOOSTR* (Khot et al., ), which simultaneously learns the rules and their weights, using functional gradient boosting (Friedman, ). While showing promising scalability, the quality of the theories learnt by BOOSTR drastically decreases in the absence of user-defined patterns (Feldstein et al., ). The inherent limitation of the above line of research is that these frameworks still require domain expertise from the user when defining patterns.
The current state-of-the-art that does not require user-defined patterns is *LSM* (Kok & Domingos, ). LSM identifies patterns by running random walks over a hypergraph representation of the data.
A major limitation of LSM is that it lacks guarantees on the quality of the mined patterns. *PRISM* is an efficient pattern-mining technique with theoretical guarantees on the quality of mined patterns, solving the above limitation (Feldstein et al., ).
Our empirical results show that SPECTRUM scales significantly better than any of the techniques mentioned above, without requiring any domain expertise as patterns are mined automatically. In addition, inspired by Feldstein et al. (), we provide $\varepsilon$-uncertainty guarantees, which, in contrast to PRISM, are guarantees on the utility of the output theory rather than just the patterns.

#### Inductive logic programming.

A popular family of techniques for learning Datalog theories is *inductive logic programming* (ILP), e.g. *FOIL* (Quinlan, ), *MDIE* (Muggleton, ) and *Inspire* (Schüller & Benz, ).
Given a database $\mathcal{D}$, a set of positive facts $E^{+}$ and a set of negative facts $E^{-}$, ILP-based techniques work by computing a theory that along with $\mathcal{D}$ entails all facts in $E^{+}$ and no fact in $E^{-}$.
*MetaAbd* (Dai & Muggleton, ) mixes logical abduction (i.e., backward reasoning) (Kakas, ) with ILP to simultaneously learn a logical theory and train a neural classifier. A recent line of research proposed formulations of ILP in which part of the computation can be differentiated and, hence, (part of) the learning is done through backpropagation. For example, Evans & Grefenstette () introduced $\delta$ILP which employs the semantics of fuzzy logic for interpreting rules. Sen et al. () proposed a similar ILP technique based on logical neural networks (Riegel et al., ).
All ILP-based techniques require users to provide the patterns of the formulae to be mined. The above requirement, along with issues regarding scalability (Evans & Grefenstette, ), limits the applicability of ILP techniques in large and complex datasets.

## 9 Conclusions

A major point of criticism against neurosymbolic techniques and logical models is the need for domain expertise (Feldstein et al., ; Huang et al., ; Li et al., ). This work tackles the scalability issue of learning logical models from data, mining accurate logical theories in minutes for datasets with millions of instances, thus making
the development of a logical model a simple and fast process.
Therefore, we see our work as having the potential to increase the adoption of neurosymbolic frameworks. In addition, learning logical models improves explainability by extracting knowledge from data that is interpretable by a domain expert.

There are several directions for future research.
First, the pattern mining algorithm could be generalised to relations with higher arity. Second, the pattern mining algorithm could be extended to require fewer restrictions on the shape of the rules. Finally, since the rules we learn are model agnostic, we plan to apply our technique to other logical frameworks, in addition to MLNs and PSL, such as Problog (De Raedt et al., ).

## Appendix A Proof of Theoretical Properties of Pattern Mining

In this section, we prove Theorems 5, 6, and 7 and justify Remark 2.
We start with some preliminary definitions before proceeding with the proof.

#### Definitions and notation.

The *$D$-neighbourhood of a node $v_{i}$* is the set of all nodes that are a distance less than or equal to $D$ from $v_{i}$. The *$D$-neighbourhood length $l$ patterns of a node $v_{i}$*, denoted $\mathcal{P}_{D,l}(v_{i})$, is the set of all connected patterns of length $l$ that have a grounding that includes $v_{i}$, and whose remaining nodes in the grounding also occur within the $D$-neighbourhood of $v_{i}$. The *$D$-neighbourhood length $l$ pattern distribution of $v_{i}$* is the function that maps from $\mathcal{P}_{D,l}(v_{i})$ to the number of groundings of that pattern within the $D$-neighbourhood of $v_{i}$ that include $v_{i}$. The *$D$-neighbourhood length $l$ pattern probability distribution of $v_{i}$*, denoted $P^{(l)}_{i}$, is the probability distribution obtained by normalising this distribution.

### A.1 Proof of Theorem 5

###### Proof.

We prove this theorem by proving the two statements individually:

- S1:
Algorithm 1 finds all patterns of length $l\leq D$ that only involve the source node and other $N$-close nodes.
- S2:
For patterns involving nodes that are not $N$-close, Algorithm 1 finds them with a probability larger than when running random walks.

###### Proof.

#### Statement 1:

Consider a node $v^{\prime}$ that is a distance $l\leq D$ away from a source node $v_{0}=v_{i_{0}}$ and consider a generic path of length $l$ from $v_{i_{0}}$ to $v^{\prime}=v_{i_{l}}$, $(v_{i_{0}},e_{i_{0}},\dots,e_{i_{l-1}},v_{i_{l}})$.

First, notice that if $N\geq|\mathcal{E}^{\prime}|=|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}
(v_{i_{0}})|$, then the edge $e_{i_{0}}$ will certainly be discovered by Algorithm 1 (selection step, lines 1-1). Similarly, for the second edge $e_{i_{1}}$ to be found, we need the value of $n$ upon reaching node $v_{i_{1}}$ to satisfy $n\geq|\mathcal{E}^{\prime}|$ (selection step, lines 1-1). Note also that $|\mathcal{E}^{\prime}|\leq|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v
_{i_{1}})|-1$, since the previous incident edge to $v_{i_{1}}$ is excluded from the set $\mathcal{E^{\prime}}$ (line 1). Therefore, a sufficient condition for the edge $e_{i_{1}}$ to be included is $N\geq|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v_{i_{0}})|(|\mathsf{b
}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v_{i_{1}})|-1)$. Reasoning inductively, a sufficient condition for every edge in the path to be found by Algorithm 1 is

$$ $\displaystyle N\geq|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v_{i_{0} })|\prod\limits_{j=1}^{l-1}(|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}} (v_{i_{j}})|-1).$ (2) $$

If this holds for all possible length $l$ paths between $v_{i_{0}}$ and $v_{i_{l}}$, then all of those paths will be discovered. This is equivalent to the statement that $v_{i_{l}}$ is $N$-close to $v_{i_{0}}$. Therefore, for any node that is $N$-close to $v_{i_{0}}$ (and is a distance $l$ from $v_{i_{0}}$), all possible length $l$ paths leading to that node will be found. Since any connected patterns is a subsets of a path, all possible patterns of length $l\in\{1,2,\dots,D\}$ have been found by Algorithm 1, thus completing the proof.

#### Statement 2:

First, notice that if a node is not $N$-close, then there is still a chance that it could be found due to random selection. This is because the smallest value of $n$ is $1$ and if $n<|\mathcal{E}^{\prime}|$ then we proceed by choosing the next edge in the path uniform randomly (line 1). Worst-case, $\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v_{i_{0}})|\geq N$, in which case the algorithm runs $N$ different paths where each edge is chosen at random. This is almost equivalent to running $N$ random walks, with the difference that Algorithm 1 does not allow backtracking or visiting previously encountered nodes, which increases the probability of finding novel nodes compared to independent random walks. Thus, the probability that a node is found using Algorithm 1 is strictly larger than when running $N$ independent random walks from $v_{0}$.

∎

### A.2 Proof of Theorem 6

###### Proof.

We prove this by partitioning the possibilities into three cases and proving that the upper bound formula is true in all cases.

Case 1 – every node in the $D$-neighbourhood of $v_{0}$ is $N$-close to $v_{0}$: In this case, the number of calls to NextStep is given by the total number of selections of binary edges (i.e. the cumulative sum of $|\mathcal{E}^{\prime}|$ every time it is computed). Recall, from the discussion in the proof of Theorem 5, that for node $v_{0}$, $|\mathcal{E}^{\prime}|\leq|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v
_{0})|$, and for all other nodes $v_{i}$, $|\mathcal{E^{\prime}}|\leq|\mathsf{b}_{\overline{\mathcal{G}}_{\mathcal{D}}}(v
_{i})|-1$. Therefore, the sum of $|\mathcal{E}^{\prime}|$ is upper bounded by the sum of the RHSs of these inequalities. Summing over all nodes gives the quantity in the left-hand argument of the minimum function in Theorem 6(^2^22In practice, the true number of recursions is likely to be considerably less than this, due to the avoidance of previously explored edges when passing binaries onto the next step (line 1).). Note that, in this case, the quantity in the right-hand argument, $ND$, is strictly larger since this is the maximum computation when running $N$ paths of length $D$ without avoiding previously encountered edges. The minimum therefore gives a valid upper bound.

Case 2 – no node (other than the source node) exists in the $D$-neighbourhood of $v_{0}$ that is $N$-close to $v_{0}$: In this case, $N$ recursions are called in the first step, and each following recursion will call one recursion until the final depth $D$ is reached, totalling $ND$ recursions, which is the right-hand argument of the minimum function in Theorem 6. In this case the LHS is actually larger than the RHS, since the branching factor of paths is strictly larger at the first step. The minimum therefore gives a valid upper bound.

Case 3 – some nodes are $N$-close and other nodes are not: In this case, the number of recursions is strictly less than the left-hand argument of the minimum function in Theorem 6, for if it wasn’t, then by definition every node would be $N$-close (contradiction). Likewise, it is also strictly less than $ND$, since this is the maximum computation when running $N$ paths of length $D$ without avoiding previously encountered edges. The minimum of the two is therefore also a valid upper bound.

Therefore, in all possible cases, the minimum of these two quantities gives a valid upper bound for the number of recursions, and thus the computational complexity, of Algorithm 1.
∎

###### Proof.

### A.3 Proof of Theorem 7

###### Proof.

We will prove the theorem in three stages:

- S1:
We derive an upper bound, $N(\varepsilon^{\prime})$, on the number of purely random walks required to achieve $\varepsilon^{\prime}$-uncertainty of the top $M$ pattern probabilities;
- S2:
We derive the corresponding $N(\varepsilon)$ required to achieve $\varepsilon$-uncertainty in the utility of an arbitrary set of rules whose head pattern, body pattern and rule patterns belong to these top $M$ patterns, under purely random walks;
- S3:
We prove that running Algorithm 1 with $N=N(\varepsilon)$ leads to a strictly lower $\varepsilon$-uncertainty for this rule utility than when using purely random walks, thus $N(\varepsilon)$ satisfies the theorem claim.

Stage 1 of the proof is an adaptation of a similar proof for $\varepsilon$-uncertainty of path probabilities of random walks on hypergraphs by Feldstein et al. Feldstein et al. ().

Stage 1
Throughout this proof, we will consider pattern probabilities within the $D$-neighbourhood of nodes, where $D$ is fixed by Algorithm 1.

Given a node $v_{i}\in\mathcal{D}_{G}$, let $P_{i}^{(l)}(\mathcal{G}_{k})$ denote the pattern probability of the $k^{th}$ most common pattern in the $D$-neighbourhood length $l$ patterns of $v_{i}$ (note that the constraints we make on rule patterns in Section 6.1 means that we can bound $l\leq 2D+1$, where $l$ can exceed $D$ due to the presence of unary predicates in the rule pattern). The Ziphian assumption implies that

$$ $P_{i}^{(l)}(\mathcal{G}_{k})=\frac{1}{kZ},$ (3) $$

where $Z=\sum_{k=1}^{|\mathcal{P}_{D,l}(v_{i})|}\frac{1}{k}$ is the normalisation constant.

Consider running $N$ random walks from $v_{i}$ without backtracking, and up to a maximum depth of $D$ (c.f. Algorithm 1). Since the walks are uniform random, a partial walk up to step $l\leq 2D+1$ yields a random sample from the $D$-neighbourhood length $l$ pattern probability distribution of $v_{i}$. Denote by $\hat{C}^{(l)}_{i,N}(\mathcal{G}_{k})$ the number of times that the $k^{th}$ most probable pattern, $\mathcal{G}_{k}$, was sampled after running all $N$ random walks. By independence of the random walks, the quantity $\hat{C}^{(l)}_{i,N}(\mathcal{G}_{k})$ is a binomially distributed random variable with

$$ $\mathbb{E}\left[\hat{C}^{(l)}_{i,N}(\mathcal{G}_{k})\right]=NP_{i}^{(l)}( \mathcal{G}_{k});\quad\text{Var}\left[\hat{C}^{(l)}_{i,N}(\mathcal{G}_{k}) \right]=NP_{i}^{(l)}(\mathcal{G}_{k})(1-P_{i}^{(l)}(\mathcal{G}_{k})).$ $$

It follows that the pattern probability estimate $\hat{P}^{N}_{i}(\mathcal{G}_{k}^{(l)})\vcentcolon=\hat{C}^{(l)}_{i,N}(\mathcal
{G}_{k})/N$ has fractional uncertainty $\epsilon(\mathcal{G}_{k})$ given by

$$ $\begin{split}\epsilon\left(\mathcal{G}_{k}\right)\vcentcolon&=\frac{\sqrt{ \text{Var}\left[\hat{P}^{N}_{i}(\mathcal{G}_{k}^{(l)})\right]}}{\mathbb{E} \left[\hat{P}^{N}_{i}(\mathcal{G}_{k}^{(l)})\right]}=\sqrt{\frac{1-P_{i}^{(l)} (\mathcal{G}_{k})}{NP_{i}^{(l)}(\mathcal{G}_{k})}}\\ &=\sqrt{\frac{k\left(\sum_{m=1}^{|\mathcal{P}_{D,l}(v_{i})|}\frac{1}{m}\right) -1}{N}},\end{split}$ (4) $$

where in the second line we used the Ziphian assumption equation 3. Suppose further that we require that all pattern probabilities $P_{i}^{(l)}(\mathcal{G}_{k})$ up to the $M^{\text{th}}$ highest probability for that length have $\varepsilon^{\prime}$-uncertainty, i.e.

$$ $\varepsilon^{\prime}=\max_{k\in\{1,2,\dots,M\}}\epsilon(\mathcal{G}_{k})= \epsilon(\mathcal{G}_{M}),$ $$

where $\mathcal{G}_{M}$ is the $M^{\textnormal{th}}$ most probable pattern, and so, upon rearranging,

$$ $N(\varepsilon^{\prime})=\frac{M\left(\sum_{m=1}^{|\mathcal{P}_{D,l}(v_{i})|} \frac{1}{m}\right)-1}{\varepsilon^{\prime 2}}.$ (5) $$

We have

$$ $N(\varepsilon^{\prime})\approx\frac{M\left(\gamma+\ln(|\mathcal{P}_{D,l}(v_{i} )|)\right)}{\varepsilon^{\prime 2}},$ (6) $$

where we used the log-integral approximation for the sum of harmonic numbers $\sum_{m=1}^{|\mathcal{P}_{D,l}(v_{i})|}\frac{1}{m}=\gamma+\ln(|\mathcal{P}_{D,
l}(v_{i})|)+\mathcal{O}\left(\frac{1}{|\mathcal{P}_{D,l}(v_{i})|}\right)$, where $\gamma\approx 0.577$ is the Euler-Mascheroni constant. Equation equation 6 gives an upper bound on the number of random walks required to achieve $\varepsilon^{\prime}$-uncertainty of the top $M$ most common pattern probabilities of length $l$ that occur in the $3$-neighbourhood of node $v_{i}$. Note that the exact value of $|\mathcal{P}_{D,l}(v_{i})|$ depends on the specifics of the dataset, however, in general, it would grow exponentially with the length $l$ due to a combinatorial explosion in the number of patterns Feldstein et al. (). This means that $N(\varepsilon^{\prime})$ scales as

$$ $N(\varepsilon^{\prime})\sim\mathcal{O}\left(\frac{Ml}{\varepsilon^{\prime 2}} \right).$ $$

If we want to ensure $\varepsilon^{\prime}$ uncertainty for patterns of all lengths $l\in\left\{1,2,\dots,2D+1\right\}$ then we conclude that $N(\varepsilon^{\prime})$ should scale as

$$ $N(\varepsilon^{\prime})\sim\mathcal{O}\left(\frac{MD}{\varepsilon^{\prime 2}} \right).$ $$

This concludes stage 1.

Stage 2 Assuming that the top $M$ most common pattern probabilities of length $l$ are $\varepsilon^{\prime}$-uncertain, for all $l\in\left\{1,2,\dots,2D+1\right\}$, we now derive an upper bound for the level of uncertainty of the utility of an arbitrary set of rules whose head patterns, body patterns and rule patterns belong to these top $M$ patterns.

Recall that the precision of a rule $\rho$ can be expressed as the ratio of the number of groundings of $\mathsf{head}(\rho)\wedge\mathsf{body}(\rho)$, to the number of groundings of $\mathsf{body}(\rho)$ in the data i.e.

$$ $\mathsf{P}(\rho)=\frac{|\bm{\overline{\mathcal{G}}}_{\mathsf{body}(\rho)\wedge \mathsf{head}(\rho)}|}{|\bm{\overline{\mathcal{G}}}_{\mathsf{body}(\rho)}|}.$ $$

Computing precision exactly would require exhaustively sampling the entire dataset. However, we can still obtain an unbiased estimate of precision, $\widehat{\mathsf{P}}(\rho)$, using the ratio of counts of these ground patterns from running random walks. Assuming that $\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ is a length $l$ pattern:

$$ $\widehat{\mathsf{P}}(\rho)=\frac{\sum_{v_{i}\in\overline{\mathcal{G}}_{ \mathcal{D}}}\hat{C}^{(l)}_{i,N}\left(\mathcal{G}_{\mathsf{body}(\rho)\wedge \mathsf{head}(\rho)}\right)}{\sum_{v_{i}\in\overline{\mathcal{G}}_{\mathcal{D} }}\hat{C}^{(l)}_{i,N}\left(\mathcal{G}_{\mathsf{body}(\rho)}\right)},$ $$

is an unbiased estimator for $\mathsf{P}(\rho)$. Assuming the rule’s head, body and rule patterns belong to the top $M$ patterns, then we know that the numerator and denominator both individually have $\varepsilon^{\prime}$-uncertainty so we have, in the worst case, that $\widehat{\mathsf{P}}(\rho)$ has $\varepsilon$-uncertainty where $\varepsilon=2\varepsilon^{\prime}$.

Next, we consider the estimate of the quantity $|\bm{\overline{\mathcal{G}}}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}^{
\mathsf{head}(\rho)={\overline{\alpha}}}|$, where $\overline{\alpha}$ is a grounding of the head of the rule in the data. For brevity, we call the size of this set the recall degree of $\overline{\alpha}$ given a rule, and denote it as $\mathsf{D}_{\rho}(\overline{\alpha})\vcentcolon=|\bm{\overline{\mathcal{G}}}_{
\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}^{\mathsf{head}(\rho)={\overline{
\alpha}}}|$. Consider an arbitrary fact $\overline{\alpha}$ in the data that is in the $D$-neighbourhood of node $v_{i}$, and is the head predicate of a rule whose pattern $\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ can be traversed, without backtracking, starting from $v_{i}$. The probability, $q$, that $\overline{\alpha}$ is not discovered as part of that rule after $N(\varepsilon^{\prime})$ random walks is given by

$$ $q=(1-p^{\prime})^{N(\varepsilon^{\prime})},$ $$

where in the above, $p^{\prime}$ is shorthand for $P_{i}^{(l)}(\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)})$. We have

$$ $\ln(q)=N(\varepsilon^{\prime})\ln(1-p^{\prime})<-N(\varepsilon^{\prime})p^{\prime}$ $$

and hence

$$ $q<e^{-N(\varepsilon^{\prime})p^{\prime}}.$ $$

But since, by the Ziphian assumption, $p^{\prime}>\frac{1}{Z\cdot M}\approx\frac{1}{M(\gamma+\ln P)}$, we have that $p^{\prime}N(\varepsilon^{\prime})>\frac{1}{\varepsilon^{\prime 2}}$ and hence

$$ $q<e^{-\frac{1}{\varepsilon^{\prime 2}}}.$ $$

The above inequality holds for arbitrary $v_{i}$, hence the expectation of the estimated recall degree satisfies

$$ $\mathsf{D}_{\rho}(\overline{\alpha})>\mathbb{E}[\widehat{\mathcal{D}}_{\rho}( \overline{\alpha})]>\mathsf{D}_{\rho}(\overline{\alpha})(1-e^{-\frac{1}{ \varepsilon^{\prime 2}}}),$ $$

where $\mathsf{D}_{\rho}(\overline{\alpha})$ is the true recall degree of $\overline{\alpha}$. Since $\varepsilon^{\prime}>e^{-\frac{1}{\varepsilon^{\prime 2}}}$ for all $0<\varepsilon^{\prime}<1$, we conclude that $\widehat{\mathcal{D}}_{\rho}(\overline{\alpha})$ has $\varepsilon^{\prime}$-uncertainty. Therefore, by the Taylor expansion, the estimated log-recall, $\ln(1+\widehat{\mathcal{D}}_{\rho}(\overline{\alpha}))$ also has $\varepsilon^{\prime}$ uncertainty, as does the estimated rule-set log-recall $\mathsf{R}(\bm{\rho}_{\alpha})=\ln\left(1+\sum_{\rho\in\bm{\rho}_{\alpha}}
\widehat{\mathcal{D}}_{\rho}(\overline{\alpha})\right)$.

Note that the symmetry factor $\mathsf{S}(\rho)$ is known exactly for every rule, as it is a topological property of the rule rather than a property of the data. For the same reason, the complexity factor $\mathsf{C}(\rho)$ is also known exactly. Finally, the Bayesian prior $\mathsf{B}(\rho)$ is also known exactly, since computing it requires summing over the data once, which we do once at the beginning of SPECTRUM, and this only takes linear time.

Using the above results, we conclude that the rule-set utility

$$ $\mathsf{U}(\bm{\rho})=\sum_{\alpha\in\bm{\alpha}}\left(\sum_{\rho\in\bm{\rho}_ {\alpha}}\frac{\mathsf{P}(\rho)\mathsf{S}(\rho)}{\mathsf{B}(\rho)}\right)\cdot \mathsf{R}(\bm{\rho}_{\alpha})\mathsf{C}(\bm{\rho}_{\alpha}),$ $$

has, by error propagation, worst case $\varepsilon$-uncertainty with $\varepsilon=3\varepsilon^{\prime}$.

Substituting $\varepsilon^{\prime}=\varepsilon/3$ into equation 6, we conclude that an upper bound on the number of random walks required to guarantee $\varepsilon$-uncertainty of the rule-set utility, $\mathsf{U}(\bm{\rho})$ (where all rules’ head patterns, body patterns and rule patterns belong to the $M$ most common patterns of their respective length) under random walks is given by

$$ $\displaystyle N(\varepsilon)=\frac{9M\left(\gamma+\ln(|\mathcal{P}_{D,l}(v_{i} )|)\right)}{\varepsilon^{2}}.$ (7) $$

Considering all patterns of length $l\in\left\{1,2,\dots,2D+1\right\}$ we see that this scales as

$$ $N(\varepsilon)\sim\mathcal{O}\left(\frac{MD}{\varepsilon^{2}}\right).$ $$

This concludes stage 2.

Stage 3 We consider now the Algorithm 1. Let $v_{i}$ denote the source node of a fragment mining run. Set $N=N(\varepsilon)$. Partition the $D$-neighbourhood of $v_{i}$ into two sets, $\mathcal{N}^{\text{close}}_{i}$ and $\mathcal{N}^{\text{far}}_{i}$ - nodes that are $N(\varepsilon)$-close and not $N(\varepsilon)$-close to $v_{i}$ respectively (Theorem 5). By the definition of $N$-close, setting $N=N(\varepsilon^{\prime})$ in Algorithm 1 guarantees that all patterns containing nodes exclusively with $\mathcal{N}^{\text{close}}_{i}$ are counted exactly, whereas patterns that contain nodes within $\mathcal{N}^{\text{far}}_{i}$ are, in the worst case not counted with a probability given by

$$ $q=(1-p^{\prime})^{N(\varepsilon^{\prime})},$ $$

with $p^{\prime}=P_{i}^{(l)}(\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(
\rho)})$, assuming that $\rho$ is a length $l$ rule.

Partitioning $\hat{C}^{(l)}_{i,N}\left(\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(
\rho)}\right)$ into close and far contributions, we can write

$$ $\hat{C}^{(l)}_{i,N}\left(\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}( \rho)}\right)=\hat{C}^{(l)}_{i,\text{close},N}\left(\mathcal{G}_{\mathsf{body} (\rho)\wedge\mathsf{head}(\rho)}\right)+\hat{C}^{(l)}_{i,\text{far},N}\left( \mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}\right).$ $$

In the above, by $\hat{C}^{(l)}_{i,\text{close},N}\left(\mathcal{G}_{\mathsf{body}(\rho)\wedge
\mathsf{head}(\rho)}\right)$ we mean the number of times the pattern $\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ was counted with nodes that are exclusively in the set $\mathcal{N}_{i}^{\text{close}}$. Similarly, $\hat{C}^{(l)}_{i,\text{far},N}\left(\mathcal{G}_{\mathsf{body}(\rho)\wedge
\mathsf{head}(\rho)}\right)$ is the number of times that $\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(\rho)}$ was counted with nodes that are in a mixture of $\mathcal{N}_{i}^{\text{close}}$ and $\mathcal{N}_{i}^{\text{far}}$. Note that $\hat{C}^{(l)}_{i,\text{close},N}\left(\mathcal{G}_{\mathsf{body}(\rho)\wedge
\mathsf{head}(\rho)}\right)$ is an exact count and has no uncertainty due to the exhaustive property of Algorithm 1 for $N$-close nodes.

Using the result from stage 2 of the proof, we know that $q<\varepsilon^{\prime}$ and hence $\hat{C}^{(l)}_{i,\text{far},N}\left(\mathcal{G}_{\mathsf{body}(\rho)\wedge
\mathsf{head}(\rho)}\right)$ has, worst case, $\varepsilon^{\prime}$-uncertainty and so $\hat{C}^{(l)}_{i,N}\left(\mathcal{G}_{\mathsf{body}(\rho)\wedge\mathsf{head}(
\rho)}\right)$ has strictly lower than $\varepsilon^{\prime}$-uncertainty. We conclude that pattern counts obtained from Algorithm 1 have a strictly lower uncertainty than pattern counts obtained from random walks for the same $N(\varepsilon^{\prime})$. Hence, by the result of stage 2, we can guarantee $\varepsilon$-uncertainty for the rule-set utility using Algorithm 1 with $N=N(\varepsilon)$ given by equation equation 7. The scaling law is, therefore, worst case,

$$ $N(\varepsilon)\sim\mathcal{O}\left(\frac{MD}{\varepsilon^{2}}\right),$ $$

and Algorithm 1 does strictly better than random walks. This concludes stage 3 and concludes the proof.

∎

###### Proof.

### A.4 Justification of Remark 2

In the above proof of Theorem 7 we considered the worst-case scenario, where we required $\varepsilon$-uncertainty of top-$M$ pattern fragments found locally around each node $v_{i}$ (c.f. stage 1 of the proof). In reality, in many datasets, rule fragments that appear in the $D$-neighourbood of one node, will also appear within the $D$-neighbourhoods of many other nodes in the data graph $\overline{\mathcal{G}}_{\mathcal{D}}$. The limiting case is the case of homogeneous data, where the pattern probabilities in the $D$-neighbourhood of every node in $\mathcal{D}_{G}$ are the same. In this scenario, it is the sum of pattern counts from running random walks from all nodes that needs to be connected to the notion of $\varepsilon$-uncertainty. For a dataset with $|V|$ nodes, this means that the number of random walks required to run from each individual node is smaller by a factor of $|V|$, i.e. $N(\varepsilon)\sim\mathcal{O}(MD/\varepsilon^{2}|V|)$, as stated in Remark 2.

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 3
presentation: 3
questions: How does the proposed method (SPECTRUM) compare to the prior work listed above?
soundness: 3
strengths: - The problem of scalable rule learning is highly important 
- SPECTRUM does appear to be more efficient and scalable as compared to baselines.
- The authors formally prove a number of properties of SPECTRUM including completeness and approximate optimality of the pattern mining phase
summary: This paper deals with the task of efficiently learning logical rules from large relational databases. This can be seen as structure learning for probabilistic (and neural) logical models and hence efficient rule learning is also an important problem in statistical relational and neuro symbolic AI. The authors approach this problem by proposing the SPECTRUM, an efficient rule learning algorithm based on a 2-phase process. The first phase is pattern mining; it involves finding frequent relational patterns from the database. The second phase is pattern optimization; it involves (greedily) finds the top-M rules according to an efficiently computable rule utility score. The authors prove completeness and approximate optimality of the pattern mining phase and derive a principled yet efficiently computable utility function to score theories. Once the rules are learned, they can be used to instantiate a statistical relational or neurosymbolic model. The authors consider the former case and specifically instantiate probabilistic soft logic (PSL) models. They compare SPECTRUM against NCRL (Cheng et al., 2023) and RNNlogic (Qu et al., 2021) on 5 knowledge graph completion databases. The results show that SPECTRUM outperforms the baselines especially on larger databases. The authors also compare SPECTRUM against MLN learning methods including LSM (Kok & Domingos, 2010), BOOSTR (Khot et al., 2015), and PRISM (Feldstein et al., 2023) on IMDB and WebKB databases, showing that SPECTRUM outperforms the baselines.
weaknesses: The paper is missing key related work and baselines:

1.	Poole et al., (2014) diagnose the scalability problems of MLNs.
2.	Gradient boosted Relational Dependency Networks (Natarajan et al., 2012) perform joint structure and parameter learning and have been shown to outperform MLNs
3.	B-RLR (Ramanan et al., 2021) learns Relational Logistic Regression models (Kazemi et al., 2014) using Functional Gradient boosting 
4.	NNRPT (Kaur et al., 2020) uses relational random walks to instantiate neural networks with rule-based parameter tying. 
5.	alpha-ILP (Shindo et al., 2023) uses k-beam search with a differentiable reasoner to learn rule weights.


Poole, D., Buchman, D., Kazemi, S. M., Kersting, K., & Natarajan, S. (2014). Population size extrapolation in relational probabilistic modelling. In Scalable Uncertainty Management: 8th International Conference, SUM 2014

Kaur, N., Kunapuli, G., Joshi, S., Kersting, K., & Natarajan, S. (2020). Neural networks for relational data. ILP.

Natarajan, S., Khot, T., Kersting, K., Gutmann, B., & Shavlik, J. (2012). Gradient-based boosting for statistical relational learning: The relational dependency network case. Machine Learning, 86

Shindo, H., Pfanschilling, V., Dhami, D. S., & Kersting, K. (2023). α ILP: thinking visual scenes as differentiable logic programs. Machine Learning, 112(5)

Ramanan, N., Kunapuli, G., Khot, T., Fatemi, B., Kazemi, S.M., Poole, D., Kersting, K. and Natarajan, S. (2021). Structure learning for relational logistic regression: an ensemble approach. Data Mining and Knowledge Discovery, 35

Kazemi, S.M., Buchman, D., Kersting, K., Natarajan, S. and Poole, D., (2014). Relational logistic regression. KR

---

confidence: 2
contribution: 3
initial_rating: 6
presentation: 2
questions: 1. For the definition of isomorphic, the notation $v_i$ represents a node in a graph in line 99. However, $v_i$ represents an edge in line 106. The ‘instantiations of a rule’ is not defined in line 163. In addition, the ‘symmetries’ in line 144 is not defined. 
2. When calculating the precision of a rule for example in line 983, what is the difference between ground patterns and substitutions which has a standard definition in the ILP community?  
3. There are some missing references and comparisons when defining metrics such as precision and recall for a rule. For some work [1,2,3], they also discussed precision, recall, rule length, etc. Can you evaluate some differences and similarities of your definition above the precision, recall, and complexity factor with them?

Reference:

[1] Tim Rocktäschel, Sebastian Riedel: End-to-end Differentiable Proving. NIPS 2017: 3788-3800 

[2] Kun Gao, Katsumi Inoue, Yongzhi Cao, Hanpin Wang: A differentiable first-order rule learner for inductive logic programming. Artif. Intell. 331: 104108 (2024) 

[3] Litao Qiao, Weijia Wang, Bill Lin: Learning Accurate and Interpretable Decision Rule Sets from Neural Networks. AAAI 2021: 4303-4311
soundness: 3
strengths: 1. The structure of the paper is easy to understand;
2. The authors proposed well-designed metrics to evaluate the symbolic rule. 
3. The proposed ILP algorithms are analyzed in terms of complexity and completeness. In addition, the experiments are conducted explicitly.
summary: This paper discussed a method to evaluate the quality of a symbolic first-order rule. In addition, the paper also proposed a new method for mining rules from data. The measurement is cheap, the rule learning is in linear-time complexity, and the finding best utility algorithm is in quadratic-time complexity. The experiment results indicate that the model can be used in the ILP domain for learning rules and the model can perform knowledge graph completion for larger knowledge graphs such as the FB15K-237 dataset.
weaknesses: 1. Some definitions are not clear to present. Please see the question 1. 
2. For the scalability of the proposed ILP model, there are no results to indicate SPECTRUM can extract rules from very large knowledge graphs such as UMLS, Kinship, FB15K-237, etc. However, the  NeuralLP (Yang et al., 2017) and DRUM (Sadeghian et al., 2019) did learn symbolic rules from these large datasets.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: Why use a quadratic-time greedy optimisation algorithm after getting M candidate rules? Most of the time, M is in the range of tens to hundreds. What will happen if a more precise optimisation algorithm is used to select the best subset? Will it really become a bottleneck for scalability (because your scalability focuses on the size of the data rather than M)?
soundness: 4
strengths: 1. The paper has a well-defined motivation for tackling scalability issues in probabilistic logic models, with concise and clear explanations.

2.  The authors provide theoretical guarantees on the computational cost required for a certain error bound on the utility estimates.

3.  Experimental results show that SPECTRUM significantly outperforms previous methods in both efficiency and predictive accuracy, highlighting its practical advantages
summary: This paper introduces a framework called SPECTRUM, which focuses on efficiently learning probabilistic logical models to address scalability challenges in neurosymbolic AI. SPECTRUM incorporates a low-cost utility measure for assessing the predictive performance of logical models. Additionally, it employs a linear-time pattern mining algorithm to identify common structures within data and uses a fast sorting algorithm to optimize rule selection. Experimental results demonstrate that SPECTRUM can quickly construct efficient logical models across various tasks, significantly reducing computation time while surpassing existing methods in terms of interpretability and accuracy.
weaknesses: 1. The SPECTRUM framework itself does not learn probabilistic rules, and the emphasis on "probabilistic" throughout, including in the title, seems somewhat overstated.

2. The authors' introduction of Inductive Logic Programming and Differentiable Rule Learning in the related work section appears insufficient. Some advanced differentiable rule learning algorithms have less reliance on templates and offer better scalability compared to traditional methods[1]; a comparison with these should be included.

[1] Glanois, Claire, et al. "Neuro-symbolic hierarchical rule induction." International Conference on Machine Learning. PMLR, 2022.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: Please see the questions above.
soundness: 2
strengths: - This paper is well-written and well-structured. The reader can quickly understand the main idea of the paper. 
- The proposed method operates on CPU while still getting comparable results against other methods, demonstrating strong application value in the industry.
summary: This paper aims at rule mining in the neuro-symbolic (NS)  domain. Rule mining is critical in NS methods which typically requires domain-specific rules. To address this, the paper defines several criteria to measure the utility of various rules and develop an algorithm for fast rule mining. They investigate the performance in various datasets: for MLN datasets, the method successfully mined most rules; for graph completion datasets, the method effectively outperforms RNNLogic and NCRL, two typical NS methods.
weaknesses: I have several questions:

-  The "precision" measure seems only to consider horn-clause, however, in MLNs, we also consider more general rules. In other words, 'a->b' also means 'not b-> not a'. Considering 'not b -> not a' is also important in some scenarios. How do you address this problem?
- Throughout the paper, I do not find a reference of AMIE [1], a fast and effective method of rule mining also using heuristic measurements. How do you compare with AMIE? 
- How do you leverage the mined rules in the link completion tasks? Do you use some linear models? I did not find the details of the task in sec 7.2.

[1] AMIE3: https://luisgalarraga.de/docs/amie3.pdf

Meta-review: This paper introduces a framework called SPECTRUM, a method to learn  probabilistic logical model from large relational databases. In terms of the proposed method itself, more than half of the reviewers share the appreciation of its technical contribution. Furthermore, the method first proposes a metric to evaluate the performance and then employs a linear-time pattern mining algorithm to identify common structures and uses a sorting algorithm to do the selection. The linear-time complexity has theoretical guarantee, which is a plus. However, firstly, this paper is not well contextualized; a few important references are not well discussed.  Second, the experiment results are not enough to convince readers. I would encourage the paper to, instead of spending more time on running experiments, put more efforts to carefully discuss about its baselines, and build a stronger case about its evaluation protocol. After that, to re-evaluate what experiments remain and what need to be added or ru-run.

Decision: Reject