{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Interactive Accumulator Models with `Evidently`\n", "\n", "This notebook contains interactive visualisations for a number of evidence models\n", "created using the [evidently](https://github.com/EoinTravers/Evidently) package for python.\n", "\n", "If you're running this notebook on [mybinder.org](https://mybinder.org/),\n", "and find things to be a little slow,\n", "you can run the code on your own machine instead by downloading the \n", "[GitHub repository](https://github.com/EoinTravers/Evidently).\n", "\n", "If you're unfamiliar with [Jupyter notebooks](https://jupyter.org/),\n", "you can:\n", "- Run each code cell by clicking on it to select it,\n", " then clicking the \n", " [ Run]\n", " button in the toolbar above.\n", "- Run everything by clicking [Cell] → [Run All]\n", "\n", "Either way, some of the cells below will generate interactive plots with sliders attached.\n", "Go ahead and play with the sliders, and see what happens!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import matplotlib as mpl\n", "import evidently\n", "\n", "from ipywidgets import interact, FloatSlider\n", "def fs(v, low, high, step, desc=''):\n", " return FloatSlider(value=v, min=low, max=high, step=step, description=desc, continuous_update=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple Wald Model\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(evidently.Wald.__doc__) # Print the documentation for this model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def wald_simulation_plot(t0=1., v=.5, z=0, a=1., c=1.):\n", " model = evidently.Wald(pars=[t0, v, z, a, c], max_time=5)\n", " evidently.viz.visualise_model(model, model_type='wald', measure='raw')\n", " title = 'Start time = %.1f, Drift = %.1f, Start = %.1f, Threshold = %.1f' % (t0, v, z, a)\n", " plt.suptitle(title, y=1.01)\n", " plt.show()\n", "\n", "interact(wald_simulation_plot,\n", " t0 = fs(1., 0, 5., .1, 'Start time'),\n", " v = fs(.5, 0, 2., .1, 'Drift'),\n", " z = fs(0, 0, .5, .1, 'Starting point'),\n", " a = fs(.5, 0., 2., .1, 'Threshold'),\n", " c = fs(.1, 0., 2., .1, 'Noise SD'));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple Drift Diffusion Model\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(evidently.Diffusion.__doc__)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def ddm_simulation_plot(t0=1., v=.5, z=0., a=.5, c=.1):\n", " model = evidently.Diffusion(pars=[t0, v, z, a, c])\n", " evidently.viz.visualise_model(model)\n", " title = 't0 = %.1f, Drift = %.1f, Bias = %.1f, Threshold = %.1f' % (t0, v, z, a)\n", " plt.suptitle(title, y=1.01)\n", " plt.show()\n", "\n", "interact(ddm_simulation_plot,\n", " t0 = fs(1., 0, 2., .1, 't0'),\n", " v = fs(.5, 0, 2., .1, 'Drift'),\n", " z = fs(-.5, -1., 1., .1, 'Bias'),\n", " a = fs(.5, 0., 2., .1, 'Threshold'),\n", " c = fs(.2, 0., 1., .1, 'Noise SD'));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Hierarchical Drift Diffusion Model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(evidently.HDiffusion.__doc__)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def hddm_simulation_plot(m_t0=1., m_v=.5, m_z=0., m_a=.5,\n", " s_t0=.1, s_v=.1, s_z=.1, s_a=.1, c=.1):\n", " model = evidently.HDiffusion(pars=[m_t0, m_v, m_z, m_a, s_t0, s_v, s_z, s_a, c])\n", " evidently.viz.visualise_model(model, measure='means', threshold=m_a)\n", " title = 't0 = %.1f (%.1f), Drift = %.1f (%.1f), Bias = %.1f (%.1f), Threshold = %.1f (%.1f), Noise = %.1f' % (\n", " m_t0, s_t0, m_v, s_v, m_z, s_z, m_a, s_a, c)\n", " plt.suptitle(title, y=1.05)\n", " plt.show()\n", "\n", "interact(hddm_simulation_plot,\n", " m_t0 = fs(1., 0., 1., .1, 'T0'),\n", " m_v = fs(.5, -1., 1., .1, 'Drift'),\n", " m_z = fs(-.5, -1., 1., .1, 'Bias'),\n", " m_a = fs(1., 0., 2., .1, 'Threshold'),\n", " s_t0 = fs(.1, 0., 1., .1, 'SD T0'),\n", " s_v = fs(.5, 0., 1., .1, 'SD Drift'),\n", " s_z = fs(.1, 0., 1., .1, 'SD Bias'),\n", " s_a = fs(.1, 0., 1., .1, 'SD Threshold'),\n", " c = fs(.1, 0., 1., .1, 'Noise'));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Race" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(evidently.Race.__doc__)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def race_simulation_plot(t1, v1, z1, c1, t2, v2, z2, c2, a):\n", " model = evidently.Race(pars=[t1, v1, z1, c1, t2, v2, z2, c2, a])\n", " evidently.viz.visualise_model(model, model_type='race', measure='means')\n", " title = 'Option #1: t0 = %.1f, Drift = %.1f, Bias = %.1f, Noise = %.1f' % (t1, v1, z1, c1)\n", " title += '\\nOption #2: t0 = %.1f, Drift = %.1f, Bias = %.1f, Noise = %.1f' % (t2, v2, z2, c2)\n", " title += '\\nThreshold: %.1f' % a \n", " plt.suptitle(title, y=1.2)\n", " plt.show()\n", "\n", "interact(race_simulation_plot,\n", " t1 = fs(1., 0, 2., .1, '#1: t0'),\n", " v1 = fs(.5, 0, 2., .1, '#1: Drift'),\n", " z1 = fs(0., 0, 1., .1, '#1: Bias'),\n", " c1 = fs(.1, 0., 1., .1, '#1: Noise SD'),\n", " t2 = fs(2., 0, 2., .1, '#2: t0'),\n", " v2 = fs(.75, 0, 2., .1, '#2: Drift'),\n", " z2 = fs(.2, 0., 1., .1, '#2: Bias'),\n", " c2 = fs(.2, 0., 1., .1, '#2: Noise SD'),\n", " a = fs(.5, 0., 2., .1, 'Threshold'));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Schurger Model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(evidently.models.Schurger.__doc__)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "def schurger_simulation_plot(t0=0., v=.5, k=.6, z=0., a=1., c=1.):\n", " model = evidently.models.Schurger(pars=[t0, v, k, z, a, c], max_time=20.)\n", " evidently.viz.visualise_schurger(model, rp_duration=3)\n", " title = 'Start time = %.1f, Input = %.1f, Decay = %.1f, Start = %.1f, Threshold = %.1f, Noise = %.1f' % (\n", " t0, v, k, z, a, c)\n", " plt.suptitle(title, y=1.05)\n", " plt.show()\n", "\n", "interact(schurger_simulation_plot,\n", " t0 = fs(0., 0, 5., .1, 'Start time'),\n", " v = fs(.5, 0, 2., .1, 'Drift'),\n", " k = fs(.6, 0, 2., .1, 'Decay'),\n", " z = fs(0, 0, 1., .1, 'Starting point'),\n", " a = fs(1., 0., 2., .1, 'Threshold'),\n", " c = fs(.1, 0., 1., .1, 'Noise SD'));" ] } ], "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.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }