{'fraction_non_alphanumeric': 0.03250530520534265, 'fraction_numerical': 0.010860067407314941, 'mean_word_length': 4.619528619528619, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Causal-based Approach to Explain, Predict and Prevent Failures in Robotic Tasks

Robots working in real environments need to adapt to unexpected changes to avoid failures. This is an open and complex challenge that requires robots to timely predict and identify the causes of failures to prevent them. In this paper, we present a causal method that will enable robots to predict when errors are likely to occur and prevent them from happening by executing a corrective action. First, we propose a causal-based method to detect the cause-effect relationships between task executions and their consequences by learning a causal Bayesian network (BN). The obtained model is transferred from simulated data to real scenarios to demonstrate the robustness and generalization of the obtained models. Based on the causal BN, the robot can predict if and why the executed action will succeed or not in its current state. Then, we introduce a novel method that finds the closest state alternatives through a contrastive Breadth-First-Search if the current action was predicted to fail. We evaluate our approach for the problem of stacking cubes in two cases; a) single stacks (stacking one cube) and; b) multiple stacks (stacking three cubes). In the single-stack case, our method was able to reduce the error rate by 97%. We also show that our approach can scale to capture multiple actions in one model, allowing to measure timely shifted action effects, such as the impact of an imprecise stack of the first cube on the stacking success of the third cube. For these complex situations, our model was able to prevent around 75% of the stacking errors, even for the challenging multiple-stack scenario. Thus, demonstrating that our method is able to explain, predict, and prevent execution failures, which even scales to complex scenarios that require an understanding of how the action history impacts future actions.


Introduction
Robots that act in human-centered environments have to handle the execution of various tasks, which requires them to adapt their plan execution flexibly to unexpected changes in the environment [1]. Due to the complexity of these environments, we expect failures in various forms and for various reasons [2], one example being execution failures. The ability to explain their own actions [3], particularly when failures have occurred [4,5], is, therefore, an essential skill of such robots. However, diagnosis capabilities are not only crucial for detecting the causes [6], but could also be used to learn from failures and prevent them from happening [7].
Generating explanations is conceptually based on causality methods [8], which are typically implemented through statistical techniques that learn a mapping between possible causes (preconditions) and the action-outcome (effect) [9,10]. First, we need to investigate how robots can utilize prior experience to reason and consequently generate an explanation about what and why an action execution went wrong [11]. For example, if a robot fails to execute the task of stacking a cube on top of another one, it should be able to explain that the execution failed because the upper cube was dropped too far to the left of the lower cube. In our previous work [11], we proposed a causal-based method based on learning a causal Bayesian network to produce explanations when a failure was detected, meaning that the robot needed to fail. Upon failures, explanations were generated by contrastively comparing the variable parametrization associated with the failed activity with its closest parametrization that would have led to successful execution. Therefore, the next challenge is to use the acquired experience to predict failures in order to prevent them.
The causal relations obtained by the Bayesian networks can be used to predict how likely a particular parametrization of causes will produce failures. In this paper, we propose an extension of [11] which makes use of the prediction capabilities of the learned BNs to prevent failures from happening. When the prediction of a failure has a high probability given the current state, our method finds an alternative execution state, which is expected to result in a successful action execution. This alternative state is found through BFS in a similar fashion as in [11], which allows the agent not only to prevent failures but, at the same time, to provide explanations for its corrective actions.
Predicting and preventing errors is particularly difficult if the effects of First, a causal model is learned from simulations (steps 1,2). Then, this model is used to predict the success of an action given the current state and finds corrective actions in case the action is expected to fail (step 3), even in case of timely shifted action failures.
an action are not immediately flawed but become problematic in future actions [12]. For example, the error was produced on the first action, but the consequence is only observed after the third action (in the future). We call these cases timely shifted action errors. In such cases, the models need to consider the history of the previous actions. Fig. 1 depicts the case of a robot building a tower of four cubes. The second (red) cube is not stacked entirely centered with respect to the bottom (blue) cube. Even if this particular stack can be considered successful on its own, it negatively impacts the overall stability of the tower, which might become a problem later after the second or third stack. This challenging problem is also addressed in this paper, and we show that our causal-based method scales to these complex cases by detecting causal links over the history of several actions, effectively predicting and preventing action failures. To summarize, our contributions are as follows: • We propose a causal-based method that allows robots to understand possible causes for errors and predict how likely an action will succeed.
• We then introduce a novel method that utilizes these prediction capabilities to find corrective actions which will allow the robot to prevent failures from happening.
• Our algorithm proposes a solution to the complex challenge of timely shifted action effects. By detecting causal links over the history of several actions, the robot can effectively predict and prevent failures even if the root of a failure lies in a previous action.

