{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Causal Structures - Intervention-Prediction" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%%capture\n", "# execute the creation & training notebook first\n", "%run \"02-02-prediction.ipynb\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the [prediction section](./02-02-prediction.ipynb) made prediction based on our trained causal structure.\n", "The ``prediction`` method propagates information to all directions. This is correct from an information theoretical point of view. An observation of a certain parameter can contain information about all other parameters." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``InterventionPredictor``, that can be applied by calling the ``predict_interventions`` method of the ``CausalStructure``, distinguishes between interventions and observations by applying the Do calculus for causal models. Information from parameters that are subject to an intervention can only propagate forwards in the causal model." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can observe this difference when making intervention predictions given the parameter \"(b|a)\". This parameter depends on \"(a)\" and influences \"(c|a,b)\". In that sense it is both input and output." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CausalStructure([({'(a)'}, '(b|a)'),\n", " (set(), '(a)'),\n", " ({'(a)', '(b|a)'}, '(c|a,b)')])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "causal_structure" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With neither observations nor interventions we just get the learned mean values." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
(a)(b|a)(c|a,b)
04.989583-24.72305640.030782
\n", "
" ], "text/plain": [ " (a) (b|a) (c|a,b)\n", "0 4.989583 -24.723056 40.030782" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "causal_structure.predict_interventions(data={}, interventions={})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With the observation b=0 we see that both the predicted values for \"(a)\" and \"(c|a,b)\" change, since observational information travels forwards and backwards." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
(a)(b|a)(c|a,b)
04.5268230.047.290798
\n", "
" ], "text/plain": [ " (a) (b|a) (c|a,b)\n", "0 4.526823 0.0 47.290798" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "causal_structure.predict_interventions(data={\"(b|a)\": [0]}, interventions={})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With the intervention b=0 we see that only \"(c|a,b)\" changes, since interventional information only travels forwards.\n", "The predicted values for \"(c|a,b)\" also changed because \"(c|a,b)\" also depends on \"(a)\" (and therefore its estimate)." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
(a)(b|a)(c|a,b)
04.9895830.051.021084
\n", "
" ], "text/plain": [ " (a) (b|a) (c|a,b)\n", "0 4.989583 0.0 51.021084" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "causal_structure.predict_interventions(data={}, interventions={\"(b|a)\": [0]})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the [next section](./02-04-evaluation.ipynb) we will evaluate the causal structures predictive performance." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 4 }