|
73 | 73 | "source": [ |
74 | 74 | "%%treeppl flip samples=10\n", |
75 | 75 | "\n", |
76 | | - "model function flip(): Bool {\n", |
| 76 | + "model function flip() => Bool {\n", |
77 | 77 | " assume p ~ Bernoulli(0.5);\n", |
78 | 78 | " return p;\n", |
79 | 79 | "}" |
|
102 | 102 | "res.samples" |
103 | 103 | ] |
104 | 104 | }, |
105 | | - { |
106 | | - "cell_type": "markdown", |
107 | | - "id": "dcd09ad5", |
108 | | - "metadata": {}, |
109 | | - "source": [ |
110 | | - "We can dynamically adjust the number of samples as follows:" |
111 | | - ] |
112 | | - }, |
113 | | - { |
114 | | - "cell_type": "code", |
115 | | - "execution_count": null, |
116 | | - "id": "b5810a7c", |
117 | | - "metadata": {}, |
118 | | - "outputs": [], |
119 | | - "source": [ |
120 | | - "flip.set_samples(1000)" |
121 | | - ] |
122 | | - }, |
123 | | - { |
124 | | - "cell_type": "code", |
125 | | - "execution_count": null, |
126 | | - "id": "d961ee99", |
127 | | - "metadata": {}, |
128 | | - "outputs": [], |
129 | | - "source": [ |
130 | | - "res = flip()\n", |
131 | | - "sns.countplot(y=res.samples)" |
132 | | - ] |
133 | | - }, |
134 | 105 | { |
135 | 106 | "cell_type": "markdown", |
136 | 107 | "id": "1e839e5b", |
|
156 | 127 | "source": [ |
157 | 128 | "%%treeppl coin samples=100000\n", |
158 | 129 | "\n", |
159 | | - "model function coin(outcomes: Bool[]): Real {\n", |
| 130 | + "model function coin(outcomes: Bool[]) => Real {\n", |
160 | 131 | " assume p ~ Uniform(0.0, 1.0);\n", |
161 | 132 | " for i in 1 to (length(outcomes)) {\n", |
162 | 133 | " observe outcomes[i] ~ Bernoulli(p);\n", |
|
200 | 171 | "source": [ |
201 | 172 | "%%treeppl generative_crbd samples=1\n", |
202 | 173 | "\n", |
203 | | - "model function generativeCrbd(time: Real, lambda: Real, mu: Real): Tree {\n", |
| 174 | + "model function generativeCrbd(time: Real, lambda: Real, mu: Real) => Tree {\n", |
204 | 175 | " assume waitingTime ~ Exponential(lambda + mu);\n", |
205 | 176 | " let eventTime = time - waitingTime;\n", |
206 | 177 | " if eventTime < 0.0 {\n", |
|
291 | 262 | " }\n", |
292 | 263 | "}\n", |
293 | 264 | "\n", |
294 | | - "model function crbd(tree: Tree): Real[] {\n", |
| 265 | + "model function crbd(tree: Tree) => Real[] {\n", |
295 | 266 | " assume lambda ~ Gamma(1.0, 1.0);\n", |
296 | 267 | " assume mu ~ Gamma(1.0, 0.5);\n", |
297 | 268 | " walk(tree.left, tree.age, lambda, mu);\n", |
|
0 commit comments