Causality in Robotics
Even though the centrality of causality is increasingly recognized, it is still an underexplored topic in the robotics community [13,5]. One of its significant strengths is the ability to discern task-relevant from irrelevant variables in data. This feature is taken advantage of, for example, in CREST [14], where causal interventions on environment variables are used to discover which variables affect an RL policy. Consequently, excluding irrelevant variables was found to positively affect generalizability and sim-to-real transfer of the policy. Another application was presented in [15], where a set of taskagnostic learning rules was defined to learn causal relations in a physical task. In particular, through repeated interaction with its environment, a humanoid iCub robot learned a causal relationship between the weight of objects and its ability to increase the water level, while other variables, like color, were found to be irrelevant. Another paper [16] has the objective of learning causal relations between actions in household tasks. From human demonstrations in Virtual Reality, they discovered a causal link between opening a drawer and retrieving plates. A causal approach to tool affordance learning was presented in [13]. Their goal was to equip a robot with the ability to work with new tools more effectively through prior experience with different tools. Also [17] exploits the ability to learn the causal relevance of variables to discover dependencies between object, action, constraint features, and the task of grasp selection. Their main objective is to find the best grasp conditional on constraints and object features. The presented approaches and our method have in common that the framework of causality is used to a) detect causal links between certain preconditions in the environment and the success of an action [14,15,16] and b) make use of that knowledge to do something in an optimal fashion (e.g. picking the best tool [13] or grasp [17]). However, those methods have not explored how this causal understanding can be used to explain, predict and prevent failures from happening. Furthermore none of these works discussed the problem of timely shifted action errors, which we are addressing in this paper.

Learning explainable models of cause-effect relations
The planning community captures cause-effect relationships in the form of (probabilistic) planning operators [18]. Some works proposed the concept of task execution models, which combines symbolic preconditions and a function approximation for the success model [9], based on Gaussian Process models. They evaluate their method by learning how to grasp handles. The authors noted that a simulated environment could be incorporated for a faster and more extensive experience acquisition, as proposed in [17], which is a technique we employ to learn our Bayesian Networks. Human virtual demonstrations have been used to construct planning operators to learn cause-effect relationships between actions and observed state-variable changes [18]. Bauer et al. learn probabilistic action effects of dropping objects into different containers [10], with the goal of generalizing the probability predictions for a variety of objects, like bowls and bread boxes. They utilize an ontology to find out how closely related the objects are but do not consider object properties. Our approach has several advantages over the work mentioned in this subsection. While we share the general objective of learning generalizable prediction models that map preconditions to action effects, our proposed causal approach allows us, as opposed to [10], to learn which object properties and environment preconditions are relevant for the investigated actions. This feature is also the basis for our method to explain, predict and prevent failures. Furthermore, our method scales to scenarios where the effect of a previous action has an impact on subsequent actions, as opposed to [9].

