This repository implements the algorithm introduced in our paper:
- Tzu-Yi Chiu, Jérôme Le Ny, and Jean Pierre David, Temporal Logic Explanations for Dynamic Decision Systems using Anchors and Monte Carlo Tree Search, Artificial Intelligence Journal (AIJ) Special Issue on Risk-aware Autonomous Systems, 2023
For many automated perception and decision tasks, state-of-the-art performance may be obtained by algorithms that are too complex for their behavior to be completely understandable or predictable by human users, e.g., because they employ large machine learning models. To integrate these algorithms into safety-critical decision and control systems, it is particularly important to develop methods that can promote trust into their decisions and help explore their failure modes.
In this article, we combine the anchors methodology [1] with Monte Carlo Tree Search (MCTS) to provide local model-agnostic explanations for the behaviors of a given black-box model making decisions by processing time-varying input signals. Our approach searches for highly descriptive explanations for these decisions in the form of properties of the input signals, expressed in Signal Temporal Logic (STL), which are highly likely to reproduce the observed behavior.
To illustrate the methodology, we apply it in simulations to the analysis of a hybrid (continuous-discrete) control system and a collision avoidance system for unmanned aircraft (ACAS Xu) implemented by a neural network.
Let
An anchor is defined as a rule
It can be viewed as a logic formula describing via a set of rules (predicates)
a neighborhood
The precision of a rule
The coverage of a rule
The figure below illustrates the notions of precision and coverage.
On this figure, the curved boundary separates the decision
Suppose that the threshold
Although only the precision is involved to define anchors, rules that have broader coverage, i.e., that are satisfied by more input instances, are intuitively preferable. Essentially, an explanation of high precision approximates an accurate sufficient condition on the input features such that the output remains the same, while a larger coverage makes the explanation more general, thus approaching a necessary condition.
Therefore, [1]
proposes to maximize the coverage among all anchors to find
the best explanations, i.e., among those which have sufficient precision.
This anchor with maximized coverage allows to locally approximate the boundary
separating the inputs leading to the specific output
We provide a simple example to illustrate the evolution of a Directed Acyclic
Graph (DAG) built with the proposed MCTS algorithm.
We work here over the discrete time set
Consider an automated thermostat, measuring the temperature signal
Starting from the trivial STL formula
At the end, the algorithm returns
|- main.py - Main executable script
|- mcts.py - Tree object implementing MCTS steps
|- stl.py - STL objects (primitives & formulas)
|- visual.py - Script for visualization of the tree evolution (Section 4.3)
|- simulator.py - Abstract class for simulators
|
| **folders**
|- simulators - Simulators that can generate signal samples (function `simulate`)
|- demo - Figures and important log files
|_ log - Automatically generated log files
The code was developped in Python 3.8 and should only require basic packages
such as numpy
.
In main.py, multiple case studies (see here for details) can be run successively by uncommenting the corresponding lines:
def main(log_to_file: bool = False) -> None:
"Run algorithm in multiple case studies."
set_logger() # log to terminal
simulators = []
simulators.append('thermostat')
#simulators.append('auto_trans_alarm1')
#simulators.append('auto_trans_alarm2')
#simulators.append('auto_trans_alarm3')
#simulators.append('auto_trans_alarm4')
#simulators.append('auto_trans_alarm5')
#simulators.append('auto_trans')
#simulators.append('acas_xu')
for simulator in simulators:
if log_to_file:
set_logger(simulator)
run(simulator)
The argument --log [-l]
logs the (intermediate & final)
results to a log
folder:
python3 main.py [--log [-l]]
For the automated thermostat specifically, the evolution of the DAG shown above can be visualized with visual.py:
python3 visual.py
This work was funded by NSERC under grant ALLRP 548464-19.
[1] T. M. Ribeiro, S. Singh, C. Guestrin, Anchors: High-precision model-agnostic explanations, AAAI.