You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/A Bottom-Up Introduction to Gen.ipynb
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -2170,7 +2170,7 @@
2170
2170
"cell_type": "markdown",
2171
2171
"metadata": {},
2172
2172
"source": [
2173
-
"The ability to *trace* the values of random choices in a probabilistic program (i.e. record the value of each choice in a trace data structure) is one of the basic features of Gen's built-in modeling language. To write a function in this language we use the `@gen` macro provided by Gen. Note that the built-in modeling language is just one way of defining a [generative function](https://www.gen.dev/docs/stable/ref/distributions/).\n",
2173
+
"The ability to *trace* the values of random choices in a probabilistic program (i.e. record the value of each choice in a trace data structure) is one of the basic features of Gen's built-in modeling language. To write a function in this language we use the `@gen` macro provided by Gen. Note that the built-in modeling language is just one way of defining a [generative function](https://www.gen.dev/docs/stable/ref/modeling/distributions/#distributions).\n",
2174
2174
"\n",
2175
2175
"Below, we write a `@gen function` version of the function `f` defined above, this time using Gen's tracing instead of our own:"
2176
2176
]
@@ -2225,7 +2225,7 @@
2225
2225
"cell_type": "markdown",
2226
2226
"metadata": {},
2227
2227
"source": [
2228
-
"To run a `@gen` function and get a trace of the execution, we use the [`simulate`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.simulate) method:"
2228
+
"To run a `@gen` function and get a trace of the execution, we use the [`simulate`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.simulate) method:"
2229
2229
]
2230
2230
},
2231
2231
{
@@ -2715,7 +2715,7 @@
2715
2715
"cell_type": "markdown",
2716
2716
"metadata": {},
2717
2717
"source": [
2718
-
"We can also get the log probability that an individual trace would be generated by the function ($\\log p(t; x)$), using the [`get_score`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.get_score) method.\n",
2718
+
"We can also get the log probability that an individual trace would be generated by the function ($\\log p(t; x)$), using the [`get_score`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.get_score) method.\n",
2719
2719
"\n",
2720
2720
"Let's generate a trace below, get its log probability with `get_score`"
2721
2721
]
@@ -2778,7 +2778,7 @@
2778
2778
" gen_f(0.3)\n",
2779
2779
" ```\n",
2780
2780
"\n",
2781
-
"2. Using the [`simulate`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.simulate) method:\n",
2781
+
"2. Using the [`simulate`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.simulate) method:\n",
2782
2782
"\n",
2783
2783
" ```julia\n",
2784
2784
" trace = simulate(gen_f, (0.3,))\n",
@@ -2789,7 +2789,7 @@
2789
2789
"cell_type": "markdown",
2790
2790
"metadata": {},
2791
2791
"source": [
2792
-
"We can also generate a trace that satisfies a set of constraints on the valus of random choices using the [`generate`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.generate) method. Suppose that we want a trace where `:a` is always `true` and `:c` is always `false`. We first construct a choice map containing these constraints:"
2792
+
"We can also generate a trace that satisfies a set of constraints on the valus of random choices using the [`generate`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.generate) method. Suppose that we want a trace where `:a` is always `true` and `:c` is always `false`. We first construct a choice map containing these constraints:"
2793
2793
]
2794
2794
},
2795
2795
{
@@ -3013,7 +3013,7 @@
3013
3013
"cell_type": "markdown",
3014
3014
"metadata": {},
3015
3015
"source": [
3016
-
"A more efficient and numerically robust implementation of importance resampling is provided in Gen's inference library (see [`importance_resampling`](https://www.gen.dev/docs/stable/ref/inference/#Gen.importance_resampling))."
3016
+
"A more efficient and numerically robust implementation of importance resampling is provided in Gen's inference library (see [`importance_resampling`](https://www.gen.dev/docs/stable/ref/inference/importance/#Gen.importance_sampling)."
3017
3017
]
3018
3018
},
3019
3019
{
@@ -3433,7 +3433,7 @@
3433
3433
"cell_type": "markdown",
3434
3434
"metadata": {},
3435
3435
"source": [
3436
-
"Now, we use the [`update`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.update) method, to change the value of `:c` from `true` to `false`:"
3436
+
"Now, we use the [`update`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.update) method, to change the value of `:c` from `true` to `false`:"
# ## 2. Tracing the values of random choices in generative functions
190
190
191
-
# The ability to *trace* the values of random choices in a probabilistic program (i.e. record the value of each choice in a trace data structure) is one of the basic features of Gen's built-in modeling language. To write a function in this language we use the `@gen` macro provided by Gen. Note that the built-in modeling language is just one way of defining a [generative function](https://www.gen.dev/docs/stable/ref/distributions/).
191
+
# The ability to *trace* the values of random choices in a probabilistic program (i.e. record the value of each choice in a trace data structure) is one of the basic features of Gen's built-in modeling language. To write a function in this language we use the `@gen` macro provided by Gen. Note that the built-in modeling language is just one way of defining a [generative function](https://www.gen.dev/docs/stable/ref/modeling/distributions/#distributions).
192
192
#
193
193
# Below, we write a `@gen function` version of the function `f` defined above, this time using Gen's tracing instead of our own:
194
194
@@ -210,7 +210,7 @@ end;
210
210
211
211
gen_f(0.3)
212
212
213
-
# To run a `@gen` function and get a trace of the execution, we use the [`simulate`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.simulate) method:
213
+
# To run a `@gen` function and get a trace of the execution, we use the [`simulate`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.simulate) method:
# We can also get the log probability that an individual trace would be generated by the function ($\log p(t; x)$), using the [`get_score`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.get_score) method.
303
+
# We can also get the log probability that an individual trace would be generated by the function ($\log p(t; x)$), using the [`get_score`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.get_score) method.
304
304
#
305
305
# Let's generate a trace below, get its log probability with `get_score`
# 2. Using the [`simulate`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.simulate) method:
324
+
# 2. Using the [`simulate`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.simulate) method:
325
325
#
326
326
# ```julia
327
327
# trace = simulate(gen_f, (0.3,))
328
328
# ```
329
329
330
-
# We can also generate a trace that satisfies a set of constraints on the valus of random choices using the [`generate`](https://www.gen.dev/docs/stable/ref/gfi/#Gen.generate) method. Suppose that we want a trace where `:a` is always `true` and `:c` is always `false`. We first construct a choice map containing these constraints:
330
+
# We can also generate a trace that satisfies a set of constraints on the valus of random choices using the [`generate`](https://www.gen.dev/docs/stable/ref/core/gfi/#Gen.generate) method. Suppose that we want a trace where `:a` is always `true` and `:c` is always `false`. We first construct a choice map containing these constraints:
331
331
332
332
# +
333
333
using Gen: choicemap
@@ -414,7 +414,7 @@ function my_importance_sampler(gen_fn, args, constraints, num_traces)
414
414
return traces[idx]
415
415
end;
416
416
417
-
# A more efficient and numerically robust implementation of importance resampling is provided in Gen's inference library (see [`importance_resampling`](https://www.gen.dev/docs/stable/ref/inference/#Gen.importance_resampling)).
417
+
# A more efficient and numerically robust implementation of importance resampling is provided in Gen's inference library (see [`importance_resampling`](https://www.gen.dev/docs/stable/ref/inference/importance/#Gen.importance_sampling).
418
418
419
419
# Suppose our goal is to sample `:a` and `:b` from the conditional distribution given that we have observed `:c` is `false`. That is, we want to sample choice map $t$ with probability $0$ if $t(c) = \mbox{false}$ and otherwise probability:
0 commit comments