{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "quick_start-0",
   "metadata": {},
   "source": [
    "# Quick start\n",
    "\n",
    "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Abel-ai-lab/andrey/blob/main/examples/quick_start.ipynb)\n",
    "\n",
    "You call every method in Andrey the same way: pass it your data, and read the result it returns.\n",
    "This notebook loads the protein measurements of Sachs et al. (2005), learns a graph from them\n",
    "with four classic methods, PC, GES, FCI, and DirectLiNGAM, reads each result, and draws each\n",
    "graph."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-1",
   "metadata": {},
   "source": [
    "## Start\n",
    "\n",
    "Choose a CPU runtime and run this cell first. In Colab it installs `andrey-core==0.17.1` from PyPI;\n",
    "local kernels use the installed environment."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "quick_start-2",
   "metadata": {
    "tags": [
     "colab-setup"
    ]
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "IN_COLAB = \"google.colab\" in sys.modules\n",
    "\n",
    "if IN_COLAB:\n",
    "    os.environ[\"ANDREY_DEVICE\"] = \"cpu\"\n",
    "    !pip install --quiet \"andrey-core[viz]==0.17.1\" pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "quick_start-3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import andrey\n",
    "import andrey.viz\n",
    "from andrey.data import load_dataset"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-4",
   "metadata": {},
   "source": [
    "## The data\n",
    "\n",
    "Sachs and colleagues (2005) measured 11 proteins and phospholipids in 853 single human immune\n",
    "cells. Biologists had already mapped how these molecules signal to one another, so a graph\n",
    "learned from the measurements can be checked against a known network of 17 links.\n",
    "`load_dataset` downloads the measurements on first use and caches them.\n",
    "\n",
    "Each row is one cell and each column one molecule. For your own data, pass a pandas DataFrame\n",
    "or a NumPy array of the same shape: one row per sample, one column per variable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "quick_start-5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>raf</th>\n",
       "      <th>mek</th>\n",
       "      <th>plc</th>\n",
       "      <th>pip2</th>\n",
       "      <th>pip3</th>\n",
       "      <th>erk</th>\n",
       "      <th>akt</th>\n",
       "      <th>pka</th>\n",
       "      <th>pkc</th>\n",
       "      <th>p38</th>\n",
       "      <th>jnk</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>26.4</td>\n",
       "      <td>13.2</td>\n",
       "      <td>8.82</td>\n",
       "      <td>18.30</td>\n",
       "      <td>58.80</td>\n",
       "      <td>6.61</td>\n",
       "      <td>17.0</td>\n",
       "      <td>414.0</td>\n",
       "      <td>17.00</td>\n",
       "      <td>44.9</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>35.9</td>\n",
       "      <td>16.5</td>\n",
       "      <td>12.30</td>\n",
       "      <td>16.80</td>\n",
       "      <td>8.13</td>\n",
       "      <td>18.60</td>\n",
       "      <td>32.5</td>\n",
       "      <td>352.0</td>\n",
       "      <td>3.37</td>\n",
       "      <td>16.5</td>\n",
       "      <td>61.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>59.4</td>\n",
       "      <td>44.1</td>\n",
       "      <td>14.60</td>\n",
       "      <td>10.20</td>\n",
       "      <td>13.00</td>\n",
       "      <td>14.90</td>\n",
       "      <td>32.5</td>\n",
       "      <td>403.0</td>\n",
       "      <td>11.40</td>\n",
       "      <td>31.9</td>\n",
       "      <td>19.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>73.0</td>\n",
       "      <td>82.8</td>\n",
       "      <td>23.10</td>\n",
       "      <td>13.50</td>\n",
       "      <td>1.29</td>\n",
       "      <td>5.83</td>\n",
       "      <td>11.8</td>\n",
       "      <td>528.0</td>\n",
       "      <td>13.70</td>\n",
       "      <td>28.6</td>\n",
       "      <td>23.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>33.7</td>\n",
       "      <td>19.8</td>\n",
       "      <td>5.19</td>\n",
       "      <td>9.73</td>\n",
       "      <td>24.80</td>\n",
       "      <td>21.10</td>\n",
       "      <td>46.1</td>\n",
       "      <td>305.0</td>\n",
       "      <td>4.66</td>\n",
       "      <td>25.7</td>\n",
       "      <td>81.3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    raf   mek    plc   pip2   pip3    erk   akt    pka    pkc   p38   jnk\n",
       "0  26.4  13.2   8.82  18.30  58.80   6.61  17.0  414.0  17.00  44.9  40.0\n",
       "1  35.9  16.5  12.30  16.80   8.13  18.60  32.5  352.0   3.37  16.5  61.5\n",
       "2  59.4  44.1  14.60  10.20  13.00  14.90  32.5  403.0  11.40  31.9  19.5\n",
       "3  73.0  82.8  23.10  13.50   1.29   5.83  11.8  528.0  13.70  28.6  23.1\n",
       "4  33.7  19.8   5.19   9.73  24.80  21.10  46.1  305.0   4.66  25.7  81.3"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sachs = load_dataset(\"sachs\")  # 853 cells, 11 proteins, and the known network\n",
    "data = sachs.data\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-math",
   "metadata": {},
   "source": [
    "## In math\n",
    "\n",
    "Each column of `data` is a variable $X_j$, here $d = 11$ of them, and each row is one draw from a\n",
    "distribution $P$ over $V = \\{X_1, \\dots, X_d\\}$. We model each variable as a function of its\n",
    "parents in a directed acyclic graph (DAG) $G$, its direct causes, and of its own noise:\n",
    "\n",
    "$$X_j = f_j(X_{\\mathrm{pa}_G(j)}, N_j), \\qquad j = 1, \\dots, d,$$\n",
    "\n",
    "with the noise terms $N_j$ jointly independent, so no hidden variable causes two columns. A method\n",
    "estimates $G$, or the part of $G$ the data identify: PC and GES below return a class of DAGs, FCI\n",
    "drops the independence of the noise to allow hidden common causes, and DirectLiNGAM identifies $G$\n",
    "itself by assuming linear $f_j$ and non-Gaussian noise. The\n",
    "[concepts page](https://andrey.abel.ai/docs/guides/concepts.html) states each assumption and what\n",
    "each graph claims."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-6",
   "metadata": {},
   "source": [
    "## PC\n",
    "\n",
    "PC starts with every pair of molecules linked. It removes a link when a statistical test finds\n",
    "the two independent, either alone or given some of their other neighbors, and orients a link\n",
    "only when a pattern in the tests forces its direction."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "quick_start-7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pc  cpdag  |  11 nodes  |  8 edges (6 undirected, 2 directed)\n",
      "\n",
      "  raf -- mek\n",
      "  plc -- pip3\n",
      "  pip2 -- pip3\n",
      "  erk -- akt\n",
      "  erk -- pka\n",
      "  akt -- pka\n",
      "  p38 -> pkc\n",
      "  jnk -> pkc\n",
      "\n",
      "  indep_test: fisherz\n",
      "  tie_break: rank\n"
     ]
    }
   ],
   "source": [
    "pc = andrey.pc(data)\n",
    "print(pc)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-8",
   "metadata": {},
   "source": [
    "The first line names the method and the kind of graph. This one is a CPDAG: it stands for\n",
    "every causal graph that independence tests cannot tell apart. A directed edge (`->`) points\n",
    "the same way in all of them, and an undirected edge (`--`) can point either way.\n",
    "\n",
    "You can read the same parts in code. `pc.structure` is the graph: its `kind` says how to read\n",
    "the edges, and `oriented_edges()` lists each edge as (source, target, type), with your column\n",
    "names. `pc.metadata` records the settings of the run."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "quick_start-9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "kind: cpdag\n",
      "directed: [('p38', 'pkc', 'directed'), ('jnk', 'pkc', 'directed')]\n",
      "test: fisherz\n"
     ]
    }
   ],
   "source": [
    "graph = pc.structure\n",
    "print(\"kind:\", graph.kind)\n",
    "print(\"directed:\", [edge for edge in graph.oriented_edges() if edge[2] == \"directed\"])\n",
    "print(\"test:\", pc.metadata[\"indep_test\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-10",
   "metadata": {},
   "source": [
    "`andrey.viz.draw` renders the graph as an SVG, which the notebook shows. A directed edge ends\n",
    "in an arrowhead; an undirected edge has none and is drawn in amber."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "quick_start-11",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 360 478\" width=\"100%\" font-family=\"Inter, system-ui, sans-serif\"><rect width=\"360\" height=\"478\" fill=\"#fafbfc\"/><line x1=\"93.00\" y1=\"445.91\" x2=\"167.00\" y2=\"445.91\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"90.64\" y1=\"282.11\" x2=\"169.36\" y2=\"337.38\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.93\" y1=\"354.11\" x2=\"167.07\" y2=\"346.23\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.74\" y1=\"191.21\" x2=\"167.26\" y2=\"176.15\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.98\" y1=\"194.48\" x2=\"267.02\" y2=\"203.74\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"192.42\" y1=\"177.41\" x2=\"267.58\" y2=\"200.59\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"158.68\" y1=\"63.89\" x2=\"92.05\" y2=\"36.96\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.95,67.64 160.55,59.25 156.80,68.53\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"158.68\" y1=\"81.13\" x2=\"92.05\" y2=\"108.06\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.95,77.38 156.80,76.50 160.55,85.77\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><circle cx=\"80.00\" cy=\"445.91\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"470.91\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">raf</text><circle cx=\"180.00\" cy=\"445.91\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"470.91\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">mek</text><circle cx=\"80.00\" cy=\"274.64\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"299.64\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">plc</text><circle cx=\"80.00\" cy=\"355.49\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"380.49\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip2</text><circle cx=\"180.00\" cy=\"344.85\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"369.85\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip3</text><circle cx=\"80.00\" cy=\"193.79\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"218.79\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">erk</text><circle cx=\"180.00\" cy=\"173.57\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"198.57\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">akt</text><circle cx=\"280.00\" cy=\"204.43\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"229.43\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pka</text><circle cx=\"180.00\" cy=\"72.51\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"97.51\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pkc</text><circle cx=\"80.00\" cy=\"32.09\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"57.09\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">p38</text><circle cx=\"80.00\" cy=\"112.94\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"137.94\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">jnk</text></svg>"
      ],
      "text/plain": [
       "'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 360 478\" width=\"100%\" font-family=\"Inter, system-ui, sans-serif\"><rect width=\"360\" height=\"478\" fill=\"#fafbfc\"/><line x1=\"93.00\" y1=\"445.91\" x2=\"167.00\" y2=\"445.91\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"90.64\" y1=\"282.11\" x2=\"169.36\" y2=\"337.38\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.93\" y1=\"354.11\" x2=\"167.07\" y2=\"346.23\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.74\" y1=\"191.21\" x2=\"167.26\" y2=\"176.15\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.98\" y1=\"194.48\" x2=\"267.02\" y2=\"203.74\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"192.42\" y1=\"177.41\" x2=\"267.58\" y2=\"200.59\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"158.68\" y1=\"63.89\" x2=\"92.05\" y2=\"36.96\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.95,67.64 160.55,59.25 156.80,68.53\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"158.68\" y1=\"81.13\" x2=\"92.05\" y2=\"108.06\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.95,77.38 156.80,76.50 160.55,85.77\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><circle cx=\"80.00\" cy=\"445.91\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"470.91\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">raf</text><circle cx=\"180.00\" cy=\"445.91\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"470.91\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">mek</text><circle cx=\"80.00\" cy=\"274.64\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"299.64\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">plc</text><circle cx=\"80.00\" cy=\"355.49\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"380.49\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip2</text><circle cx=\"180.00\" cy=\"344.85\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"369.85\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip3</text><circle cx=\"80.00\" cy=\"193.79\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"218.79\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">erk</text><circle cx=\"180.00\" cy=\"173.57\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"198.57\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">akt</text><circle cx=\"280.00\" cy=\"204.43\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"229.43\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pka</text><circle cx=\"180.00\" cy=\"72.51\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"97.51\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pkc</text><circle cx=\"80.00\" cy=\"32.09\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"57.09\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">p38</text><circle cx=\"80.00\" cy=\"112.94\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"137.94\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">jnk</text></svg>'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "andrey.viz.draw(pc.structure)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-12",
   "metadata": {},
   "source": [
    "## GES\n",
    "\n",
    "GES, greedy equivalence search, reaches a graph a different way: it searches for the graph\n",
    "with the best score, instead of testing independence. You call it the same way."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "quick_start-13",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ges  cpdag  |  11 nodes  |  8 edges (6 undirected, 2 directed)\n",
      "\n",
      "  raf -- mek\n",
      "  plc -- pip3\n",
      "  pip2 -- pip3\n",
      "  erk -- akt\n",
      "  erk -- pka\n",
      "  akt -- pka\n",
      "  p38 -> pkc\n",
      "  jnk -> pkc\n",
      "\n",
      "  score: 6.692e+04\n",
      "  score_func: bic\n",
      "  penalty_discount: 1\n",
      "  ebic_gamma: 1\n",
      "  tie_break: rank\n"
     ]
    }
   ],
   "source": [
    "ges = andrey.ges(data)\n",
    "print(ges)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-14",
   "metadata": {},
   "source": [
    "GES returns a CPDAG too, and on these data it is the same graph as PC's. Its metadata holds\n",
    "the score of the graph, where lower is better, and the settings that produced it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "quick_start-15",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "same edges as PC: True\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 360 478\" width=\"100%\" font-family=\"Inter, system-ui, sans-serif\"><rect width=\"360\" height=\"478\" fill=\"#fafbfc\"/><line x1=\"93.00\" y1=\"445.91\" x2=\"167.00\" y2=\"445.91\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"90.64\" y1=\"282.11\" x2=\"169.36\" y2=\"337.38\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.93\" y1=\"354.11\" x2=\"167.07\" y2=\"346.23\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.74\" y1=\"191.21\" x2=\"167.26\" y2=\"176.15\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.98\" y1=\"194.48\" x2=\"267.02\" y2=\"203.74\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"192.42\" y1=\"177.41\" x2=\"267.58\" y2=\"200.59\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"158.68\" y1=\"63.89\" x2=\"92.05\" y2=\"36.96\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.95,67.64 160.55,59.25 156.80,68.53\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"158.68\" y1=\"81.13\" x2=\"92.05\" y2=\"108.06\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.95,77.38 156.80,76.50 160.55,85.77\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><circle cx=\"80.00\" cy=\"445.91\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"470.91\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">raf</text><circle cx=\"180.00\" cy=\"445.91\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"470.91\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">mek</text><circle cx=\"80.00\" cy=\"274.64\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"299.64\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">plc</text><circle cx=\"80.00\" cy=\"355.49\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"380.49\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip2</text><circle cx=\"180.00\" cy=\"344.85\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"369.85\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip3</text><circle cx=\"80.00\" cy=\"193.79\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"218.79\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">erk</text><circle cx=\"180.00\" cy=\"173.57\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"198.57\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">akt</text><circle cx=\"280.00\" cy=\"204.43\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"229.43\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pka</text><circle cx=\"180.00\" cy=\"72.51\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"97.51\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pkc</text><circle cx=\"80.00\" cy=\"32.09\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"57.09\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">p38</text><circle cx=\"80.00\" cy=\"112.94\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"137.94\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">jnk</text></svg>"
      ],
      "text/plain": [
       "'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 360 478\" width=\"100%\" font-family=\"Inter, system-ui, sans-serif\"><rect width=\"360\" height=\"478\" fill=\"#fafbfc\"/><line x1=\"93.00\" y1=\"445.91\" x2=\"167.00\" y2=\"445.91\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"90.64\" y1=\"282.11\" x2=\"169.36\" y2=\"337.38\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.93\" y1=\"354.11\" x2=\"167.07\" y2=\"346.23\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.74\" y1=\"191.21\" x2=\"167.26\" y2=\"176.15\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"92.98\" y1=\"194.48\" x2=\"267.02\" y2=\"203.74\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"192.42\" y1=\"177.41\" x2=\"267.58\" y2=\"200.59\" stroke=\"#e0982b\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><line x1=\"158.68\" y1=\"63.89\" x2=\"92.05\" y2=\"36.96\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.95,67.64 160.55,59.25 156.80,68.53\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"158.68\" y1=\"81.13\" x2=\"92.05\" y2=\"108.06\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.95,77.38 156.80,76.50 160.55,85.77\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><circle cx=\"80.00\" cy=\"445.91\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"470.91\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">raf</text><circle cx=\"180.00\" cy=\"445.91\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"470.91\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">mek</text><circle cx=\"80.00\" cy=\"274.64\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"299.64\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">plc</text><circle cx=\"80.00\" cy=\"355.49\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"380.49\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip2</text><circle cx=\"180.00\" cy=\"344.85\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"369.85\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip3</text><circle cx=\"80.00\" cy=\"193.79\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"218.79\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">erk</text><circle cx=\"180.00\" cy=\"173.57\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"198.57\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">akt</text><circle cx=\"280.00\" cy=\"204.43\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"229.43\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pka</text><circle cx=\"180.00\" cy=\"72.51\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"97.51\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pkc</text><circle cx=\"80.00\" cy=\"32.09\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"57.09\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">p38</text><circle cx=\"80.00\" cy=\"112.94\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"137.94\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">jnk</text></svg>'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"same edges as PC:\", ges.structure.oriented_edges() == pc.structure.oriented_edges())\n",
    "andrey.viz.draw(ges.structure)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-16",
   "metadata": {},
   "source": [
    "## FCI\n",
    "\n",
    "PC and GES assume that every common cause of two measured variables is measured too. FCI does\n",
    "not: it allows hidden common causes, and says less about each edge in return."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "quick_start-17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fci  pag  |  11 nodes  |  8 edges (6 circle, 2 partially_directed)\n",
      "\n",
      "  raf o-o mek\n",
      "  plc o-o pip3\n",
      "  pip2 o-o pip3\n",
      "  erk o-o akt\n",
      "  erk o-o pka\n",
      "  akt o-o pka\n",
      "  p38 o-> pkc\n",
      "  jnk o-> pkc\n",
      "\n",
      "  indep_test: fisherz\n",
      "  tie_break: rank\n"
     ]
    }
   ],
   "source": [
    "fci = andrey.fci(data)\n",
    "print(fci)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-18",
   "metadata": {},
   "source": [
    "FCI returns a PAG. A circle (`o`) at an end of an edge means the tests do not say whether that\n",
    "end is an arrowhead or a tail. So `p38 o-> pkc` says that pkc does not cause p38, and leaves\n",
    "open whether p38 causes pkc or a hidden variable causes both. The drawing shows each circle as\n",
    "a hollow circle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "quick_start-19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 360 498\" width=\"100%\" font-family=\"Inter, system-ui, sans-serif\"><rect width=\"360\" height=\"498\" fill=\"#fafbfc\"/><line x1=\"101.40\" y1=\"466.02\" x2=\"158.60\" y2=\"466.02\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"97.20\" cy=\"466.02\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"162.80\" cy=\"466.02\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"97.51\" y1=\"307.04\" x2=\"162.49\" y2=\"352.66\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"94.08\" cy=\"304.63\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"165.92\" cy=\"355.07\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"101.28\" y1=\"373.33\" x2=\"158.72\" y2=\"367.22\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"97.10\" cy=\"373.78\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"162.90\" cy=\"366.78\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"100.98\" y1=\"209.65\" x2=\"159.02\" y2=\"197.92\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"96.86\" cy=\"210.49\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"163.14\" cy=\"197.09\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"101.37\" y1=\"215.03\" x2=\"258.63\" y2=\"223.40\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"97.18\" cy=\"214.81\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"262.82\" cy=\"223.62\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"200.45\" y1=\"199.99\" x2=\"259.55\" y2=\"218.22\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"196.44\" cy=\"198.75\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"263.56\" cy=\"219.46\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"99.67\" y1=\"80.69\" x2=\"161.70\" y2=\"43.07\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"91.12,85.88 102.26,84.97 97.07,76.42\" fill=\"#7c5cd8\" stroke-linejoin=\"round\"/><circle cx=\"165.29\" cy=\"40.90\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"102.54\" y1=\"97.17\" x2=\"159.02\" y2=\"108.59\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"92.74,95.19 101.55,102.07 103.53,92.27\" fill=\"#7c5cd8\" stroke-linejoin=\"round\"/><circle cx=\"163.14\" cy=\"109.42\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"80.00\" cy=\"466.02\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"491.02\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">raf</text><circle cx=\"180.00\" cy=\"466.02\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"491.02\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">mek</text><circle cx=\"80.00\" cy=\"294.74\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"319.74\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">plc</text><circle cx=\"80.00\" cy=\"375.60\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"400.60\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip2</text><circle cx=\"180.00\" cy=\"364.96\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"389.96\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip3</text><circle cx=\"80.00\" cy=\"213.89\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"238.89\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">erk</text><circle cx=\"180.00\" cy=\"193.68\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"218.68\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">akt</text><circle cx=\"280.00\" cy=\"224.53\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"249.53\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pka</text><circle cx=\"80.00\" cy=\"92.62\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"117.62\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pkc</text><circle cx=\"180.00\" cy=\"31.98\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"56.98\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">p38</text><circle cx=\"180.00\" cy=\"112.83\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"137.83\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">jnk</text></svg>"
      ],
      "text/plain": [
       "'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 360 498\" width=\"100%\" font-family=\"Inter, system-ui, sans-serif\"><rect width=\"360\" height=\"498\" fill=\"#fafbfc\"/><line x1=\"101.40\" y1=\"466.02\" x2=\"158.60\" y2=\"466.02\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"97.20\" cy=\"466.02\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"162.80\" cy=\"466.02\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"97.51\" y1=\"307.04\" x2=\"162.49\" y2=\"352.66\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"94.08\" cy=\"304.63\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"165.92\" cy=\"355.07\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"101.28\" y1=\"373.33\" x2=\"158.72\" y2=\"367.22\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"97.10\" cy=\"373.78\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"162.90\" cy=\"366.78\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"100.98\" y1=\"209.65\" x2=\"159.02\" y2=\"197.92\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"96.86\" cy=\"210.49\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"163.14\" cy=\"197.09\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"101.37\" y1=\"215.03\" x2=\"258.63\" y2=\"223.40\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"97.18\" cy=\"214.81\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"262.82\" cy=\"223.62\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"200.45\" y1=\"199.99\" x2=\"259.55\" y2=\"218.22\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><circle cx=\"196.44\" cy=\"198.75\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"263.56\" cy=\"219.46\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"99.67\" y1=\"80.69\" x2=\"161.70\" y2=\"43.07\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"91.12,85.88 102.26,84.97 97.07,76.42\" fill=\"#7c5cd8\" stroke-linejoin=\"round\"/><circle cx=\"165.29\" cy=\"40.90\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><line x1=\"102.54\" y1=\"97.17\" x2=\"159.02\" y2=\"108.59\" stroke=\"#7c5cd8\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"92.74,95.19 101.55,102.07 103.53,92.27\" fill=\"#7c5cd8\" stroke-linejoin=\"round\"/><circle cx=\"163.14\" cy=\"109.42\" r=\"4.20\" fill=\"#ffffff\" stroke=\"#7c5cd8\" stroke-width=\"2.0\"/><circle cx=\"80.00\" cy=\"466.02\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"491.02\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">raf</text><circle cx=\"180.00\" cy=\"466.02\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"491.02\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">mek</text><circle cx=\"80.00\" cy=\"294.74\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"319.74\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">plc</text><circle cx=\"80.00\" cy=\"375.60\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"400.60\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip2</text><circle cx=\"180.00\" cy=\"364.96\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"389.96\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip3</text><circle cx=\"80.00\" cy=\"213.89\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"238.89\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">erk</text><circle cx=\"180.00\" cy=\"193.68\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"218.68\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">akt</text><circle cx=\"280.00\" cy=\"224.53\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"249.53\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pka</text><circle cx=\"80.00\" cy=\"92.62\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"117.62\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pkc</text><circle cx=\"180.00\" cy=\"31.98\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"56.98\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">p38</text><circle cx=\"180.00\" cy=\"112.83\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"137.83\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">jnk</text></svg>'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "andrey.viz.draw(fci.structure)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-20",
   "metadata": {},
   "source": [
    "## DirectLiNGAM\n",
    "\n",
    "DirectLiNGAM assumes that each variable is a linear function of its causes plus noise that is\n",
    "not Gaussian. When that holds, the data identify one graph, so it returns a DAG: every edge has\n",
    "a direction."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "quick_start-21",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "direct_lingam  dag  |  11 nodes  |  11 edges (11 directed)\n",
      "\n",
      "  mek -> raf  (+1.2)\n",
      "  mek -> pip2  (+0.285)\n",
      "  plc -> pip2  (+0.583)\n",
      "  plc -> pip3  (+0.236)\n",
      "  pip2 -> pip3  (+0.0952)\n",
      "  erk -> akt  (+1.37)\n",
      "  erk -> pka  (+1.84)\n",
      "  pka -> akt  (+0.017)\n",
      "  pkc -> p38  (+1.28)\n",
      "  jnk -> pkc  (-0.0526)\n",
      "  jnk -> p38  (+0.0582)\n",
      "\n",
      "  order: erk -> plc -> mek -> pip2 -> pip3 -> pka -> jnk -> akt -> pkc -> p38 -> raf\n",
      "\n",
      "  tie_break: rank\n"
     ]
    }
   ],
   "source": [
    "lingam = andrey.direct_lingam(data)\n",
    "print(lingam)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-22",
   "metadata": {},
   "source": [
    "The number beside an edge is its weight, the coefficient of the cause in the linear equation\n",
    "for the effect, and `order` is the causal order the method found. These directions rest on the\n",
    "method's assumption, so treat them as hypotheses to test."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "quick_start-23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 360 446\" width=\"100%\" font-family=\"Inter, system-ui, sans-serif\"><rect width=\"360\" height=\"446\" fill=\"#fafbfc\"/><line x1=\"157.29\" y1=\"290.99\" x2=\"92.84\" y2=\"301.27\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.16,289.41 156.50,286.05 158.08,295.92\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"90.91\" y1=\"310.40\" x2=\"160.71\" y2=\"355.69\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"169.09,361.14 163.43,351.50 157.98,359.89\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"91.82\" y1=\"408.55\" x2=\"159.08\" y2=\"377.78\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"168.18,373.62 157.00,373.23 161.16,382.33\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"92.96\" y1=\"412.92\" x2=\"257.07\" y2=\"399.83\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.04,399.03 256.68,394.85 257.47,404.81\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"192.46\" y1=\"371.92\" x2=\"257.96\" y2=\"391.43\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.54,394.29 259.38,386.64 256.53,396.23\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"92.95\" y1=\"175.55\" x2=\"257.09\" y2=\"160.71\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.05,159.81 256.64,155.73 257.54,165.69\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"92.46\" y1=\"180.43\" x2=\"157.96\" y2=\"199.94\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.54,202.80 159.38,195.15 156.53,204.74\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"259.25\" y1=\"168.57\" x2=\"191.73\" y2=\"200.90\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"268.27,164.25 257.10,164.06 261.41,173.08\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"192.22\" y1=\"36.46\" x2=\"258.37\" y2=\"60.39\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.78,63.79 260.07,55.69 256.67,65.09\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"158.02\" y1=\"38.82\" x2=\"92.42\" y2=\"59.06\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.58,35.87 156.55,34.05 159.50,43.60\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"257.01\" y1=\"67.60\" x2=\"93.00\" y2=\"63.24\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.00,67.87 257.14,62.60 256.88,72.60\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><circle cx=\"180.00\" cy=\"287.36\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"312.36\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">raf</text><circle cx=\"80.00\" cy=\"303.32\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"328.32\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">mek</text><circle cx=\"80.00\" cy=\"413.96\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"438.96\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">plc</text><circle cx=\"180.00\" cy=\"368.21\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"393.21\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip2</text><circle cx=\"280.00\" cy=\"398.00\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"423.00\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip3</text><circle cx=\"80.00\" cy=\"176.72\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"201.72\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">erk</text><circle cx=\"280.00\" cy=\"158.64\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"183.64\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">akt</text><circle cx=\"180.00\" cy=\"206.51\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"231.51\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pka</text><circle cx=\"180.00\" cy=\"32.04\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"57.04\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pkc</text><circle cx=\"280.00\" cy=\"68.21\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"93.21\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">p38</text><circle cx=\"80.00\" cy=\"62.89\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"87.89\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">jnk</text></svg>"
      ],
      "text/plain": [
       "'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 360 446\" width=\"100%\" font-family=\"Inter, system-ui, sans-serif\"><rect width=\"360\" height=\"446\" fill=\"#fafbfc\"/><line x1=\"157.29\" y1=\"290.99\" x2=\"92.84\" y2=\"301.27\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.16,289.41 156.50,286.05 158.08,295.92\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"90.91\" y1=\"310.40\" x2=\"160.71\" y2=\"355.69\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"169.09,361.14 163.43,351.50 157.98,359.89\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"91.82\" y1=\"408.55\" x2=\"159.08\" y2=\"377.78\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"168.18,373.62 157.00,373.23 161.16,382.33\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"92.96\" y1=\"412.92\" x2=\"257.07\" y2=\"399.83\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.04,399.03 256.68,394.85 257.47,404.81\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"192.46\" y1=\"371.92\" x2=\"257.96\" y2=\"391.43\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.54,394.29 259.38,386.64 256.53,396.23\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"92.95\" y1=\"175.55\" x2=\"257.09\" y2=\"160.71\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.05,159.81 256.64,155.73 257.54,165.69\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"92.46\" y1=\"180.43\" x2=\"157.96\" y2=\"199.94\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.54,202.80 159.38,195.15 156.53,204.74\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"259.25\" y1=\"168.57\" x2=\"191.73\" y2=\"200.90\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"268.27,164.25 257.10,164.06 261.41,173.08\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"192.22\" y1=\"36.46\" x2=\"258.37\" y2=\"60.39\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.78,63.79 260.07,55.69 256.67,65.09\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"158.02\" y1=\"38.82\" x2=\"92.42\" y2=\"59.06\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"167.58,35.87 156.55,34.05 159.50,43.60\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><line x1=\"257.01\" y1=\"67.60\" x2=\"93.00\" y2=\"63.24\" stroke=\"#3a4658\" stroke-width=\"2.0\" stroke-linecap=\"round\"/><polygon points=\"267.00,67.87 257.14,62.60 256.88,72.60\" fill=\"#3a4658\" stroke-linejoin=\"round\"/><circle cx=\"180.00\" cy=\"287.36\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"312.36\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">raf</text><circle cx=\"80.00\" cy=\"303.32\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"328.32\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">mek</text><circle cx=\"80.00\" cy=\"413.96\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"438.96\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">plc</text><circle cx=\"180.00\" cy=\"368.21\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"393.21\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip2</text><circle cx=\"280.00\" cy=\"398.00\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"423.00\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pip3</text><circle cx=\"80.00\" cy=\"176.72\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"201.72\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">erk</text><circle cx=\"280.00\" cy=\"158.64\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"183.64\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">akt</text><circle cx=\"180.00\" cy=\"206.51\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"231.51\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pka</text><circle cx=\"180.00\" cy=\"32.04\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"180.00\" y=\"57.04\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">pkc</text><circle cx=\"280.00\" cy=\"68.21\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"280.00\" y=\"93.21\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">p38</text><circle cx=\"80.00\" cy=\"62.89\" r=\"13.00\" fill=\"#ffffff\" stroke=\"#182233\" stroke-width=\"1.8\"/><text x=\"80.00\" y=\"87.89\" text-anchor=\"middle\" font-size=\"11\" font-weight=\"600\" fill=\"#5c6675\" stroke=\"#fafbfc\" stroke-width=\"3\" stroke-linejoin=\"round\" paint-order=\"stroke\">jnk</text></svg>'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "andrey.viz.draw(lingam.structure)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "quick_start-24",
   "metadata": {},
   "source": [
    "## Next\n",
    "\n",
    "The [Methods notebooks](https://andrey.abel.ai/docs/examples/index.html#methods) each take one\n",
    "family of methods further: its other methods, its settings, and the data it suits."
   ]
  }
 ],
 "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.14.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