Failure prevention
In [2], approaches for fault detection and diagnosis in Robotic systems are classified into data-driven, model-based, and knowledge-based. The ability to diagnose and correct robot action failures are discussed in [7] for the problem of robot grasping. They propose a method that diagnoses potential causes (unmet preconditions) for a failure and, through sampling, finds a parametrization that maximizes predicted execution success under the known execution model. This method works well when the errors occur immediately after the action. However, if errors either occur in the future or build up cumulatively over several actions, we require a model that can capture the action history. In [12] the authors propose a method that would also be able to detect the cause of failures, even if it is not related to the currently executed action. They utilize Hierarchical Hidden Markov Models (HHMMs) to represent and track failures over time, which allows them to generate a list of possible causes with different likelihoods when a failure is encountered during a plan execution. However, they have not utilized this information to prevent failure through corrective actions, as we propose.

Contrastive Explanations
An important element of many explainable AI methods like Explainable AI Planning (XAIP) [19], is the concept of contrastive explanations. This concept draws parallels to the way that humans generate explanations [4]. Typically the focus of work that falls under the umbrella of XAIP are questions like why the plan contains a particular action a 1 and not action a 2 ? [19,20] or they focus more on the actual communication of plan execution failures [21]. We utilize this concept in a different way and for a different purpose. We search for contrastive failure causes, which allow us to explain why failures might occur in the future and find corrective actions to prevent them from happening.

Our approach to explaining, predicting and preventing failures
We propose and present a multi-step approach to predicting and preventing failures, which consists of four main steps: 1. We start by explaining the task of variable identification (sec. 3.1). In this step, an action is represented in terms of a set of random variables that describe both possible preconditions as well as effects. 2. Then, we learn a causal model using the identified variables from step 1 based on BN learning (sec. 3.2). BN learning is typically divided into learning the causal connections between the variables (structure learning) and learning conditional probability distributions (parameter learning). 3. In section 3.3, we elaborate on how we use the obtained causal model to predict when a failure is likely to occur and how we have previously used the model to explain the reasons for failures after they have occurred [11].
4. Finally, in section 3.4, we further expand our method to address the problem of preventing failures.

Variable definitions and assumptions
Our method for explaining, predicting, and preventing failures is based on detecting causal relations between possible causes and effects of an action. Actions refer to concrete movements executed by the robot to act on its environment, e.g., reaching a cube or stacking a cube. For the purpose of learning the causal relations, we describe each action in terms of a set of random variables X = {X 1 , X 2 , ..., X n }. The choice of the number of (n) variables is, in principle, in the hands of the experiment designer. However, there are several aspects that need to be considered: We conceptually split X into a subset of treatment (cause) variables C ⊂ X and outcome (effect) variables E ⊂ X. Then, the goal is to measure the effect of treatment variables on their outcome. In other words, C and E differ since we can decide and set values for variables in C, while outcome variables are not actively set but measured at the end or throughout the experiment. We measure the success of an action in terms of effect variables. For example, the action of cancer treatment is successful if the outcome variable that denotes whether a patient has cancer equals 0. Therefore, we necessarily need to define at least one effect variable.
We can collect data for learning causal models either from simulations or from the real world. A data sample d consists of a particular parametrization of the previously defined set of variables X, which we denote as d = {X 1 = x 1 , X 2 = x 2 , ..., X n = x n }, where n denotes the number of variables.... We currently assume that d contains a value for all variables in X, but there are also Bayesian network learning methods that can deal with incomplete datasamples [22]. We sample values for the causes C randomly. Randomized controlled trials are referred to as the gold standard for causal inference [3] and allow us to avoid the danger of unmeasured confounders. Consequently, we can call the detected relations between the variables X causal and not merely correlations, which can be spurious. Then, one advantage is that the generated failure explanations are truly causal. The second advantage of causal models is that they can also answer interventional queries, whereas non-causal models can only answer observational queries.
We define another set of variables G ⊂ E, which denote outcome variables via which the success of an action is specified and X goal = { d goal 1 , d goal 2 , ..., d goal h } a set that contains all possible variable parametrizations that denote a successful action execution. Each goal parametrization d goal l ∀l ∈ {1, 2, ..., h}, describes one possible variable assignment of a subset of the outcome variables E, that are possible successful action outcomes. For example, in the cancer treatment, there is only one single successful outcome, namely the patient is cancer-free, thus h = 1. Then, an action is successful iff the parametrization .., m}. Note that G does not necessarily need to contain all variables E, but depends on the actual goal that one aims on measuring. Thus m denotes the number of variables that are relevant for specifying the success of an action. It is out of scope of this paper to learn X goal and instead we assume it is provided. However, the robot has no apriori knowledge about which variables in X = X 1 , X 2 , ..., X n are in C or E, nor how they are related.

