← Blog

Tutorial: Knowledge Discovery and Interpretable Inference in Digital Twins via Rule Learning

Tutorial: Knowledge Discovery and Interpretable Inference in Digital Twins via Rule Learning

This blog post is the tutorial we prepared for ICSOC 2026 together with Victoria Degeler, turned into a page.

Abstract

Digital twins of cyber-physical systems, especially of critical infrastructure, require human-understandable decision-making pipelines. One prominent way to create such pipelines is via discovering patterns in the form of logical rules that describe the relations in the data, and then making decisions based on these human-understandable patterns. Rule discovery has been dominated by rule mining methods that are symbolic algorithms built on co-occurrence counting. This leads to many problems including rule explosion on high-dimensional datasets and rule interestingness where methods find many spurious patterns.

Throughout several papers, we reframed rule discovery as a neurosymbolic rule learning problem rather than mining. We proposed that rather than symbolic algorithms, we can train neural networks to learn a concise set of interesting rules. We also show that you can re-purpose many predictive models for rule learning via our TabProbe method, including the tabular foundation models such as TabPFN, as well as tree-based models such as RandomForest or XGBoost. In this blog post, you will see hands-on how neurosymbolic rule learning can be used for both knowledge discovery and interpretable inference in digital twins, with an example on water distribution networks. Our examples include both a specialized neurosymbolic rule learning architecture, PyAerial , as well as TabProbe that allows you to learn rules with your own models.

Table of Contents

  1. What data do we have?
  2. What is the task of rule learning and why should you care?
  3. How to learn only a small set of interesting rules with Aerial+ and PyAerial?
  4. How to further evaluate whether the rules are good?
  5. Can I use my own model instead of Autoencoders?
  6. What else can we do?

Running the code

The easiest way to run the notebook is Google Colab, without installing anything locally: open the notebook in Colab. Or run it on your own machine, all the code is at https://github.com/DiTEC-project/icsoc_tutorial:

git clone https://github.com/DiTEC-project/icsoc_tutorial.git
cd icsoc_tutorial
jupyter notebook rule_learning_tutorial.ipynb

The code cells on this page are not runnable. The figures and the tables below are the outputs of the notebook, and to try the changes the notebook suggests (e.g., another row, another model or another rule strength threshold), use Colab. The leak detection in Part 4 is still interactive here, you can play it and click on the alarms to see which rules raised them.

The notebook calls a number of helper functions for preparing the data, plotting and showing tables. These are not the interesting part, so they are not printed here. Under the code cells, there is a Source line that points to where each function is defined, either in the tutorial repository, in PyAerial or in TabProbe. In the code, tu is the tutorial’s helper module (tutorial_utils.py), and seed(0) fixes the random seeds so that the results are reproducible.


Part 1 · What data do we have?

One year of sensor readings from a water network with two leakages.

Where are the sensors and the leaks? LeakDB [1] simulates leaks in the Hanoi water network. We use the 18 sensors that are at most 2 pipes away from a leak itself.

scenario = preprocess.download("Scenario-10")
table = preprocess.build_table(scenario, window="6h", hops=2)
sensors = [c for c in table.columns if c not in ("timestamp", "leakage")]

tu.draw_network(scenario, sensors)
Hanoi water network with the sensors and the two leaks

Source: preprocess.download · preprocess.build_table · tu.draw_network

How to represent the data? We represent the sensor data as a table, where the columns are the sensors and the rows are the measurements per timeframe. In this tutorial, we used 6 hours of timeframes and aggregated the data with an average function.

Leakages are added as a separate column. If it has a value of 1, that means there is a leakage in the system.

Below: the pressure at leak node 28 and the flow in pipe 29, which feeds that node.

raw = preprocess.read_sensors(scenario)
tu.plot_aggregation(raw, table, ["node_28_pressure", "pipe_29_flow"], scenario)
Raw readings and 6-hour averages of node 28 pressure and pipe 29 flow

