Fix geometric() in tutorial
Use count of failures to match torch.distrivbutions.Geometric
"cell_type": "code",
"execution_count": null,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "sample tensor(-1.3622)\n",
+ "log prob tensor(-1.8467)\n"
+ ]
+ }
+ ],
"source": [
"loc = 0. # mean zero\n",
"scale = 1. # unit variance\n",
"cell_type": "code",
"execution_count": null,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "tensor(2.2513)\n"
+ ]
+ }
+ ],
"source": [
"x = pyro.sample(\"my_sample\", dist.Normal(loc, scale))\n",
"print(x)"
"cell_type": "code",
"execution_count": null,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "('sunny', 82.32789611816406)\n",
+ "('cloudy', 50.69925308227539)\n",
+ "('sunny', 78.7621841430664)\n"
+ ]
+ }
+ ],
"source": [
"def weather():\n",
" cloudy = pyro.sample('cloudy', dist.Bernoulli(0.3))\n",
"cell_type": "code",
"execution_count": null,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "0\n"
+ ]
+ }
+ ],
"source": [
"def geometric(p, t=None):\n",
" if t is None:\n",
" t = 0\n",
" x = pyro.sample(\"x_{}\".format(t), dist.Bernoulli(p))\n",
- " if x.item() == 0:\n",
- " return x\n",
+ " if x.item() == 1:\n",
+ " return 0\n",
" else:\n",
- " return x + geometric(p, t + 1)\n",
+ " return 1 + geometric(p, t + 1)\n",
" \n",
"print(geometric(0.5))"
]
"cell_type": "code",
"execution_count": null,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "tensor(-0.3108)\n"
+ ]
+ }
+ ],
"source": [
"def normal_product(loc, scale):\n",
" z1 = pyro.sample(\"z1\", dist.Normal(loc, scale))\n",