Our proposed pipeline to learn causal models
.., X n } represents a set of nodes which correspond to the random variables X that describe our action, and A is the set of arcs [23] that denotes all relations between the variables. This dependency allows to factorize the joint probability distribution of a BN into local probability distributions, where each random variable X i only depends on its direct parents Π X i : To learn a BN from data, we first learn the structure of the DAG, and then retrieve the local probability distributions, which is referred to as parameter learning. Many structure learning algorithms cannot handle continuous variables as parents of categorical variables [24,23]. We, therefore, perform quantile discretization [25] on all continuous random variables in X.

Structure Learning
To learn the causal relations G = (V, A) between the variables we utilize the stable implementation of the PC [26] algorithm. This algorithm is a constraint-based-algorithm, and it uses statistical tests to determine conditional independence relations from the data [25]. PC is one of many structure learning algorithms [22], which could be used with equal eligibility for this step. In the following, we assume that the outcome of the structure learning step indeed reveals the correct graph G. If G is not found to be correct or only partially directed, it might be required to collect more data samples or tune the number of discretization steps.

Parameter Learning
The purpose of this step is to fit functions that reflect the local probability distributions, of the factorization in formula 1. We utilize the bayes estimator for conditional probabilities to generate a conditional probability table: Our Bayes estimator uses a uniform prior that matches the Bayesian Dirichlet equivalent (bde) score [25].

Inference
Given the network structure G and the conditional probability table, we can query the BN to retrieve information about the probability distribution of BN variables. This process is also called inference. We rely on logic sampling, which belongs to the family of approximate inference algorithms [25].

Our proposed method to explain failures
In our previous work [11], we proposed a method to generate contrastive failure explanations, which uses the obtained causal Bayesian network to compute success predictions (summarized in algorithm 1).
After retrieving the current interval from the continuous variable parametrization (L-1 Alg. 1)), a transition matrix is generated (L-2 Alg. 1)). This transition matrix will be used to provide all possible state transitions in the search tree. A state in the search tree is made up of a complete parametrization of all variables in X. Let's consider the example of X = {X 1 , X 2 } with two intervals x , x each. Then, all possible valid transitions for node = ( In lines 5-15 (Alg. 1), the closest variable parametrization that fulfills the goal criteria of P (d g ∈ X goal |Π G = child) > , is searched for through BFS.
is the success threshold and can be set heuristically. The concept of our explanation generation is comparing the current variable intervals that lead to an execution failure x current int with the closest intervals would have been expected to lead to a successful task execution Algorithm 1 Get closest successful variable parametrization from causal model Input: failure variable parameterization x failure , structural equations P (X i |Π X i ), discretization intervals of all model variables X int , success threshold , goal parametrizations X goal Output: solution variable parameterization x solution int , solution success probability prediction p solution for all transition t ∈ P (node) do 10: child ← Child(P, node) 11: if child ∈ q, v then 12: p solution = P (d g ∈ X goal |Π G = child) 13: if p solution > then 14: x solution int ← child 15: return(p solution , x solution int ) 16: x solution int . This process is visualized in Fig. 2 exemplified on two variables X and Y , which both have a causal effect on variable X out . Given that x out = 1 ∈ X goal would denote the succesfull action that is described through this causal model, the resulting explanation would be that the action has failed because X = x 1 instead of X = x 2 and Y = y 4 instead of Y = y 3 .

