Skip to content

Commit 0fec505

Browse files
committed
Fix 3 pre-existing notebook logic bugs
- search.ipynb: cell 112 redefines hill_climbing as a TSP-specific version (using two_opt), shadowing the library's generic one; the later Peak-Finding section then called it on a PeakFindingProblem (no two_opt) and failed. Re-import the library hill_climbing right before that section. - chapter22/Parsing.ipynb: CYK_parse returns a probability table (defaultdict(float)), but the cells called .leaves on the float values. Display the probabilities instead (full table; VP entries). - chapter19/Optimizer and Backpropagation.ipynb: pseudocode() is a string API (e.g. pseudocode('Back-Prop-Learning')); pseudocode(adam) passed a function and Adam has no aima-pseudocode entry. Dropped it; psource(adam) still shows the implementation. All three now run clean headless; no module changes (test suite unaffected).
1 parent 09890ad commit 0fec505

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎notebooks/chapter19/Optimizer and Backpropagation.ipynb‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@
222222
"metadata": {},
223223
"outputs": [],
224224
"source": [
225-
"pseudocode(adam)\n",
226225
"psource(adam)"
227226
]
228227
},

‎notebooks/chapter22/Parsing.ipynb‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
}
303303
],
304304
"source": [
305-
"parses = {k: p.leaves for k, p in P.items()}\n",
305+
"parses = {k: p for k, p in P.items() if p}\n",
306306
"\n",
307307
"print(parses)"
308308
]
@@ -329,8 +329,9 @@
329329
}
330330
],
331331
"source": [
332-
"for subtree in P['VP', 2, 3].leaves:\n",
333-
" print(subtree.leaves)"
332+
"# CYK_parse returns a probability table P[(symbol, start, length)] -> probability;\n",
333+
"# show where the grammar can parse a VP (verb phrase) and with what probability\n",
334+
"print({k: p for k, p in P.items() if k[0] == 'VP' and p})"
334335
]
335336
},
336337
{

‎notebooks/search.ipynb‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3479,6 +3479,16 @@
34793479
"This could also be solved by Hill Climbing as follows."
34803480
]
34813481
},
3482+
{
3483+
"cell_type": "code",
3484+
"execution_count": null,
3485+
"metadata": {},
3486+
"outputs": [],
3487+
"source": [
3488+
"# re-import the library's generic hill_climbing (the TSP cell above shadowed it with a two_opt-based version)\n",
3489+
"from aima.search import hill_climbing"
3490+
]
3491+
},
34823492
{
34833493
"cell_type": "code",
34843494
"execution_count": 15,

0 commit comments

Comments
 (0)