|
18 | 18 | }, |
19 | 19 | { |
20 | 20 | "cell_type": "code", |
21 | | - "execution_count": null, |
| 21 | + "execution_count": 1, |
22 | 22 | "metadata": { |
23 | 23 | "nbsphinx": "hidden" |
24 | 24 | }, |
|
33 | 33 | }, |
34 | 34 | { |
35 | 35 | "cell_type": "code", |
36 | | - "execution_count": null, |
| 36 | + "execution_count": 2, |
37 | 37 | "metadata": {}, |
38 | | - "outputs": [], |
| 38 | + "outputs": [ |
| 39 | + { |
| 40 | + "name": "stdout", |
| 41 | + "output_type": "stream", |
| 42 | + "text": [ |
| 43 | + "functions {\n", |
| 44 | + " real make_odds(real theta);\n", |
| 45 | + "}\n", |
| 46 | + "data {\n", |
| 47 | + " int<lower=0> N;\n", |
| 48 | + " array[N] int<lower=0, upper=1> y;\n", |
| 49 | + "}\n", |
| 50 | + "parameters {\n", |
| 51 | + " real<lower=0, upper=1> theta;\n", |
| 52 | + "}\n", |
| 53 | + "model {\n", |
| 54 | + " theta ~ beta(1, 1); // uniform prior on interval 0, 1\n", |
| 55 | + " y ~ bernoulli(theta);\n", |
| 56 | + "}\n", |
| 57 | + "generated quantities {\n", |
| 58 | + " real odds;\n", |
| 59 | + " odds = make_odds(theta);\n", |
| 60 | + "} \n", |
| 61 | + "\n" |
| 62 | + ] |
| 63 | + } |
| 64 | + ], |
39 | 65 | "source": [ |
40 | 66 | "from cmdstanpy import CmdStanModel\n", |
41 | 67 | "model_external = CmdStanModel(stan_file='bernoulli_external.stan', compile=False)\n", |
|
51 | 77 | }, |
52 | 78 | { |
53 | 79 | "cell_type": "code", |
54 | | - "execution_count": null, |
| 80 | + "execution_count": 3, |
55 | 81 | "metadata": { |
56 | 82 | "tags": [ |
57 | 83 | "raises-exception" |
58 | 84 | ] |
59 | 85 | }, |
60 | | - "outputs": [], |
| 86 | + "outputs": [ |
| 87 | + { |
| 88 | + "name": "stderr", |
| 89 | + "output_type": "stream", |
| 90 | + "text": [ |
| 91 | + "14:52:06 - cmdstanpy - INFO - compiling stan file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan to exe file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external\n", |
| 92 | + "14:52:06 - cmdstanpy - ERROR - Stan program failed to compile:\n", |
| 93 | + "14:52:06 - cmdstanpy - WARNING - \n", |
| 94 | + "--- Translating Stan model to C++ code ---\n", |
| 95 | + "bin/stanc --o=/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.hpp /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan\n", |
| 96 | + "Semantic error in '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan', line 2, column 7 to column 16:\n", |
| 97 | + " -------------------------------------------------\n", |
| 98 | + " 1: functions {\n", |
| 99 | + " 2: real make_odds(real theta);\n", |
| 100 | + " ^\n", |
| 101 | + " 3: }\n", |
| 102 | + " 4: data {\n", |
| 103 | + " -------------------------------------------------\n", |
| 104 | + "\n", |
| 105 | + "Function is declared without specifying a definition.\n", |
| 106 | + "make: *** [make/program:50: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.hpp] Error 1\n", |
| 107 | + "\n", |
| 108 | + "Command ['make', '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external']\n", |
| 109 | + "\terror during processing No such file or directory\n", |
| 110 | + "\n" |
| 111 | + ] |
| 112 | + } |
| 113 | + ], |
61 | 114 | "source": [ |
62 | 115 | "model_external.compile()" |
63 | 116 | ] |
|
71 | 124 | }, |
72 | 125 | { |
73 | 126 | "cell_type": "code", |
74 | | - "execution_count": null, |
| 127 | + "execution_count": 4, |
75 | 128 | "metadata": { |
76 | 129 | "tags": [ |
77 | 130 | "raises-exception" |
78 | 131 | ] |
79 | 132 | }, |
80 | | - "outputs": [], |
| 133 | + "outputs": [ |
| 134 | + { |
| 135 | + "name": "stderr", |
| 136 | + "output_type": "stream", |
| 137 | + "text": [ |
| 138 | + "14:52:06 - cmdstanpy - INFO - compiling stan file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan to exe file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external\n", |
| 139 | + "14:52:07 - cmdstanpy - ERROR - Stan program failed to compile:\n", |
| 140 | + "14:52:07 - cmdstanpy - WARNING - \n", |
| 141 | + "--- Translating Stan model to C++ code ---\n", |
| 142 | + "bin/stanc --allow-undefined --o=/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.hpp /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan\n", |
| 143 | + "\n", |
| 144 | + "--- Compiling, linking C++ code ---\n", |
| 145 | + "g++ -march=native -mtune=native -std=c++1y -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.75.0 -I stan/lib/stan_math/lib/sundials_6.0.0/include -I stan/lib/stan_math/lib/sundials_6.0.0/src/sundials -DBOOST_DISABLE_ASSERTS -c -Wno-ignored-attributes -include /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/user_header.hpp -x c++ -o /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.o /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.hpp\n", |
| 146 | + "cc1plus: fatal error: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/user_header.hpp: No such file or directory\n", |
| 147 | + "compilation terminated.\n", |
| 148 | + "make: *** [make/program:58: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external] Error 1\n", |
| 149 | + "\n", |
| 150 | + "Command ['make', 'STANCFLAGS+=--allow-undefined', '/home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external']\n", |
| 151 | + "\terror during processing No such file or directory\n", |
| 152 | + "\n" |
| 153 | + ] |
| 154 | + } |
| 155 | + ], |
81 | 156 | "source": [ |
82 | 157 | "model_external.compile(stanc_options={'allow-undefined':True})" |
83 | 158 | ] |
|
95 | 170 | }, |
96 | 171 | { |
97 | 172 | "cell_type": "code", |
98 | | - "execution_count": null, |
| 173 | + "execution_count": 5, |
99 | 174 | "metadata": {}, |
100 | | - "outputs": [], |
| 175 | + "outputs": [ |
| 176 | + { |
| 177 | + "name": "stderr", |
| 178 | + "output_type": "stream", |
| 179 | + "text": [ |
| 180 | + "14:52:07 - cmdstanpy - INFO - compiling stan file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external.stan to exe file /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external\n", |
| 181 | + "14:52:25 - cmdstanpy - INFO - compiled model executable: /home/brian/Dev/py/cmdstanpy/docsrc/users-guide/examples/bernoulli_external\n" |
| 182 | + ] |
| 183 | + } |
| 184 | + ], |
101 | 185 | "source": [ |
102 | | - "model_external.compile(user_header='make_odds.hpp')" |
| 186 | + "model_external.compile(user_header='make_odds.hpp')\n", |
| 187 | + "assert model_external.exe_file is not None" |
103 | 188 | ] |
104 | 189 | }, |
105 | 190 | { |
|
111 | 196 | }, |
112 | 197 | { |
113 | 198 | "cell_type": "code", |
114 | | - "execution_count": null, |
| 199 | + "execution_count": 6, |
115 | 200 | "metadata": {}, |
116 | | - "outputs": [], |
| 201 | + "outputs": [ |
| 202 | + { |
| 203 | + "name": "stderr", |
| 204 | + "output_type": "stream", |
| 205 | + "text": [ |
| 206 | + "14:52:25 - cmdstanpy - INFO - CmdStan start processing\n", |
| 207 | + "chain 1 |\u001b[33m \u001b[0m| 00:00 Status\n", |
| 208 | + "\u001b[A\n", |
| 209 | + "\n", |
| 210 | + "chain 1 |\u001b[34m██████████\u001b[0m| 00:00 Sampling completed\n", |
| 211 | + "chain 2 |\u001b[34m██████████\u001b[0m| 00:00 Sampling completed\n", |
| 212 | + "chain 3 |\u001b[34m██████████\u001b[0m| 00:00 Sampling completed\n", |
| 213 | + "chain 4 |\u001b[34m██████████\u001b[0m| 00:00 Sampling completed" |
| 214 | + ] |
| 215 | + }, |
| 216 | + { |
| 217 | + "name": "stdout", |
| 218 | + "output_type": "stream", |
| 219 | + "text": [ |
| 220 | + " " |
| 221 | + ] |
| 222 | + }, |
| 223 | + { |
| 224 | + "name": "stderr", |
| 225 | + "output_type": "stream", |
| 226 | + "text": [ |
| 227 | + "\n", |
| 228 | + "14:52:25 - cmdstanpy - INFO - CmdStan done processing.\n" |
| 229 | + ] |
| 230 | + }, |
| 231 | + { |
| 232 | + "name": "stdout", |
| 233 | + "output_type": "stream", |
| 234 | + "text": [ |
| 235 | + "\n" |
| 236 | + ] |
| 237 | + }, |
| 238 | + { |
| 239 | + "data": { |
| 240 | + "text/plain": [ |
| 241 | + "array([0.20418 , 0.27078 , 0.614841 , ..., 0.124882 , 0.0797855,\n", |
| 242 | + " 0.165672 ])" |
| 243 | + ] |
| 244 | + }, |
| 245 | + "execution_count": 6, |
| 246 | + "metadata": {}, |
| 247 | + "output_type": "execute_result" |
| 248 | + } |
| 249 | + ], |
117 | 250 | "source": [ |
118 | 251 | "fit = model_external.sample(data={'N':10, 'y':[0,1,0,0,0,0,0,0,0,1]})\n", |
119 | 252 | "fit.stan_variable('odds')" |
|
0 commit comments