Our Proposed method to predict and prevent failures
In [11], we have used Alg. 1 to explain the reasons for a failure only after the failure has occurred. For this, our algorithm searches for the closest variable parametrization that would have likely led to successful execution. However, the causal model can also be used to predict the success probability of the current state prior to the actual execution.
In this paper, we, therefore, propose an extension of our method presented in the new Alg. 2 to prevent failures from happening when an error has been predicted with a high probability. In particular, we first retrieve the discretization intervals for the current variable parametrization (L-1 Alg. 2)) and query the causal model to predict the success probability for the current state (L-2 Alg. 2)). In case the predicted probability is above a chosen threshold of , we continue with the execution based on the current parameters (L-3 Alg. 2)). If, however, the probability is below the threshold (L-4 Alg. 2)), we retrieve the closest success parametrization through Alg. 1 (L-7 Alg. 2)). Finally, we use the middle values of the corrected intervals as concrete parameters to retrieve a corrected action (L-8 Alg. 2)). Note, the algorithm only changes the parametrization for intervals that have been deemed responsible for the failure and keep the current parametrization for variables that are not problematic. The output parametrization x success can then be used to manipulate the environment to ensure the action will succeed, e.g., by moving the robot gripper into a different position.

Algorithm 2 Predict and prevent failures
Input: current variable parameterization x current ,structural equations P (X i |Π X i ), discretization intervals of all model variables X int , success threshold , goal parametrizations X goal Output: Concrete success variable parametrization x success 2: x solution int ← getIntervalFromVal(x current , X int ) 3: 4: x success ← x current

Experiments and Results
We evaluate our method to predict and prevent execution failures for the problem of stacking cubes. We conducted two different experiments: Experiment 1 : First, we evaluate our learned causal model in a simple task of stacking one cube, see Fig. 3.a. From this task, we assess the correction abilities of the obtained causal model (see, Sec. 4.1). Experiment 2 : Then, we assess our proposed method in a complex task of staking multiple cubes for building a tower of four cubes. With this experiment, we also investigate the case of performing the stacking action three times in a row (see Sec. 4.2).
For both experiments, we design an environment that contains two types of cubes: CubeDown and CubeUp i , with i being the stacking order of the upper cubes (e.g., CubeUp 1 is the cube that is stacked first). CubeDown is the bottom cube of a tower that, in our case, does not need to be rearranged or requires any movement prior to the stacking actions. All cubes have a fixed size of 5cm. To describe the stacking action we define four types of variables: xOff i , yOff i , dropOff i , onTop i , where i denotes the corresponding cube. Fig. 3.b and Fig. 4.b provides a detailed description of the variables for both experiments.
The data collection for training and evaluating the causal models is conducted in Unity3d, which employs the Nvidia PhysX engine for physics simulations. Inside Unity, we set up 400 parallel table environments to speed up the simulation process and data collection. At the beginning of every stacking experiment, the variable values for xOff i , yOff i , dropOff i are randomly sampled and the cube positions are initialized accordingly. Note, that the simulations are conducted without the existence of any robot and only involve cubes dropping from a predefined position. As a result, the simulations are less conservative than the real world. However, in [11], we have experimentally determined approximately 70% congruence in terms of stacking success between simulated stacks and stacks that were performed by a real robot. In our first experiment, the goal is to stack only one single cube on top of the bottom cube (see Fig. 3.a). As the initial step, we deploy a training phase to collect data for learning the causal Bayesian network. For this purpose, we run 40,000 simulations of randomized single-stack actions. We define the set of variables that is used for the first experiment (E1) as

Experiment 1 Setup: Stack-1-Cube scenario
We sample randomly values for xOff i , yOff i ∼ U [−0.03,0.03] (in meter), dropOff i ∼ U [0.005,0.1] (in meter). onTop i = {True, False} is not sampled but automatically determined after the stacking process. From this training data, we learn the graphical representation of the variables and fit the conditional probability distributions. For each conditional value assignment, we then determine the closest variable parametrization that would lead to a successful execution based on the procedure which is elaborated in Sec. 3. This allows us to generate a 'lookup' table for the best possible corrections for each x-y-dropOffset parametrization that we could possibly encounter during a single stack action.
The goal set G = {onTop 1 } for this experiment, describes the stacking success for the cube that is stacked and consequently we denote the action as successful iff onTop 1 = 1. We then evaluate the impact of having the obtained correction model in terms of cube-stacking success by comparing two cases (datasets): one without corrections from the model and one including the corrected stacking positions. Both test datasets use the same sample seed, different from the train-dataset seed. However, the variable distributions for training and testing are similar. Our hypothesis for this experiment is that deploying our method to adapt the stacking position prior to dropping the cube will significantly improve the stacking success.

Experiment 2 Setup: Stack-3-Cubes scenario
Our second experiment (E2) considers the more complex scenario of stacking three cubes on top of a base cube (see Fig. 4.a). Unlike experiment 1, we need three upper cube variables: CubeUp 1 , CubeUp 2 and CubeUp 3 instead of a single upper cube. Now, the goal of the robot is to build a tower of cubes by stacking CubeUp 1 on top of CubeDown, CubeUp 2 on top of CubeUp 1 and, finally, CubeUp 3 on top of CubeUp 2 . Our new set of variables is In this case, we expect that the success of each stacking action becomes increasingly difficult, the higher the tower of cubes.
To test this second experiment, we implement some slight adaptations to the simulation environment. For example, every 3 seconds, the next cube is dropped until the whole tower is complete. If a previous stack has failed, the whole experiment is considered a failure, and no more cubes are stacked on top, therefore, the experiment is terminated. Furthermore, the offset between two cubes is always calculated with respect to the previously stacked cube (e.g., betweenCubeUp 1 and CubeDown or CubeUp 2 and CubeUp 1 ), as exemplified in Fig. 4.b.
Similarly to the first experiment, we begin with a learning phase. Due to the requirement of the increased samples, we conducted a total of 800,000 experiments. In addition, unlike the uniformly distributed samples in experiment 1, we sample from a gaussian distribution for this experiment, to achieve a more equally distributed ratio between failures and successful stacks. We evaluate this experiment in two ways. First, we learn a BN only on the first stacking action, which we call 1-Stack-Model g (g denoting that the data was samples from Gaussian distributions), and we want to evaluate how useful this model is for failure prediction and prevention in later stacks. We don't reuse the model from experiment 1 (1-Stack-Model u , where u=uniform distribution) since we expect some differences due to the adapted sampling distributions (E1:Uniform and E2: Gaussian distributions). Then, we learn a second model that captures all three stacks in one model, which we call the 3-Stack-Model g . Consequently, we created three different test datasets, each consisting of 40,000 samples, following a similar distribution but other seed as in the training dataset. The first test dataset represents the case of no corrections (our baseline), followed by applying the smaller model on each of the cubes (no history case). Finally, we used the complete 3-Stack-Model g to correct the data accordingly.
The goal set G = {onTop 3 } for this experiment indicates the stacking success of the third cube and we denote the action as successful iff onTop 3 = 1. Note that, since the experiment was stopped, if one of the previous stacks has failed, a successful third stack will imply success in the other two stacks as well. We hypothesize that, while the 1-Stack-Model g will improve the stacking success of the complete tower, the 3-Stack-Model g will be even more helpful since it takes the entire history of all single stacking actions into account.