Source: preprocess.read_sensors · tu.plot_aggregation

cols = ["timestamp", "node_28_pressure", "pipe_29_flow", "node_12_pressure", "leakage"]
tu.show(table.loc[562:567, cols].round(1))   # 3 of the 18 sensors, as the leak at node 28 starts
#timestampnode_28_pressurepipe_29_flownode_12_pressureleakage
56321 May 12:0062.5258.063.50
56421 May 18:0062.7253.263.70
56522 May 00:0067.8129.068.00
56622 May 06:0061.0283.862.30
56722 May 12:0036.51059.662.21
56822 May 18:0023.81446.961.51

Source: tu.show

Why low / mid / high? Rules speak in categories, not numbers, so each reading becomes low, mid or high.

data = tu.discretize(table)
tu.show(data.loc[562:567, cols[1:]])
#node_28_pressurepipe_29_flownode_12_pressureleakage
563highlowhighno
564highlowhighno
565highlowhighno
566highlowhighno
567midhighhighyes
568lowhighhighyes

Source: tu.discretize · tu.show

Part 2 · What is the task of rule learning and why should you care?

What is a rule?

    IF pipe_29_flow = high THEN leakage = yes

  • support: how often IF and THEN are true together
  • confidence: how often THEN is true, when IF is true

How many rules could there be? Even for our small table:

possible = tu.count_possible_rules(data, max_len=3)
all_rules = tu.mine_all_rules(data, max_len=2)          # classical exhaustive search
strong = all_rules[all_rules.confidence >= 0.8]

tu.plot_rule_explosion(possible, len(strong))
Number of possible rules versus strong rules found by exhaustive search

Source: tu.count_possible_rules · tu.mine_all_rules · tu.plot_rule_explosion

Is a rule with high confidence always useful? No. E.g., we also have to compare it with the base rate: how often THEN is true anyway.

tu.explain_examples(data, [
    ({"pipe_11_flow": "low"},        ("node_12_pressure", "high"), "mostly high anyway"),
    ({"node_12_pressure": "high"},   ("pipe_10_flow", "low"),      "almost always low anyway"),
    ({"pipe_29_flow": "high"},       ("leakage", "yes"),           "confidence far above base rate"),
    ({"pipe_10_flow": "low", "pipe_29_flow": "high"}, ("leakage", "yes"), "repeats the rule above"),
], highlight=3)
#RuleSupportConfidenceBase rateWhy
1pipe_11_flow = low → node_12_pressure = high86%88%86%mostly high anyway
2node_12_pressure = high → pipe_10_flow = low86%100%98%almost always low anyway
3pipe_29_flow = high → leakage = yes42%100%44%confidence far above base rate
4pipe_10_flow = low AND pipe_29_flow = high → leakage = yes42%100%44%repeats the rule above

Source: tu.explain_examples

So we want a few rules that tell us something new, without listing millions of them.

Part 3 · How to learn only a small set of interesting rules with Aerial+ and PyAerial?

A neural network learns the patterns in the table, and then we probe it with queries [2, 3].

How Aerial+ works

Let’s try it: learn rules that say something about leakage.

from aerial import model, rule_extraction

seed(0)
autoencoder = model.train(data, layer_dims=[16], epochs=2, show_progress=False)
rules = rule_extraction.generate_rules(autoencoder, target_classes=["leakage"])["rules"]

