{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# silico general demo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "from numpy import random" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import silico" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define a function that takes some parameters and returns a dict of information about the results:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def experiment_f(mean, sigma, seed):\n", " # All seeds should be initialized using a parameter for reproducibility\n", " random.seed(seed)\n", " # Return a dict with the results (must be pickleable)\n", " return {\"value\": random.normal(mean, sigma)}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the values for each of the parameters:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "experiment = silico.Experiment(\n", " [\n", " (\"mean\", [1, 2, 4]),\n", " (\"sigma\", [1, 2, 3]),\n", " (\"seed\", list(range(20))),\n", " ],\n", " experiment_f, # Function\n", " \"experiment-demo\", # Folder where the results are stored\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# If the definition of the experiment has changed, previous results can be deleted by running:\n", "experiment.invalidate()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/json": { "ascii": false, "bar_format": null, "colour": null, "elapsed": 0.017731428146362305, "initial": 0, "n": 0, "ncols": null, "nrows": 67, "postfix": null, "prefix": "", "rate": null, "total": 180, "unit": "it", "unit_divisor": 1000, "unit_scale": false }, "application/vnd.jupyter.widget-view+json": { "model_id": "3d03d1d9fb344ea7a84a99cf559ac071", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/180 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "experiment.run_all()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To obtain a table with results:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | \n", " | \n", " | _run_start | \n", "_elapsed_seconds | \n", "value | \n", "
|---|---|---|---|---|---|
| mean | \n", "sigma | \n", "seed | \n", "\n", " | \n", " | \n", " |
| 1 | \n", "1 | \n", "0 | \n", "2023-03-23 01:20:53.154519 | \n", "0.000054 | \n", "2.764052 | \n", "
| 1 | \n", "2023-03-23 01:20:53.155430 | \n", "0.000050 | \n", "2.624345 | \n", "||
| 2 | \n", "2023-03-23 01:20:53.156125 | \n", "0.000030 | \n", "0.583242 | \n", "||
| 3 | \n", "2023-03-23 01:20:53.156363 | \n", "0.000023 | \n", "2.788628 | \n", "||
| 4 | \n", "2023-03-23 01:20:53.156568 | \n", "0.000021 | \n", "1.050562 | \n", "||
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 4 | \n", "3 | \n", "15 | \n", "2023-03-23 01:20:53.187919 | \n", "0.000010 | \n", "3.063015 | \n", "
| 16 | \n", "2023-03-23 01:20:53.188014 | \n", "0.000010 | \n", "4.383846 | \n", "||
| 17 | \n", "2023-03-23 01:20:53.188111 | \n", "0.000009 | \n", "4.828798 | \n", "||
| 18 | \n", "2023-03-23 01:20:53.188217 | \n", "0.000010 | \n", "4.238285 | \n", "||
| 19 | \n", "2023-03-23 01:20:53.188313 | \n", "0.000010 | \n", "4.663010 | \n", "
180 rows × 3 columns
\n", "| \n", " | \n", " | _elapsed_seconds | \n", "value | \n", "
|---|---|---|---|
| mean | \n", "sigma | \n", "\n", " | \n", " |
| 1 | \n", "1 | \n", "0.000023 ± 0.000002 | \n", "1.58 ± 0.19 | \n", "
| 2 | \n", "0.0000262 ± 0.0000014 | \n", "2.2 ± 0.4 | \n", "|
| 3 | \n", "0.0000219 ± 0.0000009 | \n", "2.7 ± 0.6 | \n", "|
| 2 | \n", "1 | \n", "0.000028 ± 0.000002 | \n", "2.58 ± 0.19 | \n", "
| 2 | \n", "0.0000243 ± 0.0000014 | \n", "3.2 ± 0.4 | \n", "|
| 3 | \n", "0.000024 ± 0.000003 | \n", "3.7 ± 0.6 | \n", "|
| 4 | \n", "1 | \n", "0.0000156 ± 0.0000005 | \n", "4.58 ± 0.19 | \n", "
| 2 | \n", "0.00000995 ± 0.00000009 | \n", "5.2 ± 0.4 | \n", "|
| 3 | \n", "0.00000975 ± 0.00000010 | \n", "5.7 ± 0.6 | \n", "