diff --git a/doc/example/amici.ipynb b/doc/example/amici.ipynb index 3b0bcb96e..703fe4e95 100644 --- a/doc/example/amici.ipynb +++ b/doc/example/amici.ipynb @@ -4,6 +4,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -28,6 +31,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -52,6 +58,7 @@ "import pypesto.store as store\n", "import pypesto.visualize as visualize\n", "import pypesto.visualize.model_fit as model_fit\n", + "import pypesto\n", "\n", "mpl.rcParams[\"figure.dpi\"] = 100\n", "mpl.rcParams[\"font.size\"] = 18\n", @@ -71,6 +78,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -83,6 +93,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -98,6 +111,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -113,6 +129,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -125,6 +144,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -140,6 +162,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -153,6 +178,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -170,6 +198,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -190,6 +221,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -205,6 +239,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -221,6 +258,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -236,6 +276,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -258,6 +301,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -273,6 +319,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -286,6 +335,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -299,6 +351,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -316,6 +371,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -331,6 +389,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -429,6 +490,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -470,6 +534,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -499,6 +566,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -515,6 +585,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -532,6 +605,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -554,6 +630,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -567,6 +646,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -586,6 +668,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -598,6 +683,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -610,6 +698,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -617,13 +708,13 @@ "source": [ "#### Background on PEtab\n", "\n", - "\"pyPESTO\n", + "\"PEtab\n", "\n", "pyPESTO supports the [PEtab](https://github.com/PEtab-dev/PEtab) standard. PEtab is a data format for specifying parameter estimation problems in systems biology.\n", "\n", "A PEtab problem consist of an [SBML](https://sbml.org) file, defining the model topology and a set of `.tsv` files, defining experimental conditions, observables, measurements and parameters (and their optimization bounds, scale, priors...). All files that make up a PEtab problem can be structured in a `.yaml` file. The `pypesto.Objective` coming from a PEtab problem corresponds to the negative-log-likelihood/negative-log-posterior distribution of the parameters.\n", "\n", - "For more details on PEtab, the interested reader is referred to [PEtab's format definition](https://petab.readthedocs.io/en/latest/documentation_data_format.html), for examples the reader is referred to the [PEtab benchmark collection](https://github.com/Benchmarking-Initiative/Benchmark-Models-PEtab). The Model from _[Böhm et al. JProteomRes 2014](https://pubs.acs.org/doi/abs/10.1021/pr5006923)_ is part of the benchmark collection and will be used as the running example throughout this notebook.\n" + "For more details on PEtab, the interested reader is referred to [PEtab's format definition](https://petab.readthedocs.io/en/latest/documentation_data_format.html), for examples the reader is referred to the [PEtab benchmark collection](https://github.com/Benchmarking-Initiative/Benchmark-Models-PEtab). For demonstration purposes, a simple model of conversion-reaction will be used as the running example throughout this notebook.\n" ] }, { @@ -631,6 +722,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -638,6 +732,7 @@ "outputs": [], "source": [ "%%capture\n", + "\n", "petab_yaml = f\"./{model_name}/{model_name}.yaml\"\n", "\n", "petab_problem = petab.Problem.from_yaml(petab_yaml)\n", @@ -650,6 +745,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -665,6 +763,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -680,6 +781,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -695,6 +799,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -709,6 +816,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -722,6 +832,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -729,7 +842,7 @@ "outputs": [], "source": [ "# call the objective function\n", - "print(f\"Objective value: {problem.objective(benchmark_parameters)}\")\n", + "print(f\"Objective value: {problem.objective(petab_problem.x_free_indices)}\")\n", "# change things in the model\n", "problem.objective.amici_model.requireSensitivitiesForAllParameters()\n", "# change solver settings\n", @@ -746,6 +859,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -758,6 +874,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -772,6 +891,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -789,6 +911,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -806,14 +931,17 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } }, "source": [ - "### Startpoint method\n", + "### History options\n", "\n", - "The startpoint method describes how you want to choose your startpoints, in case you do a multistart optimization. The default here is `uniform` meaning that each startpoint is a uniform sample from the allowed parameter space. The other two notable options are either `latin_hypercube` or a self defined function." + "In some cases, it is good to trace what the optimizer did in each step, i.e., the history. There is a multitude of options on what to report here, but the most important one is `trace_record` which turns the history function on and off." ] }, { @@ -821,48 +949,44 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ - "startpoint_method = pypesto.startpoint.uniform" + "# save optimizer trace\n", + "history_options = pypesto.HistoryOptions(trace_record=True)" ] }, { "cell_type": "markdown", - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%% md\n" - } - }, + "metadata": {}, "source": [ - "### History options\n", + "### Startpoint method\n", "\n", - "In some cases, it is good to trace what the optimizer did in each step, i.e., the history. There is a multitude of options on what to report here, but the most important one is `trace_record` which turns the history function on and off." + "The startpoint method describes how you want to choose your startpoints, in case you do a multistart optimization. The default here is `uniform` meaning that each startpoint is a uniform sample from the allowed parameter space. The other two notable options are either `latin_hypercube` or a self-defined function. The startpoint method is an inherent attribute of the problem and can be set there." ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - }, + "metadata": {}, "outputs": [], "source": [ - "# save optimizer trace\n", - "history_options = pypesto.HistoryOptions(trace_record=True)" + "problem.startpoint_method = pypesto.startpoint.uniform" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -878,6 +1002,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -892,6 +1019,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -907,6 +1037,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -922,6 +1055,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -933,7 +1069,6 @@ " problem=problem,\n", " optimizer=optimizer,\n", " n_starts=n_starts,\n", - " startpoint_method=startpoint_method,\n", " engine=engine,\n", " options=opt_options,\n", ")" @@ -943,6 +1078,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -956,6 +1094,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -969,6 +1110,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -983,6 +1127,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -995,6 +1142,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1010,6 +1160,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1025,6 +1178,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1042,6 +1198,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1055,6 +1214,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1069,6 +1231,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1084,6 +1249,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1097,6 +1265,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1111,7 +1282,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "pycharm": { "name": "#%%\n" } @@ -1125,6 +1295,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1140,6 +1313,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1155,6 +1331,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1168,18 +1347,24 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } }, "source": [ - "We definitely need to look further into it, and thus we turn to uncertainty quantification in the next section." + "However, these visualizations are only an indicator for possible uncertainties. In the next section we turn to proper uncertainty quantification." ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1196,6 +1381,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1213,6 +1401,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1234,6 +1425,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1247,6 +1441,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1261,6 +1458,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1276,6 +1476,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1287,7 +1490,7 @@ "result = sample.sample(\n", " problem=problem,\n", " sampler=sampler,\n", - " n_samples=5000,\n", + " n_samples=1000,\n", " result=result,\n", ")" ] @@ -1296,6 +1499,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1309,6 +1515,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1324,6 +1533,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1337,6 +1549,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1351,6 +1566,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1364,6 +1582,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1389,6 +1610,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1402,6 +1626,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1419,6 +1646,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1432,6 +1662,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1445,6 +1678,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1457,6 +1693,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -1470,6 +1709,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -1497,7 +1739,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.10" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/censored_data.ipynb b/doc/example/censored_data.ipynb index 28ff83c3b..c5ac649db 100644 --- a/doc/example/censored_data.ipynb +++ b/doc/example/censored_data.ipynb @@ -237,7 +237,7 @@ ], "metadata": { "kernelspec": { - "display_name": "dev_venv", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -251,7 +251,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.2" + "version": "3.12.3" }, "vscode": { "interpreter": { @@ -260,5 +260,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/doc/example/conversion_reaction.ipynb b/doc/example/conversion_reaction.ipynb index e31217c77..c909388de 100644 --- a/doc/example/conversion_reaction.ipynb +++ b/doc/example/conversion_reaction.ipynb @@ -144,6 +144,7 @@ }, "outputs": [], "source": [ + "%%time\n", "# create objective function from amici model\n", "# pesto.AmiciObjective is derived from pesto.Objective,\n", "# the general pesto objective function class\n", @@ -157,7 +158,7 @@ "\n", "# do the optimization\n", "result = optimize.minimize(\n", - " problem=problem, optimizer=optimizer, n_starts=100, filename=None\n", + " problem=problem, optimizer=optimizer, n_starts=10, filename=None\n", ")" ] }, @@ -221,7 +222,7 @@ " problem=problem,\n", " result=result,\n", " optimizer=optimizer,\n", - " profile_index=np.array([1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0]),\n", + " profile_index=np.array([0,1]),\n", " result_index=0,\n", " profile_options=profile_options,\n", " filename=None,\n", @@ -270,7 +271,7 @@ ")\n", "\n", "result = sample.sample(\n", - " problem, n_samples=10000, sampler=sampler, result=result, filename=None\n", + " problem, n_samples=1000, sampler=sampler, result=result, filename=None\n", ")" ] }, @@ -425,7 +426,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/custom_objective_function.ipynb b/doc/example/custom_objective_function.ipynb index 35c985884..f1276c5a4 100644 --- a/doc/example/custom_objective_function.ipynb +++ b/doc/example/custom_objective_function.ipynb @@ -4,6 +4,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -16,6 +19,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -30,6 +36,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -48,6 +57,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -63,6 +75,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -89,6 +104,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -101,6 +119,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -113,6 +134,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -127,6 +151,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -145,6 +172,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -159,6 +189,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -181,6 +214,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -194,6 +230,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -216,6 +255,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -229,6 +271,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -260,6 +305,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -281,6 +329,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -301,6 +352,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -320,6 +374,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -333,6 +390,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -349,6 +409,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -362,6 +425,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -383,6 +449,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -396,12 +465,16 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ + "%%time\n", "# run optimization of problem 1\n", "result1 = optimize.minimize(\n", " problem=problem1, optimizer=optimizer, n_starts=n_starts, engine=engine\n", @@ -424,6 +497,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -437,6 +513,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -461,6 +540,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -477,6 +559,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -490,6 +575,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -507,6 +595,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -520,6 +611,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -537,6 +631,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -550,6 +647,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -572,6 +672,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -584,6 +687,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -599,6 +705,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -636,12 +745,16 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ + "%%time\n", "# compute profiles\n", "profile_options = profile.ProfileOptions(whole_path=True)\n", "\n", @@ -649,7 +762,7 @@ " problem=problem1,\n", " result=result1,\n", " optimizer=optimizer,\n", - " profile_index=np.array([0, 1, 3, 5]),\n", + " profile_index=np.array([0, 3]),\n", " result_index=0,\n", " profile_options=profile_options,\n", " filename=None,\n", @@ -660,7 +773,7 @@ " problem=problem1,\n", " result=result1,\n", " optimizer=optimizer,\n", - " profile_index=np.array([0, 1, 3, 5]),\n", + " profile_index=np.array([0, 3]),\n", " result_index=-1,\n", " profile_options=profile_options,\n", " filename=None,\n", @@ -669,7 +782,7 @@ " problem=problem4,\n", " result=result4,\n", " optimizer=optimizer,\n", - " profile_index=np.array([0, 1, 3, 5]),\n", + " profile_index=np.array([0, 3]),\n", " result_index=0,\n", " profile_options=profile_options,\n", " filename=None,\n", @@ -681,6 +794,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -690,7 +806,7 @@ "# specify the parameters, for which profiles should be computed\n", "visualize.profiles(\n", " result1,\n", - " profile_indices=[0, 1, 3, 5],\n", + " profile_indices=[0, 3],\n", " reference=[ref, ref2],\n", " profile_list_ids=[0, 1],\n", ");" @@ -701,6 +817,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -709,7 +828,7 @@ "source": [ "visualize.profiles(\n", " result4,\n", - " profile_indices=[0, 1, 3, 5],\n", + " profile_indices=[0, 3],\n", " reference=[ref4],\n", ");" ] @@ -718,6 +837,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -730,6 +852,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -742,6 +867,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -755,6 +883,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -774,6 +905,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -787,6 +921,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -795,7 +932,7 @@ "source": [ "axes = visualize.profiles(\n", " result1,\n", - " profile_indices=[0, 1, 3, 5],\n", + " profile_indices=[0, 3],\n", " profile_list_ids=[0, 2],\n", " ratio_min=0.01,\n", " colors=[(1, 0, 0, 1), (0, 0, 1, 1)],\n", @@ -811,6 +948,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -825,23 +965,23 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" + "pygments_lexer": "ipython3", + "version": "3.12.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } diff --git a/doc/example/fixed_parameters.ipynb b/doc/example/fixed_parameters.ipynb index 6f8838d9a..6074a50b7 100644 --- a/doc/example/fixed_parameters.ipynb +++ b/doc/example/fixed_parameters.ipynb @@ -146,7 +146,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.10.2 64-bit", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -160,7 +160,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.2" + "version": "3.12.3" }, "vscode": { "interpreter": { diff --git a/doc/example/getting_started.ipynb b/doc/example/getting_started.ipynb index 2f98e6d69..bf6a80e32 100644 --- a/doc/example/getting_started.ipynb +++ b/doc/example/getting_started.ipynb @@ -33,6 +33,7 @@ "import amici\n", "import matplotlib as mpl\n", "import numpy as np\n", + "import scipy as sp\n", "\n", "import pypesto.optimize as optimize\n", "import pypesto.petab\n", @@ -54,11 +55,11 @@ "source": [ "## 1. Objective Definition\n", "\n", - "PyPESTO allows the definition of a custom objectives, as well as offers support for objectives defined in the [PEtab](https://github.com/PEtab-dev/PEtab) format.\n", + "pyPESTO allows the definition of custom objectives and offers support for objectives defined in the [PEtab](https://github.com/PEtab-dev/PEtab) format.\n", "\n", "### Custom Objective Definition\n", "\n", - "You can define an objective via a python function. Also providing an analytical gradient (and potentially also a Hessian) improves the performance of Gradient/Hessian-based optimizers. When accessing parameter uncertainties via profile-likelihoods/sampling, pyPESTO interprets the objective function as the negative-log-likelihood/negative-log-posterior." + "You can define an objective via a python function. Also providing an analytical gradient (and potentially also a Hessian) improves the performance of Gradient/Hessian-based optimizers. When accessing parameter uncertainties via profile-likelihoods/sampling, pyPESTO interprets the objective function as the negative-log-likelihood/negative-log-posterior. A more in-depth construction of a custom objective function can be found in [a designated example notebook.](./custom_objective_function.ipynb)" ] }, { @@ -195,7 +196,7 @@ "\n", "#### Background on PEtab\n", "\n", - "\"pyPESTO\n", + "\"PEtab\n", "\n", "PyPESTO supports the [PEtab](https://github.com/PEtab-dev/PEtab) standard. PEtab is a data format for specifying parameter estimation problems in systems biology. \n", "\n", @@ -231,7 +232,7 @@ "source": [ "%%capture\n", "# directory of the PEtab problem\n", - "petab_yaml = \"./boehm_JProteomeRes2014/boehm_JProteomeRes2014.yaml\"\n", + "petab_yaml = \"./conversion_reaction/conversion_reaction.yaml\"\n", "\n", "importer = pypesto.petab.PetabImporter.from_yaml(petab_yaml)\n", "problem = importer.create_problem(verbose=False)" @@ -329,7 +330,7 @@ " * Gradient-free\n", "* [FIDES](https://github.com/fides-dev/fides/) (`optimize.FidesOptimizer()`)\n", " * Interior Trust Region optimizer \n", - "* [Particle Swarm](https://github.com/tisimst/pyswarm) (`optimize.PyswarmOptimizer()`)\n", + "* [Particle Swarm](https://github.com/ljvmiranda921/pyswarms) (`optimize.PyswarmsOptimizer()`)\n", " * Particle swarm algorithm\n", " * Gradient-free\n", "* [CMA-ES](https://pypi.org/project/cma-es/) (`optimize.CmaOptimizer()`)\n", @@ -351,7 +352,7 @@ "optimizer_scipy_powell = optimize.ScipyOptimizer(method=\"Powell\")\n", "\n", "optimizer_fides = optimize.FidesOptimizer(verbose=logging.ERROR)\n", - "optimizer_pyswarm = optimize.PyswarmOptimizer()" + "optimizer_pyswarm = optimize.PyswarmsOptimizer(par_popsize=10)" ] }, { @@ -384,14 +385,12 @@ "# Due to run time we already use parallelization.\n", "# This will be introduced in more detail later.\n", "engine = pypesto.engine.MultiProcessEngine()\n", - "history_options = pypesto.HistoryOptions(trace_record=True)\n", "\n", "# Scipy: L-BFGS-B\n", "result_lbfgsb = optimize.minimize(\n", " problem=problem,\n", " optimizer=optimizer_scipy_lbfgsb,\n", " engine=engine,\n", - " history_options=history_options,\n", " n_starts=n_starts,\n", ")\n", "\n", @@ -400,7 +399,6 @@ " problem=problem,\n", " optimizer=optimizer_scipy_powell,\n", " engine=engine,\n", - " history_options=history_options,\n", " n_starts=n_starts,\n", ")\n", "\n", @@ -409,7 +407,6 @@ " problem=problem,\n", " optimizer=optimizer_fides,\n", " engine=engine,\n", - " history_options=history_options,\n", " n_starts=n_starts,\n", ")\n", "\n", @@ -419,8 +416,7 @@ " problem=problem,\n", " optimizer=optimizer_pyswarm,\n", " engine=engine,\n", - " history_options=history_options,\n", - " n_starts=n_starts,\n", + " n_starts=1, # Global optimizers are usually run once. The number of particles (par_popsize) is usually the parameter that is adapted.\n", ")" ] }, @@ -435,9 +431,7 @@ "### Optimizer Convergence\n", "\n", "\n", - "A common visualization of optimizer convergence are waterfall plots. Waterfall plots show the (ordered) results of the individual optimization runs. As we see below, Dlib and pyswarm, which are not gradient-based, are not able to find the global optimum. \n", - "\n", - "Furthermore, we hope to obtain clearly visible plateaus, as they indicate optimizer convergence to local minima. " + "A common visualization of optimizer convergence are waterfall plots. Waterfall plots show the (ordered) results of the individual optimization runs. In general, we hope to obtain clearly visible plateaus, as they indicate optimizer convergence to local minima. " ] }, { @@ -453,10 +447,9 @@ "optimizer_results = [\n", " result_lbfgsb,\n", " result_powell,\n", - " result_fides,\n", - " result_pyswarm,\n", + " result_fides\n", "]\n", - "optimizer_names = [\"Scipy: L-BFGS-B\", \"Scipy: Powell\", \"Fides\", \"pyswarm\"]\n", + "optimizer_names = [\"Scipy: L-BFGS-B\", \"Scipy: Powell\", \"Fides\"]\n", "\n", "pypesto.visualize.waterfall(optimizer_results, legends=optimizer_names);" ] @@ -612,7 +605,7 @@ " problem=problem,\n", " result=result,\n", " optimizer=optimizer_scipy_lbfgsb,\n", - " profile_index=[0, 1, 2],\n", + " profile_index=[0, 1],\n", ")" ] }, @@ -910,6 +903,9 @@ "cell_type": "markdown", "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%% md\n" } @@ -941,7 +937,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.2" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/history_usage.ipynb b/doc/example/history_usage.ipynb index ae882fd77..21d661af3 100644 --- a/doc/example/history_usage.ipynb +++ b/doc/example/history_usage.ipynb @@ -376,12 +376,15 @@ }, { "cell_type": "markdown", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ "We compare the function value trace of the loaded results with the original results to ensure consistency." - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", @@ -471,7 +474,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.2" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/model_evidence_and_bayes_factors.ipynb b/doc/example/model_evidence_and_bayes_factors.ipynb index e7d0b2af7..0cc7d188a 100644 --- a/doc/example/model_evidence_and_bayes_factors.ipynb +++ b/doc/example/model_evidence_and_bayes_factors.ipynb @@ -13,8 +13,9 @@ ] }, { - "metadata": {}, "cell_type": "markdown", + "id": "5c56f766bcf7ab48", + "metadata": {}, "source": [ "\n", "## Marginal Likelihood\n", @@ -26,12 +27,12 @@ "$$\n", "\n", "where $\\theta$ are the parameters of the model. This integral averages the likelihood over the prior distribution of the parameters, providing a measure of how well the model explains the data, considering all possible parameter values." - ], - "id": "5c56f766bcf7ab48" + ] }, { - "metadata": {}, "cell_type": "markdown", + "id": "6337b6a3", + "metadata": {}, "source": [ "## Bayes Factor\n", "\n", @@ -49,12 +50,12 @@ "- Substantial: $0.5 < \\log_{10}\\operatorname{BF}_{12} \\leq 1$\n", "- Strong: $1 < \\log_{10}\\operatorname{BF}_{12} \\leq 2$\n", "- Decisive: $2 < \\log_{10}\\operatorname{BF}_{12}$" - ], - "id": "6337b6a3" + ] }, { - "metadata": {}, "cell_type": "markdown", + "id": "a6b7640cff0280de", + "metadata": {}, "source": [ "## Example\n", "\n", @@ -68,13 +69,14 @@ "The free parameters are the means of both models. \n", "For this example, we assume that the standard deviation is known and fixed to the true value.\n", "As priors, we assume normal distributions." - ], - "id": "a6b7640cff0280de" + ] }, { "cell_type": "code", + "execution_count": null, "id": "6eb930b7", "metadata": {}, + "outputs": [], "source": [ "from functools import partial\n", "from typing import Union\n", @@ -90,14 +92,18 @@ " NegLogParameterPriors,\n", " Objective,\n", ")\n", - "from pypesto.problem import Problem" - ], - "outputs": [], - "execution_count": null + "from pypesto.problem import Problem\n", + "\n", + "# For testing purposes. Remove if not running the exact example.\n", + "np.random.seed(42)" + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "ad47e3f67a7896d3", + "metadata": {}, + "outputs": [], "source": [ "# model hyperparameters\n", "N = 10\n", @@ -131,18 +137,18 @@ "plt.scatter(Y2_2, np.full(len(Y2_2), 0.1), label='Y2_2 samples', color='green')\n", "plt.legend()\n", "plt.show()" - ], - "id": "ad47e3f67a7896d3", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, + "id": "2143410833d86594", "metadata": { "tags": [ "hide-input" ] }, - "cell_type": "code", + "outputs": [], "source": [ "# evidence\n", "def log_evidence_alt(data: np.ndarray, std: float):\n", @@ -186,18 +192,18 @@ "\n", "print(\"True log evidence, true model:\", true_log_evidence_true)\n", "print(\"True log evidence, alternative model:\", true_log_evidence_alt)" - ], - "id": "2143410833d86594", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, + "id": "33659ff5eba21345", "metadata": { "tags": [ "hide-input" ] }, - "cell_type": "code", + "outputs": [], "source": [ "# define likelihood for each model, and build the objective functions for the pyPESTO problem\n", "def neg_log_likelihood(params: Union[np.ndarray, list], data: np.ndarray):\n", @@ -362,13 +368,19 @@ " x_fixed_vals=[sigma],\n", " x_priors_defs=prior_alt,\n", ")" - ], - "id": "33659ff5eba21345", - "outputs": [], - "execution_count": null + ] }, { "cell_type": "code", + "execution_count": null, + "id": "cf9af2fa37f3a0cf", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [], "source": [ "# to make the code more readable, we define a dictionary with all models\n", "# from here on, we use the pyPESTO problem objects, so the code can be reused for any other problem\n", @@ -397,24 +409,24 @@ " m['neg_log_likelihood'] = lambda x: m['problem'].objective._objectives[0](\n", " m['problem'].get_full_vector(x=x, x_fixed_vals=m['problem'].x_fixed_vals)\n", " ) " - ], - "metadata": { - "collapsed": false - }, - "id": "cf9af2fa37f3a0cf", - "outputs": [], - "execution_count": null + ] }, { - "metadata": {}, "cell_type": "markdown", - "source": "## Methods for Computing Marginal Likelihoods", - "id": "e273503367e8bf4d" + "id": "e273503367e8bf4d", + "metadata": {}, + "source": [ + "## Methods for Computing Marginal Likelihoods" + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "95ec6b53c9133332", + "metadata": {}, + "outputs": [], "source": [ + "%%time\n", "# run optimization for each model\n", "for m in models.values(): \n", " m['results'] = optimize.minimize(problem=m['problem'], n_starts=100)\n", @@ -424,14 +436,12 @@ " results=m['results'], reference={'x': m[\"true_params\"], 'fval': m['problem'].objective(m[\"true_params\"])})\n", " else:\n", " visualize.parameters(m['results'])" - ], - "id": "95ec6b53c9133332", - "outputs": [], - "execution_count": null + ] }, { - "metadata": {}, "cell_type": "markdown", + "id": "ffd895262133fe00", + "metadata": {}, "source": [ "### 1. Bayesian Information Criterion (BIC)\n", "\n", @@ -445,24 +455,24 @@ "\n", "\n", "BIC is easy to compute and converges to the marginal likelihood, but it may not capture the full complexity of model selection, especially for complex models or significant prior information as the prior is completely ignored." - ], - "id": "ffd895262133fe00" + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "1b40d72091d00e9f", + "metadata": {}, + "outputs": [], "source": [ "for m in models.values(): \n", " m['BIC'] = len(m['problem'].x_free_indices) * np.log(n_obs) + 2 * m['neg_log_likelihood'](m['results'].optimize_result.x[0])\n", " print(m['name'], 'BIC marginal likelihood approximation:', -1/2*m['BIC'])" - ], - "id": "1b40d72091d00e9f", - "outputs": [], - "execution_count": null + ] }, { - "metadata": {}, "cell_type": "markdown", + "id": "67cb4a7bb781d42", + "metadata": {}, "source": [ "### 2. Laplace Approximation\n", "\n", @@ -476,12 +486,14 @@ "\n", "\n", "The Laplace approximation is accurate if the posterior is unimodal and roughly Gaussian." - ], - "id": "67cb4a7bb781d42" + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "548513d76b8887dd", + "metadata": {}, + "outputs": [], "source": [ "%%time\n", "for m in models.values(): \n", @@ -492,26 +504,27 @@ " \n", " m['laplace_evidences'] = np.array(laplace_evidences)\n", " print(m['name'], f'laplace approximation: {m[\"laplace_evidences\"][0]}')" - ], - "id": "548513d76b8887dd", - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "id": "b5ac29500e0e678b", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ "### 3. Sampling-Based Methods\n", "\n", "Sampling-based methods, such as Markov Chain Monte Carlo (MCMC) or nested sampling, do not make assumptions about the shape of the posterior and can provide more accurate estimates of the marginal likelihood. However, they can be computationally very intensive." - ], - "metadata": { - "collapsed": false - }, - "id": "b5ac29500e0e678b" + ] }, { - "metadata": {}, "cell_type": "markdown", + "id": "212297d07ef90600", + "metadata": {}, "source": [ "\n", "#### Arithmetic Mean Estimator\n", @@ -523,11 +536,19 @@ "$$\n", "\n", "The arithmetic mean estimator requires a large number of samples and is very inefficient. It approximates the marginal likelihood from below." - ], - "id": "212297d07ef90600" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "ec2f000c836abad6", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [], "source": [ "%%time\n", "for m in models.values(): \n", @@ -538,16 +559,17 @@ " m['arithmetic_log_evidence'] = logsumexp(log_likelihoods) - np.log(log_likelihoods.size)\n", " \n", " print(m['name'], f'arithmetic mean: {m[\"arithmetic_log_evidence\"]}')" - ], - "metadata": { - "collapsed": false - }, - "id": "ec2f000c836abad6", - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "id": "77ec3e1ec016d0d1", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ "#### Harmonic Mean\n", "\n", @@ -566,15 +588,14 @@ "A reliable sampling method is bridge sampling (see [\"A Tutorial on Bridge Sampling\" by Gronau et al. (2017)](https://api.semanticscholar.org/CorpusID:5447695) for a nice introduction). It uses samples from a proposal and the posterior to estimate the marginal likelihood. The proposal distribution should be chosen to have a high overlap with the posterior (we construct it from half of the posterior samples by fitting a Gaussian distribution with the same mean and covariance). This method is more stable than the harmonic mean estimator. However, its accuracy may depend on the choice of the proposal distribution.\n", "\n", "A different approach, the learnt harmonic mean estimator, was proposed by [McEwen et al. (2021)](https://api.semanticscholar.org/CorpusID:244709474). The estimator solves the large variance problem by interpreting the harmonic mean estimator as importance sampling and introducing a new target distribution, which is learned from the posterior samples. The method can be applied just using samples from the posterior and is implemented in the software package accompanying the paper.\n" - ], - "metadata": { - "collapsed": false - }, - "id": "77ec3e1ec016d0d1" + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "ba4cc742f71fad4", + "metadata": {}, + "outputs": [], "source": [ "%%time\n", "for m in models.values(): \n", @@ -586,14 +607,14 @@ " # compute harmonic mean\n", " m['harmonic_log_evidence'] = sample.evidence.harmonic_mean_log_evidence(results)\n", " print(m['name'], f'harmonic mean: {m[\"harmonic_log_evidence\"]}') " - ], - "id": "ba4cc742f71fad4", - "outputs": [], - "execution_count": null + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "a7272997b60de2e2", + "metadata": {}, + "outputs": [], "source": [ "%%time\n", "for m in models.values(): \n", @@ -612,14 +633,14 @@ " neg_log_likelihood_fun=m['neg_log_likelihood']\n", " )\n", " print(m['name'], f'stabilized harmonic mean: {m[\"harmonic_stabilized_log_evidence\"]}')" - ], - "id": "a7272997b60de2e2", - "outputs": [], - "execution_count": null + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "ce38f1a4975cd72a", + "metadata": {}, + "outputs": [], "source": [ "%%time\n", "for m in models.values(): \n", @@ -630,27 +651,36 @@ " )\n", " m['bridge_log_evidence'] = sample.evidence.bridge_sampling_log_evidence(results)\n", " print(m['name'], f'bridge sampling: {m[\"bridge_log_evidence\"]}')" - ], - "id": "ce38f1a4975cd72a", - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "id": "443bf17c8ae27a15", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ "#### Nested Sampling\n", "\n", "Nested sampling is specifically designed for estimating marginal likelihoods. The static nested sampler is optimized for evidence computation and provides accurate estimates but may give less accurate posterior samples unless dynamic nested sampling is used. \n", "\n", "Dynamic nested sampling can improve the accuracy of posterior samples. The package [dynesty](https://dynesty.readthedocs.io/en/stable/) offers a lot of hyperparameters to tune accuracy and efficiency of computing samples from the posterior vs. estimating the marginal likelihood." - ], - "metadata": { - "collapsed": false - }, - "id": "443bf17c8ae27a15" + ] }, { "cell_type": "code", + "execution_count": null, + "id": "c0236f455dfc64d5", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [], "source": [ "%%time\n", "for m in models.values():\n", @@ -681,16 +711,17 @@ " # extract log evidence\n", " m[f'nested_log_evidence'] = nested_sampler.sampler.results.logz[-1]\n", " print(m['name'], f'nested sampling: {m[\"nested_log_evidence\"]}')" - ], - "metadata": { - "collapsed": false - }, - "id": "c0236f455dfc64d5", - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "id": "dcb16e2efcf4bf0d", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ "#### Thermodynamic Integration and Steppingstone Sampling\n", "\n", @@ -704,15 +735,14 @@ "\n", "These methods can be more accurate for complex posteriors but are computationally intensive. Thermodynamic integration (TI) relies on integrating the integral over the temperature $t$, while steppingstone sampling approximates the integral with a sum over a finite number of temperatures using an importance sampling estimator. Accuracy can be improved by using more temperatures. \n", "Errors in the estimator might come from the MCMC sampler in both cases and from numerical integration when applying TI. Steppingstone sampling can be a biased estimator for a small number of temperatures [(Annis et al., 2019)](https://doi.org/10.1016/j.jmp.2019.01.005).\n" - ], - "metadata": { - "collapsed": false - }, - "id": "dcb16e2efcf4bf0d" + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "13059e00c982d98d", + "metadata": {}, + "outputs": [], "source": [ "%%time\n", "for m in models.values():\n", @@ -730,34 +760,37 @@ " result=m['results']\n", " ) \n", " # compute log evidence via thermodynamic integration\n", - " m['thermodynamic_log_evidence'] = sample.evidence.parallel_tempering_log_evidence(result_ti)\n", + " m['thermodynamic_log_evidence'] = sample.evidence.parallel_tempering_log_evidence(result_ti, use_all_chains=False)\n", " print(m['name'], f'thermodynamic integration: {m[\"thermodynamic_log_evidence\"]}')\n", " \n", " # compute log evidence via steppingstone sampling\n", - " m['steppingstone_log_evidence'] = sample.evidence.parallel_tempering_log_evidence(result_ti, method='steppingstone')\n", + " m['steppingstone_log_evidence'] = sample.evidence.parallel_tempering_log_evidence(result_ti, method='steppingstone', use_all_chains=False)\n", " print(m['name'], f'steppingstone sampling: {m[\"steppingstone_log_evidence\"]}')" - ], - "id": "13059e00c982d98d", - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "id": "90fd0f80a9d94b7d", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "source": [ "#### Variational Inference\n", "\n", "Variational inference approximates the posterior with a simpler distribution and can be faster than sampling methods for large problems. The marginal likelihood can be estimated using similar approaches as before, but the accuracy is limited by the choice of the variational family.\n", "\n", "Variational inference optimization is based on the Evidence Lower Bound (ELBO), providing an additional check for the estimator." - ], - "metadata": { - "collapsed": false - }, - "id": "90fd0f80a9d94b7d" + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "c616b8a566478d0d", + "metadata": {}, + "outputs": [], "source": [ "%%time\n", "for m in models.values():\n", @@ -794,20 +827,22 @@ " \n", " # evidence cannot be smaller than the lower bound\n", " m[\"vi_harmonic_log_evidences\"] = max(m[\"vi_harmonic_log_evidences\"], vi_lower_bound)" - ], - "id": "c616b8a566478d0d", - "outputs": [], - "execution_count": null + ] }, { - "metadata": {}, "cell_type": "markdown", - "source": "## Comparison", - "id": "5e6c53b1a6414210" + "id": "5e6c53b1a6414210", + "metadata": {}, + "source": [ + "## Comparison" + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "fbb5a071645523d4", + "metadata": {}, + "outputs": [], "source": [ "labels = [\n", " '-1/2 BIC',\n", @@ -836,14 +871,14 @@ "]\n", "\n", "true_bf = models['mixture_model1']['true_log_evidence'] - models['mixture_model2']['true_log_evidence']" - ], - "id": "fbb5a071645523d4", - "outputs": [], - "execution_count": null + ] }, { - "metadata": {}, "cell_type": "code", + "execution_count": null, + "id": "30fea0ed78548d6b", + "metadata": {}, + "outputs": [], "source": [ "fig, ax = plt.subplots(2, 1, tight_layout=True, sharex=True, figsize=(6, 6))\n", "colors = ['blue', 'orange']\n", @@ -876,13 +911,19 @@ "ax[1].set_xticks(ticks=np.arange(len(labels)), labels=labels, rotation=60)\n", "fig.legend(ncols=1, loc='center right', bbox_to_anchor=(1.5, 0.7))\n", "plt.show()" - ], - "id": "30fea0ed78548d6b", - "outputs": [], - "execution_count": null + ] }, { "cell_type": "code", + "execution_count": null, + "id": "5d6590690b5c7a30", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [], "source": [ "fig, ax = plt.subplots(1, 1, tight_layout=True, figsize=(6, 5))\n", "ax.axhline(true_bf, linestyle='-', color='r', label='True Bayes Factor')\n", @@ -901,23 +942,17 @@ "plt.xticks(ticks=np.arange(len(bayes_factors)), labels=labels, rotation=60)\n", "fig.legend(ncols=1, loc='center right', bbox_to_anchor=(1.5, 0.7))\n", "plt.show()" - ], - "metadata": { - "collapsed": false - }, - "id": "5d6590690b5c7a30", - "outputs": [], - "execution_count": null + ] }, { - "metadata": {}, "cell_type": "markdown", + "id": "6cbfd915823d6989", + "metadata": {}, "source": [ "We recommend using either bridge sampling, nested sampling or one of the methods using power posteriors depending on the computational resources available. \n", "\n", "Bayes factors and marginal likelihoods are powerful tools for Bayesian model comparison. While there are various methods to compute marginal likelihoods, each has its strengths and weaknesses. Choosing the appropriate method depends on the specific context, the complexity of the models, and the computational resources available." - ], - "id": "6cbfd915823d6989" + ] } ], "metadata": { @@ -936,7 +971,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/model_selection.ipynb b/doc/example/model_selection.ipynb index 72ae22a8d..f31338dc7 100644 --- a/doc/example/model_selection.ipynb +++ b/doc/example/model_selection.ipynb @@ -158,9 +158,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "import logging\n", @@ -188,9 +186,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "# Reduce notebook runtime\n", @@ -263,9 +259,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "pvs.plot_calibrated_models_digraph(\n", @@ -485,9 +479,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "petab_select_problem.model_space.reset_exclusions()\n", @@ -555,7 +547,7 @@ "metadata": { "celltoolbar": "Raw Cell Format", "kernelspec": { - "display_name": "Python 3.10.2 64-bit", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -569,7 +561,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.2" + "version": "3.12.3" }, "vscode": { "interpreter": { @@ -578,5 +570,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/doc/example/ordinal_data.ipynb b/doc/example/ordinal_data.ipynb index 2b1528f61..17dbbaa2a 100644 --- a/doc/example/ordinal_data.ipynb +++ b/doc/example/ordinal_data.ipynb @@ -917,7 +917,7 @@ ], "metadata": { "kernelspec": { - "display_name": "dev_venv", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -931,7 +931,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.10" + "version": "3.12.3" }, "vscode": { "interpreter": { @@ -940,5 +940,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/doc/example/petab_import.ipynb b/doc/example/petab_import.ipynb index 69040e595..e516fa008 100644 --- a/doc/example/petab_import.ipynb +++ b/doc/example/petab_import.ipynb @@ -327,7 +327,10 @@ { "cell_type": "markdown", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ "### Dealing with function evaluations at the initial point\n", @@ -339,7 +342,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -438,7 +444,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.10" + "version": "3.12.3" }, "toc": { "base_numbering": 1, diff --git a/doc/example/prior_definition.ipynb b/doc/example/prior_definition.ipynb index 9ab018a14..60edde7f2 100644 --- a/doc/example/prior_definition.ipynb +++ b/doc/example/prior_definition.ipynb @@ -206,7 +206,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.10.2 64-bit", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -220,7 +220,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.2" + "version": "3.12.3" }, "vscode": { "interpreter": { diff --git a/doc/example/relative_data.ipynb b/doc/example/relative_data.ipynb index 62ba09c05..677b7ff75 100644 --- a/doc/example/relative_data.ipynb +++ b/doc/example/relative_data.ipynb @@ -467,7 +467,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.2" + "version": "3.12.3" }, "toc": { "base_numbering": 1, diff --git a/doc/example/roadrunner.ipynb b/doc/example/roadrunner.ipynb index 10566c2ac..a553feceb 100644 --- a/doc/example/roadrunner.ipynb +++ b/doc/example/roadrunner.ipynb @@ -62,10 +62,7 @@ "\n", "\n", "# name of the model that will also be the name of the python module\n", - "model_name = \"boehm_JProteomeRes2014\"\n", - "\n", - "# output directory\n", - "model_output_dir = \"tmp/\" + model_name" + "model_name = \"conversion_reaction\"" ] }, { @@ -223,6 +220,7 @@ }, "outputs": [], "source": [ + "%%time\n", "result = optimize.minimize(\n", " problem=problem,\n", " optimizer=optimizer,\n", @@ -380,7 +378,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.2" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/sampler_study.ipynb b/doc/example/sampler_study.ipynb index b466b028d..f5e0ccf95 100644 --- a/doc/example/sampler_study.ipynb +++ b/doc/example/sampler_study.ipynb @@ -301,7 +301,7 @@ "source": [ "sampler = sample.MetropolisSampler({\"std\": 0.5})\n", "result = sample.sample(\n", - " problem, 1e4, sampler, x0=np.array([0.5]), filename=None\n", + " problem, 1e3, sampler, x0=np.array([0.5]), filename=None\n", ")" ] }, @@ -331,7 +331,7 @@ "source": [ "sampler = sample.MetropolisSampler({\"std\": 1})\n", "result = sample.sample(\n", - " problem, 1e4, sampler, x0=np.array([0.5]), filename=None\n", + " problem, 1e3, sampler, x0=np.array([0.5]), filename=None\n", ")" ] }, @@ -620,8 +620,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The internal `dynesty` sampler can be saved and restored, for post-sampling analysis. For example, pyPESTO stores resampled MCMC-like samples from the `dynesty` sampler by default. The following code shows how to save and load the internal dynesty sampler, to facilitate post-sampling analysis of both the resampled and original chains. N.B.: when working across different computers, you might prefer to work with the raw sample results via `pypesto.sample.dynesty.save_raw_results` and `load_raw_results`.", - "\n", + "The internal `dynesty` sampler can be saved and restored, for post-sampling analysis. For example, pyPESTO stores resampled MCMC-like samples from the `dynesty` sampler by default. The following code shows how to save and load the internal dynesty sampler, to facilitate post-sampling analysis of both the resampled and original chains. N.B.: when working across different computers, you might prefer to work with the raw sample results via `pypesto.sample.dynesty.save_raw_results` and `load_raw_results`.\n", "First, we save the internal sampler." ] }, @@ -772,7 +771,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.10" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/sampling_diagnostics.ipynb b/doc/example/sampling_diagnostics.ipynb index 21827fa74..70db98959 100644 --- a/doc/example/sampling_diagnostics.ipynb +++ b/doc/example/sampling_diagnostics.ipynb @@ -680,7 +680,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.2" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/semiquantitative_data.ipynb b/doc/example/semiquantitative_data.ipynb index 721de8f20..bd277ca3f 100644 --- a/doc/example/semiquantitative_data.ipynb +++ b/doc/example/semiquantitative_data.ipynb @@ -457,7 +457,7 @@ ], "metadata": { "kernelspec": { - "display_name": "dev_venv", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -471,7 +471,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.2" + "version": "3.12.3" }, "vscode": { "interpreter": { @@ -480,5 +480,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/doc/example/store.ipynb b/doc/example/store.ipynb index 58f9902af..18df12962 100644 --- a/doc/example/store.ipynb +++ b/doc/example/store.ipynb @@ -25,6 +25,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -51,6 +54,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -99,6 +105,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -108,7 +117,7 @@ "source": [ "%%capture\n", "# directory of the PEtab problem\n", - "petab_yaml = \"./boehm_JProteomeRes2014/boehm_JProteomeRes2014.yaml\"\n", + "petab_yaml = \"./conversion_reaction/conversion_reaction.yaml\"\n", "\n", "importer = pypesto.petab.PetabImporter.from_yaml(petab_yaml)\n", "problem = importer.create_problem(verbose=False)" @@ -144,6 +153,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -159,7 +171,7 @@ ")\n", "\n", "# set number of starts\n", - "n_starts = 15 # usually a larger number >=100 is used\n", + "n_starts = 10 # usually a larger number >=100 is used\n", "\n", "# Optimization\n", "result = pypesto.optimize.minimize(\n", @@ -172,6 +184,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -198,6 +213,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -212,7 +230,7 @@ " problem=problem,\n", " result=result,\n", " optimizer=optimizer,\n", - " profile_index=np.array([1, 1, 1, 0, 0, 0, 0, 0, 1]),\n", + " profile_index=np.array([0, 1]),\n", ")" ] }, @@ -232,6 +250,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -246,7 +267,7 @@ "result = sample.sample(\n", " problem=problem,\n", " sampler=sampler,\n", - " n_samples=5000, # rather low\n", + " n_samples=1000, # rather low\n", " result=result,\n", " filename=None,\n", ")" @@ -270,6 +291,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -308,6 +332,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -337,6 +364,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -354,6 +384,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -406,6 +439,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -423,6 +459,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -451,6 +490,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -467,6 +509,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -494,6 +539,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -510,6 +558,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -581,6 +632,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -588,6 +642,7 @@ }, "outputs": [], "source": [ + "%%time\n", "# record the history\n", "history_options = pypesto.HistoryOptions(trace_record=True)\n", "\n", @@ -617,6 +672,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -660,12 +718,16 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ + "%%time\n", "# create temporary file\n", "with tempfile.NamedTemporaryFile(suffix=\"_{id}.csv\") as fn_csv:\n", " # record the history and store to CSV\n", @@ -699,6 +761,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -747,12 +812,16 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ + "%%time\n", "# create temporary file\n", "f_hdf5 = tempfile.NamedTemporaryFile(suffix=\".hdf5\", delete=False)\n", "fn_hdf5 = f_hdf5.name\n", @@ -777,6 +846,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" } @@ -808,6 +880,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "pycharm": { "name": "#%%\n" }, @@ -827,14 +902,17 @@ { "cell_type": "code", "execution_count": null, + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "outputs": [], "source": [ "# close the temporary file\n", "f_hdf5.close()" - ], - "metadata": { - "collapsed": false - } + ] } ], "metadata": { @@ -853,7 +931,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.10" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/doc/example/synthetic_data.ipynb b/doc/example/synthetic_data.ipynb index 75041530c..e5a37cf4c 100644 --- a/doc/example/synthetic_data.ipynb +++ b/doc/example/synthetic_data.ipynb @@ -150,7 +150,7 @@ "outputs": [], "source": [ "pypesto_result_original = pypesto.optimize.minimize(\n", - " pypesto_problem_original, n_starts=20\n", + " pypesto_problem_original, n_starts=10 # For demonstration purposes only n=10 starts are used. Usually n >= 100\n", ")" ] }, @@ -270,7 +270,7 @@ ")\n", "pypesto_problem_synthetic = pypesto_importer_synthetic.create_problem()\n", "pypesto_result_synthetic = pypesto.optimize.minimize(\n", - " pypesto_problem_synthetic, n_starts=20\n", + " pypesto_problem_synthetic, n_starts=10\n", ")" ] }, @@ -324,7 +324,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.10" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/tox.ini b/tox.ini index 801f8ed08..59d940c9b 100644 --- a/tox.ini +++ b/tox.ini @@ -129,7 +129,7 @@ description = [testenv:notebooks1] allowlist_externals = bash -extras = example,amici,petab,pyswarm,pymc3,cma,nlopt,fides,roadrunner +extras = example,amici,petab,pyswarms,pymc3,cma,nlopt,fides,roadrunner commands = bash test/run_notebook.sh 1 description =