print(len(rules), "rules")
tu.rules_table(rules, n=20)
88 rules
#IFTHENsupportconfidence
1pipe_23_flow = lowleakage = no46%97%
2pipe_29_flow = highleakage = yes42%100%
3node_28_pressure = lowleakage = yes42%100%
4node_29_pressure = lowleakage = yes42%100%
5pipe_30_flow = lowleakage = yes42%100%
6pipe_31_flow = lowleakage = yes42%100%
7pipe_23_flow = highleakage = yes32%100%
8node_28_pressure = high AND pipe_31_flow = highleakage = no56%97%
9node_28_pressure = high AND pipe_30_flow = highleakage = no56%97%
10node_28_pressure = high AND node_29_pressure = highleakage = no56%97%
11node_28_pressure = high AND pipe_29_flow = lowleakage = no56%97%
12pipe_30_flow = high AND pipe_31_flow = highleakage = no56%97%
13node_29_pressure = high AND pipe_31_flow = highleakage = no56%97%
14pipe_29_flow = low AND pipe_31_flow = highleakage = no56%97%
15node_29_pressure = high AND pipe_30_flow = highleakage = no56%97%
16pipe_29_flow = low AND pipe_30_flow = highleakage = no56%97%
17node_29_pressure = high AND pipe_29_flow = lowleakage = no56%97%
18node_12_pressure = high AND pipe_31_flow = highleakage = no56%100%
19node_12_pressure = high AND pipe_30_flow = highleakage = no56%100%
20node_13_pressure = high AND node_28_pressure = highleakage = no55%100%

Source: model.train · rule_extraction.generate_rules · tu.rules_table

What do support and confidence look like? Each lane shows when that side of the rule is true. Try another rule by changing row.

row = 18   # any row number (#) from the table above
tu.plot_rule_timeline(data, table.timestamp, tu.rule_at(rules, row))
Timeline of when the IF and THEN sides of a rule are true

Source: tu.rule_at · tu.plot_rule_timeline

Which rules describe the leaks? We ask only for rules that end in leakage = yes.

leak_rules = rule_extraction.generate_rules(autoencoder, target_classes=[{"leakage": "yes"}])["rules"]

print(len(leak_rules), "leakage rules")
tu.rules_table(leak_rules, n=10)
30 leakage rules
#IFTHENsupportconfidence
1pipe_29_flow = highleakage = yes42%100%
2node_28_pressure = lowleakage = yes42%100%
3node_29_pressure = lowleakage = yes42%100%
4pipe_30_flow = lowleakage = yes42%100%
5pipe_31_flow = lowleakage = yes42%100%
6pipe_23_flow = highleakage = yes32%100%
7pipe_11_flow = low AND pipe_29_flow = highleakage = yes42%100%
8pipe_10_flow = low AND pipe_29_flow = highleakage = yes42%100%
9node_28_pressure = low AND pipe_11_flow = lowleakage = yes42%100%
10pipe_11_flow = low AND pipe_31_flow = lowleakage = yes42%100%

Source: rule_extraction.generate_rules · tu.rules_table

Do they make sense? They point to the sensors around the leaks, so we can check every rule on the map.

tu.draw_network(scenario, sensors, highlight=tu.rule_sensors(leak_rules), title_text="Sensors used in the leak rules")
Sensors used in the leak rules on the network map

Source: tu.rule_sensors · tu.draw_network

Can I control how many rules I get? Yes. The autoencoder squeezes each row through a bottleneck: the smaller it is, the fewer patterns survive.

Other settings: min_rule_frequency (≈ support), min_rule_strength (≈ confidence), max_antecedents (rule length).

by_size = {}
for size in [4, 16, 32]:
    seed(0)
    ae = model.train(data, layer_dims=[size], epochs=2, show_progress=False)
    by_size[size] = rule_extraction.generate_rules(ae, target_classes=[{"leakage": "yes"}])["rules"]

tu.plot_bottleneck(by_size)
Number of leak rules for different bottleneck sizes

Source: model.train · rule_extraction.generate_rules · tu.plot_bottleneck

