Skip to content

Commit df9d7d5

Browse files
sofmonknorvig
authored andcommitted
added fol_fc_ask to logic.py ; update README.md (#415)
* Update utils.py in pseudo code the sequence of arguments is " WEIGHTED-SAMPLE-WITH-REPLACEMENT(N, S, W)"   * Update utils.py in pseudo code the sequence of arguments is " WEIGHTED-SAMPLE-WITH-REPLACEMENT(N, S, W)"  same must follow in function "particle_filtering" in the file probability.py * Update learning.py weight_sample_with_replacement sequence of args * Update probability.py weighted_sample_with_replacement sequence of args * Update search.py * Update planning.py added double_tennis_problem from chapter 11 , figure 11.10 * Update utils.py added missing space after comma * Update learning.py added missing space after comma * Update probability.py added missing space after comma * Update search.py added missing space after comma * Update planning.py * Update planning.py * Update planning.py * Update planning.py * Update planning.py * Update planning.py * Update test_agents.py pep8 changes, showed flake8 errors * Update test_agents.py * Update test_agents.py * Update test_agents.py * Update test_text.py added missing whitespace after comma * Update utils.py added space after comma * Update search.py added space after comma * Update probability.py added space after comma * Update learning.py added space after comma * Update planning.py added double_tennis_problem * Update rl.py In the pseudocode figure 21.8, the first 'if' starts with argument 's', which is the previous state, not s1(i.e, the current state). * Update search.py the 'uniform_cost_search' in notebook 'search-4e.ipynb' resembles more to the pseudocode in book. * Update search.py * Update search.py * Update search.py * Update README.md * Update README.md * Update README.md * Update planning.py * Update planning.py added spaces after comma * Update planning.py * Update test_planning.py added double_tennis_problem test * Update test_planning.py * Update logic.py added fol_fc_ask from fig 9.3 * Update logic.py * Update test_planning.py
1 parent 10c82c6 commit df9d7d5

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ Here is a table of algorithms, the figure, name of the code in the book and in t
7676
| 9.3 | FOL-FC-Ask | `fol_fc_ask` | [`logic.py`][logic] |
7777
| 9.6 | FOL-BC-Ask | `fol_bc_ask` | [`logic.py`][logic] |
7878
| 9.8 | Append | | |
79-
| 10.1 | Air-Cargo-problem | |
80-
| 10.2 | Spare-Tire-Problem | |
81-
| 10.3 | Three-Block-Tower | |
82-
| 10.7 | Cake-Problem | |
83-
| 10.9 | Graphplan | |
79+
| 10.1 | Air-Cargo-problem |`air_cargo` |[`planning.py`][planning]|
80+
| 10.2 | Spare-Tire-Problem | `spare_tire` |[`planning.py`][planning]|
81+
| 10.3 | Three-Block-Tower | `three_block_tower` |[`planning.py`][planning]|
82+
| 10.7 | Cake-Problem | `have_cake_and_eat_cake_too` |[`planning.py`][planning]|
83+
| 10.9 | Graphplan | `GraphPlan` |[`planning.py`][planning]|
8484
| 10.13 | Partial-Order-Planner | |
8585
| 11.1 | Job-Shop-Problem-With-Resources | |
8686
| 11.5 | Hierarchical-Search | |
8787
| 11.8 | Angelic-Search | |
88-
| 11.10 | Doubles-tennis | |
88+
| 11.10 | Doubles-tennis | `double_tennis_problem` |[`planning.py`][planning]|
8989
| 13 | Discrete Probability Distribution | `ProbDist` | [`probability.py`][probability] |
9090
| 13.1 | DT-Agent | `DTAgent` | [`probability.py`][probability] |
9191
| 14.9 | Enumeration-Ask | `enumeration_ask` | [`probability.py`][probability] |

logic.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,22 @@ def subst(s, x):
842842

843843

844844
def fol_fc_ask(KB, alpha):
845-
raise NotImplementedError
845+
"""A simple forward-chaining algorithm. [Figure 9.3]"""
846+
while new is not None:
847+
new = []
848+
for rule in KB:
849+
p, q = parse_definite_clause(standardize_variables(rule))
850+
for p_ in random.KB.clauses:
851+
if p != p_:
852+
for theta in (subst(theta, p) == subst(theta, p_)):
853+
q_ = subst(theta, q)
854+
if not unify(q_,KB.sentence in KB) or not unify(q_, new):
855+
new.append(q_)
856+
phi = unify(q_,alpha)
857+
if phi is not None:
858+
return phi
859+
KB.tell(new)
860+
return None
846861

847862

848863
def standardize_variables(sentence, dic=None):

planning.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def goal_test(kb):
237237

238238
return PDLL(init, [eat_cake, bake_cake], goal_test)
239239

240+
240241
class Level():
241242
"""
242243
Contains the state of the planning problem
@@ -531,8 +532,8 @@ def double_tennis_problem():
531532
init = [expr('At(A, LeftBaseLine)'),
532533
expr('At(B, RightNet)'),
533534
expr('Approaching(Ball, RightBaseLine)'),
534-
expr('Partner(A,B)'),
535-
expr('Partner(A,B)')]
535+
expr('Partner(A, B)'),
536+
expr('Partner(B, A)')]
536537

537538
def goal_test(kb):
538539
required = [expr('Goal(Returned(Ball))'), expr('At(a, RightNet)'), expr('At(a, LeftNet)')]
@@ -543,17 +544,17 @@ def goal_test(kb):
543544

544545
##actions
545546
#hit
546-
precond_pos=[expr("Approaching(Ball,loc)"), expr("At(actor,loc)")]
547+
precond_pos=[expr("Approaching(Ball, loc)"), expr("At(actor, loc)")]
547548
precond_neg=[]
548549
effect_add=[expr("Returned(Ball)")]
549550
effect_rem = []
550-
hit = Action(expr("Hit(actor,Ball)"), [precond_pos, precond_neg], [effect_add, effect_rem])
551+
hit = Action(expr("Hit(actor, Ball)"), [precond_pos, precond_neg], [effect_add, effect_rem])
551552

552553
#go
553-
precond_pos = [ expr("At(actor,loc)")]
554+
precond_pos = [expr("At(actor, loc)")]
554555
precond_neg = []
555-
effect_add = [expr("At(actor,to)")]
556-
effect_rem = [expr("At(actor,loc)")]
557-
go = Action(expr("Go(actor,to)"), [precond_pos, precond_neg], [effect_add, effect_rem])
556+
effect_add = [expr("At(actor, to)")]
557+
effect_rem = [expr("At(actor, loc)")]
558+
go = Action(expr("Go(actor, to)"), [precond_pos, precond_neg], [effect_add, effect_rem])
558559

559560
return PDLL(init, [hit, go], goal_test)

probability.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,5 +643,7 @@ def particle_filtering(e, N, HMM):
643643
w[i] = float("{0:.4f}".format(w[i]))
644644

645645
# STEP 2
646+
646647
s = weighted_sample_with_replacement(N, s, w)
648+
647649
return s

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy