|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import pymc3" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": 2, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [ |
| 17 | + { |
| 18 | + "name": "stderr", |
| 19 | + "output_type": "stream", |
| 20 | + "text": [ |
| 21 | + "Auto-assigning NUTS sampler...\n", |
| 22 | + "Initializing NUTS using jitter+adapt_diag...\n", |
| 23 | + "Multiprocess sampling (4 chains in 4 jobs)\n", |
| 24 | + "NUTS: [n]\n" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "data": { |
| 29 | + "text/html": [ |
| 30 | + "\n", |
| 31 | + " <div>\n", |
| 32 | + " <style>\n", |
| 33 | + " /* Turns off some styling */\n", |
| 34 | + " progress {\n", |
| 35 | + " /* gets rid of default border in Firefox and Opera. */\n", |
| 36 | + " border: none;\n", |
| 37 | + " /* Needs to be in here for Safari polyfill so background images work as expected. */\n", |
| 38 | + " background-size: auto;\n", |
| 39 | + " }\n", |
| 40 | + " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n", |
| 41 | + " background: #F44336;\n", |
| 42 | + " }\n", |
| 43 | + " </style>\n", |
| 44 | + " <progress value='4000' class='' max='4000', style='width:300px; height:20px; vertical-align: middle;'></progress>\n", |
| 45 | + " 100.00% [4000/4000 00:00<00:00 Sampling 4 chains, 0 divergences]\n", |
| 46 | + " </div>\n", |
| 47 | + " " |
| 48 | + ], |
| 49 | + "text/plain": [ |
| 50 | + "<IPython.core.display.HTML object>" |
| 51 | + ] |
| 52 | + }, |
| 53 | + "metadata": {}, |
| 54 | + "output_type": "display_data" |
| 55 | + }, |
| 56 | + { |
| 57 | + "name": "stderr", |
| 58 | + "output_type": "stream", |
| 59 | + "text": [ |
| 60 | + "The acceptance probability does not match the target. It is 0.8816556891941705, but should be close to 0.8. Try to increase the number of tuning steps.\n" |
| 61 | + ] |
| 62 | + } |
| 63 | + ], |
| 64 | + "source": [ |
| 65 | + "with pymc3.Model() as pmodel:\n", |
| 66 | + " n = pymc3.Normal('n')\n", |
| 67 | + " trace = pymc3.sample()\n", |
| 68 | + "\n", |
| 69 | + "with pmodel:\n", |
| 70 | + " d = pymc3.Deterministic('d', n * 4)" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "code", |
| 75 | + "execution_count": 3, |
| 76 | + "metadata": {}, |
| 77 | + "outputs": [ |
| 78 | + { |
| 79 | + "name": "stdout", |
| 80 | + "output_type": "stream", |
| 81 | + "text": [ |
| 82 | + "CPU times: user 18.8 ms, sys: 3.42 ms, total: 22.2 ms\n", |
| 83 | + "Wall time: 23.8 ms\n" |
| 84 | + ] |
| 85 | + } |
| 86 | + ], |
| 87 | + "source": [ |
| 88 | + "%%time\n", |
| 89 | + "with pmodel:\n", |
| 90 | + " pp = pymc3.fast_sample_posterior_predictive(\n", |
| 91 | + " [trace[15]],\n", |
| 92 | + " var_names=['d']\n", |
| 93 | + " )" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": 4, |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [ |
| 101 | + { |
| 102 | + "ename": "AttributeError", |
| 103 | + "evalue": "'list' object has no attribute '_straces'", |
| 104 | + "output_type": "error", |
| 105 | + "traceback": [ |
| 106 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 107 | + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", |
| 108 | + "\u001b[0;32m<timed exec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n", |
| 109 | + "\u001b[0;32m~/src/pymc3/pymc3/sampling.py\u001b[0m in \u001b[0;36msample_posterior_predictive\u001b[0;34m(trace, samples, model, vars, var_names, size, keep_size, random_seed, progressbar)\u001b[0m\n\u001b[1;32m 1539\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1540\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0msamples\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1541\u001b[0;31m \u001b[0msamples\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtrace\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_straces\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1542\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1543\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0msamples\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mlen_trace\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mnchain\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
| 110 | + "\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute '_straces'" |
| 111 | + ] |
| 112 | + } |
| 113 | + ], |
| 114 | + "source": [ |
| 115 | + "%%time\n", |
| 116 | + "with pmodel:\n", |
| 117 | + " pp = pymc3.sample_posterior_predictive(\n", |
| 118 | + " [trace[15]],\n", |
| 119 | + " var_names=['d']\n", |
| 120 | + " )" |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "code", |
| 125 | + "execution_count": 5, |
| 126 | + "metadata": {}, |
| 127 | + "outputs": [ |
| 128 | + { |
| 129 | + "data": { |
| 130 | + "text/plain": [ |
| 131 | + "{'n': 0.691903087470128}" |
| 132 | + ] |
| 133 | + }, |
| 134 | + "execution_count": 5, |
| 135 | + "metadata": {}, |
| 136 | + "output_type": "execute_result" |
| 137 | + } |
| 138 | + ], |
| 139 | + "source": [ |
| 140 | + "trace[15]" |
| 141 | + ] |
| 142 | + }, |
| 143 | + { |
| 144 | + "cell_type": "code", |
| 145 | + "execution_count": 8, |
| 146 | + "metadata": {}, |
| 147 | + "outputs": [ |
| 148 | + { |
| 149 | + "data": { |
| 150 | + "text/plain": [ |
| 151 | + "True" |
| 152 | + ] |
| 153 | + }, |
| 154 | + "execution_count": 8, |
| 155 | + "metadata": {}, |
| 156 | + "output_type": "execute_result" |
| 157 | + } |
| 158 | + ], |
| 159 | + "source": [ |
| 160 | + "'MultiTrace' in dir(pymc3.backends.base)" |
| 161 | + ] |
| 162 | + }, |
| 163 | + { |
| 164 | + "cell_type": "code", |
| 165 | + "execution_count": null, |
| 166 | + "metadata": {}, |
| 167 | + "outputs": [], |
| 168 | + "source": [] |
| 169 | + } |
| 170 | + ], |
| 171 | + "metadata": { |
| 172 | + "kernelspec": { |
| 173 | + "display_name": "Python 3", |
| 174 | + "language": "python", |
| 175 | + "name": "python3" |
| 176 | + }, |
| 177 | + "language_info": { |
| 178 | + "codemirror_mode": { |
| 179 | + "name": "ipython", |
| 180 | + "version": 3 |
| 181 | + }, |
| 182 | + "file_extension": ".py", |
| 183 | + "mimetype": "text/x-python", |
| 184 | + "name": "python", |
| 185 | + "nbconvert_exporter": "python", |
| 186 | + "pygments_lexer": "ipython3", |
| 187 | + "version": "3.7.6" |
| 188 | + } |
| 189 | + }, |
| 190 | + "nbformat": 4, |
| 191 | + "nbformat_minor": 2 |
| 192 | +} |
0 commit comments