tu.rules_table(by_size[4])
#IFTHENsupportconfidence
1node_29_pressure = low AND pipe_30_flow = lowleakage = yes42%100%
2pipe_30_flow = low AND pipe_31_flow = lowleakage = yes42%100%
3pipe_29_flow = high AND pipe_30_flow = lowleakage = yes42%100%
4node_28_pressure = low AND node_29_pressure = lowleakage = yes42%100%
5node_29_pressure = low AND pipe_31_flow = lowleakage = yes42%100%
6node_29_pressure = low AND pipe_29_flow = highleakage = yes42%100%
7node_28_pressure = low AND pipe_31_flow = lowleakage = yes42%100%
8node_28_pressure = low AND pipe_29_flow = highleakage = yes42%100%

Source: tu.rules_table

Part 4 · How to further evaluate whether the rules are good?

We learn rules on part of the year and check them on weeks the model has never seen.

week = table.timestamp.dt.isocalendar().week.values
test = week % 4 == 0
tu.plot_split(table.timestamp, test, table)
Training and test weeks over the year

Source: tu.plot_split

Are the rules still confident on unseen weeks? Each dot is one or more rules learned on the training weeks; bigger dots group rules with the same confidence on both.

seed(0)
ae = model.train(data[~test], layer_dims=[16], epochs=2, show_progress=False)
train_rules = rule_extraction.generate_rules(ae, min_rule_strength=0.8, target_classes=[{"leakage": "yes"}])["rules"]

tu.plot_train_vs_test(train_rules, data[test])
Confidence of leak rules on training versus test weeks

Source: model.train · rule_extraction.generate_rules · tu.plot_train_vs_test

Can the rules detect leaks? Raise an alarm whenever a rule fires. Every alarm comes with its reason: the rule itself. Press ▶ play to replay the test weeks. Click any dark alarm bar to see every rule that raised it: the full IF–THEN, its support and confidence, and the sensor readings that made it fire.

tu.animate_alarms(table, data, test, train_rules)   # press ▶ play; click a dark alarm bar to see its rules

On a phone, rotate it to landscape or pinch to zoom to use the replay.

Click a dark alarm bar to see every rule that raised it.

Source: tu.animate_alarms

What does the rule strength threshold change? We learned the rules above with min_rule_strength=0.8. Increasing it keeps only the more confident rules, which can get rid of false alarms, if any, but it can also reduce the correct alarms, since fewer rules are left to fire. Reducing it does the opposite: more rules and more leaks caught, but also more false alarms.

Try 0.9 above: here it removes the false alarms raised by the less confident rules (e.g., node_10_pressure = mid) without missing any leak.

Part 5 · Can I use my own model instead of Autoencoders?

Yes. TabProbe turns any model that predicts a column from the other columns into a rule learner [6].

How TabProbe works

Same two steps as Aerial+, only the model changes: tabular foundation models (TabPFN, TabICL, TabDPT), XGBoost, random forests, …

Let’s try it with XGBoost [9]:

from src.wrapper import TabProbe

miner = TabProbe(method="xgboost", max_antecedents=2, ant_similarity=0.5, cons_similarity=0.8)
xgb_rules = miner.mine_rules(data, metrics=["support", "confidence"])
xgb_leak_rules = [r for r in xgb_rules if r["consequent"] == {"feature": "leakage", "value": "yes"}]

print(len(xgb_rules), "rules,", len(xgb_leak_rules), "about leakage")
828 rules, 74 about leakage

Source: TabProbe · TabProbe.mine_rules

Can we trust every rule? XGBoost is often over-confident, so we keep only the rules that also hold on the data.

xgb_leak_rules = [r for r in xgb_leak_rules if r["confidence"] >= 0.8]
tu.rules_table(xgb_leak_rules, n=10)
#IFTHENsupportconfidence
1pipe_29_flow = highleakage = yes42%100%
2node_10_pressure = midleakage = yes26%88%
3node_23_pressure = midleakage = yes20%85%
4pipe_10_flow = low AND pipe_29_flow = highleakage = yes42%100%
5pipe_11_flow = low AND pipe_29_flow = highleakage = yes42%100%
6node_12_pressure = high AND pipe_29_flow = highleakage = yes31%100%
7node_13_pressure = high AND pipe_29_flow = highleakage = yes28%100%
8node_10_pressure = mid AND pipe_29_flow = highleakage = yes26%100%
9node_10_pressure = mid AND pipe_10_flow = lowleakage = yes26%87%
10node_10_pressure = mid AND pipe_11_flow = lowleakage = yes26%87%