Assessing the obtained causal models
We first analyze the obtained causal models in terms of the graphical structure of the learned BN. Then, we explain the obtained conditional probabilities that were fitted around the experiment data. We validate the correctness of the model to make sure that the predictions are not based on a flawed understanding of cause-effect relations, which could result in wrong failure explanations and obstruct the failure prevention. Fig. 5 visualizes the obtained causal relations between the subset of variables X E1 = {xOff 1 , yOff 1 , dropOff 1 onTop 1 }. The results exhibit dependencies of all the cube positioning variables (dropOff 1 , xOff 1 , yOff 1 ) on the stacking outcome onTop 1 . Notice, that all the variables from X E1 were discretized according to Tab. 1. For example, the variable of dropOff 1 has three possible intervals (z 1 , z 2 , and z 3 ). Fig. 6 visualizes the obtained probabilities for the stacking success of CubeUp 1 conditional on the analyzed variables. Generally, for all three drop-offset intervals, the causal model showed large stacking success probabilities centered around smaller x/y-offsets and decreases the larger the x/y-offsets become. This decrease in probability is faster for higher drop-offset positions (e.g., compare the two drop-offset intervals of z 1 and z 3 ). For the most extreme x/y-offset intervals, the model displays a stacking success of below 0.2 (red areas in Fig. 6), which is credible considering that the center of gravity of the stacked cubes in these x/y-offset intervals is close to the limits or outside the surface of the bottom cube. We conclude that the probability distributions trained on simulated data are plausible.

Learned causal model for Experiment 2
The obtained DAGs for the two evaluation cases (1-Stack-Model g and 3-Stack-Model g ), are displayed in Fig. 7. For both cases, the used variables were discretized according to Tab. 2. In the case of the 1-Stack-Model g (i = 1), we obtained a slightly different dependency structure than in the model obtained from experiment 1 1-Stack-Model u . In particular, we notice A similar graph dependency structure between the variables is observed in the 3-Stack-Model g (i = 1, 2, 3). Where the dropOff i variables are independent of the stacking success. From Fig. 7.b it becomes evident that the success of each stack depends on an increasing number of parent nodes. Interestingly, the complete graph shown in Fig. 7.b indicates that not only the x/y-offset variables but also previous onTop i impact the stacking success (e.g. consider the arrow from onTop 2 to onTop 3 ). The reason for these causal links is the termination of the stacking experiments in cases where the previous stack has already failed. We conclude that the 3-Stack-Model g successfully captures the dependence of earlier stacks on the outcome of later stacking actions, thus encoding the action history in one causal model 1 .

Evaluation of Prediction and Failure Prevention Capabilities
We finally analyze the ability of our obtained causal models to predict and avoid potential future failures by correcting the cubes' stacking position to the closest variable parametrization (as explained in Sec. 3.4).

Failure prediction and prevention in Experiment 1
The results from the test datasets of experiment 1 are displayed in Tab. 3. Out of 40,000 collected samples of the ground-truth dataset, almost 30,000 stacking experiments failed (around 74%) without corrective actions. However, our model could fix and prevent 97% of these failures. If we consider the confusion matrix in Tab. 4, we see that our model predicts almost all actual failures as failures (true negatives). At the same time, it predicts around 42% (11.1/26.2) of the actually correct cases as failures (false negatives). For the current example, however, this might be beneficial since we want to avoid stacking failures and might not mind an additional action as much as a failed tower. We, therefore, conclude that our model is highly beneficial for predicting and avoiding future errors.

Failure prediction and prevention in Experiment 2
Failure prediction and correction ability are analyzed in Tab   action, 42% happened during the second, and 36% during the third in the ground truth dataset (no corrections). This allows the conclusion that the failure probability increases with the height of the tower. The decreasing number of errors for the third stacking action is due to the limited number of data samples that reach the third stack. Considering the failure prediction confusion matrix of the 3-Stack-Model g in Tab. 6, we can again detect a large true negative rate but also a high false negatives rate. If we could increase the number of discretization intervals, we could enhance the prediction capabilities of the model. However, an increased number of intervals also requires an increased number of training samples. As the second row of Tab. 5 shows, applying the 1-Stack-Model g on all three stacking actions reduced the number of stacking failures significantly by 78% and applying the 3-Stack-Model g reduces the errors by 75%. We can conclude that both models greatly improve the stacking success. Remarkably, the 1-Stack-Model g performed well on all three stacking actions, despite having been trained only from data of the first stacking action and requiring 20 times fewer data than the 3-Stack-Model g . This is a good indication of the scalability possibilities of our model.