Source: tu.rules_table

Do both methods find the same leaks?

tu.compare_networks(scenario, sensors, {"Aerial+": leak_rules, "TabProbe + XGBoost": xgb_leak_rules})
Sensors used by Aerial+ and TabProbe with XGBoost leak rules

Source: tu.compare_networks

Your turn: change method="xgboost" to "random_forest". With a GPU runtime, try "tabpfn" or "tabicl" (pip install tabpfn / tabicl).

Part 6 · What else can we do?

Three more questions we answered in recent papers.

  • What if I don’t want to choose low / mid / high myself? DiffNARM learns the ranges together with the rules [7].
  • What if I have very few rows but thousands of columns? Transfer learning from a tabular foundation model into Aerial+ [5], or use TabProbe [6] directly on a tabular foundation model, e.g., TabPFN [8].
  • Can rules know the network itself? With a knowledge graph of the network, rules can say “IF a flow sensor in a pipe longer than L reads V1, THEN the pressure sensor at the connected junction reads V2” [4].

**Code: ** PyAerial · TabProbe · DiffNARM

References

  1. Vrachimis, Stelios G., and Marios S. Kyriakou. “Leakdb: a benchmark dataset for leakage diagnosis in water distribution networks.” WDSA/CCWI joint conference proceedings. Vol. 1. 2018.
  2. Karabulut, Erkan, Paul Groth, and Victoria Degeler. “Neurosymbolic Association Rule Mining from Tabular Data.” Proceedings of the 19th International Conference on Neurosymbolic Learning and Reasoning (NeSy). Proceedings of Machine Learning Research 284, PMLR, 2025, pp. 565–88, https://proceedings.mlr.press/v284/karabulut25a.html.
  3. Karabulut, Erkan, Paul Groth, and Victoria Degeler. “PyAerial: Scalable association rule mining from tabular data.” SoftwareX, vol. 31, 2025, p. 102341. https://doi.org/10.1016/j.softx.2025.102341.
  4. Karabulut, Erkan, Paul Groth, and Victoria Degeler. “Learning semantic association rules from internet of things data.” Neurosymbolic Artificial Intelligence, vol. 1, 2025. https://doi.org/10.1177/29498732251377518.
  5. Karabulut, Erkan, Daniel Daza, Paul Groth, and Victoria Degeler. “Discovering Association Rules in High-Dimensional Small Tabular Data.” 1st International Workshop on Advanced NeuroSymbolic Applications (ANSyA), at ECAI 2025. CEUR Workshop Proceedings 4125, CEUR-WS, 2025, pp. 105–13, ceur-ws.org/Vol-4125/paper_26.pdf.
  6. Karabulut, Erkan, Daniel Daza, Paul Groth, M.C. Schut, and Victoria Degeler. “Model-Agnostic Association Rule Learning with Tabular Foundation Models.” Transactions on Machine Learning Research,
    1. https://openreview.net/forum?id=Y70lnNnA6T.
  7. Karabulut, Erkan, Daniel Daza, Emile van Krieken, Paul Groth, and Victoria Degeler. “Differentiable Numerical Association Rule Learning.” Transactions on Machine Learning Research,
    1. https://openreview.net/forum?id=0WZf2uidpa.
  8. Hollmann, Noah, et al. “Accurate predictions on small data with a tabular foundation model.” Nature 637.8045 (2025): 319-326.
  9. Chen, Tianqi, and Carlos Guestrin. “Xgboost: A scalable tree boosting system.” Proceedings of the 22nd acm sigkdd international conference on knowledge discovery and data mining. 2016.