Explanation & Correction of timely shifted action effects
Even though the 3-Stack-Model g and the 1-Stack-Model g perform approximately similar in terms of failure reduction, we required significantly more data samples to learn the structure and parameters of the BN. A critical advantage of the 3-Stack-Model, however, is the possibility to explain Three Stacks Case failure percentage fail in 1 fail in 2 fail in 3 no correction 81% 21% 42% 36% 1-Stacks-Model g 18% 4% 12% 83% 3-Stacks-Model g 20% 11.5% 5.5% 83%  showcase scenarios where the tower did not fall directly when the error had been committed but only became evident later. In example 1 (see Tab. 7, Fig. 8), the first cube has been stacked far to the left. This did not lead to a failure immediately, but after stacking the second (1 out of 3 times) or third cube (2 out of 3 times), the tower fell. Our model detected that the culprit was this first stack and not the third. Taking each stack individually would have also yielded a correction of the first stacking action since the 1-Stack-Model u 2 predicts a success probability of < 0.2 (Fig. 6), despite the tower not failing in reality. As discussed in Tab.4, the model has a relatively large number of false negatives, which, however, in this case, was beneficial to unintentionally prevent a future failure. However, in example 2 (see Tab. 7, Fig. 9), we investigated a case where the 1-Stack-Model u did not predict any errors since each stack looks perfectly fine on its own. Only due to the cumulative effect of several offsets did we get a failure at the last stack of cube 3 (3 out of 3 cases). Without the history of the 3-Stack-Model, we would not be able to correct this example. In both examples, the corrected version by the 3-Stack-Model g succeeded in all three trials 3 . Figure 8: Displayes the stacking execution of Example 1 performed on the real robot. In the first row, the cubeUp 1 (green), is stacked too far to the right, which leads to a failure in the third stack. In the corrected sequence, as proposed by the 3-Stack-Model g , cubeUp 1 (red) is stacked a little more to the left, which allows the robot to successfully stack all 3 cubes.

Conclusion
In this paper, we propose a causal-based method that allows robots to understand possible causes for execution errors and predict how likely an action will succeed. We then introduce a novel method that utilizes these prediction capabilities to find corrective actions which will allow the robot to prevent failures from happening. Our algorithm proposes a solution to the complex challenge of timely shifted action effects. By detecting causal links over the history of several actions, the robot can effectively predict and prevent failures even if the root of a failure lies in a previous action. We Figure 9: Displayes the stacking execution of Example 2 performed on the real robot. In the first row, each cube is stacked a little to the right and down. Each stack on itself is not found to be problematic by 1-Stack-Model g , and thus no corrective actions are found. However, with the third cube, the cumulative error is too large and the tower falls. In the corrected sequence, as proposed by the 3-Stack-Model g , cubeUp 1 (blue) is stacked a little more to the left, which allows the robot to successfully stack all 3 cubes, despite further offsets in the other stacks.
have shown the success of our approach for the problem of stacking cubes in two cases; a) single stacks (stacking one cube) and; b) multiple stacks (stacking three cubes). In the single-stack case, our method was able to reduce the error rate by 97%. We also show that our approach can scale to capture multiple actions in one model, allowing to measure timely shifted action effects, such as the impact of an imprecise stack of the first cube on the stacking success of the third cube. For these complex situations, our model was able to prevent around 75%.
Despite being able to capture action histories in one model, one disadvantage of such large models is data efficiency. The more parents a BN node has, the more samples are required to learn its graphical structure and the conditional probabilities. In the future, one important aspect of the feasibility of such models is to find intelligent ways of pre-initializing the model, e.g., by utilizing the single-action models as prior for structure and probabilities.

0.88
Explanation: The first cube was stacked too far to the right.  Fig. 8 and 9.