Thanks to visit codestin.com
Credit goes to github.com

Skip to content

added fol_fc_ask to logic.py ; update README.md #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Mar 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e14c34b
Update utils.py
sofmonk Mar 17, 2017
8298332
Update utils.py
sofmonk Mar 17, 2017
588c318
Update learning.py
sofmonk Mar 17, 2017
8b2b94b
Update probability.py
sofmonk Mar 17, 2017
35c9d51
Update search.py
sofmonk Mar 18, 2017
0be9f2c
Update planning.py
sofmonk Mar 18, 2017
76bd895
Update utils.py
sofmonk Mar 18, 2017
f9b8ad4
Update learning.py
sofmonk Mar 18, 2017
a60ef5a
Update probability.py
sofmonk Mar 18, 2017
f1b4e25
Update search.py
sofmonk Mar 18, 2017
d45d8d4
Update planning.py
sofmonk Mar 18, 2017
c43fd7e
Update planning.py
sofmonk Mar 18, 2017
dc20b93
Update planning.py
sofmonk Mar 18, 2017
4bac058
Update planning.py
sofmonk Mar 18, 2017
a31c09b
Merge branch 'master' into master
sofmonk Mar 18, 2017
cdbbde7
Update planning.py
sofmonk Mar 18, 2017
86615b3
Update planning.py
sofmonk Mar 18, 2017
9d272b7
Update test_agents.py
sofmonk Mar 18, 2017
1581f7a
Update test_agents.py
sofmonk Mar 18, 2017
7f9d053
Update test_agents.py
sofmonk Mar 18, 2017
594736d
Update test_agents.py
sofmonk Mar 18, 2017
b6f9de4
Update test_text.py
sofmonk Mar 18, 2017
7d5dcba
Update utils.py
sofmonk Mar 18, 2017
2783b6a
Update search.py
sofmonk Mar 18, 2017
99cbbaf
Update probability.py
sofmonk Mar 18, 2017
620cb41
Update learning.py
sofmonk Mar 18, 2017
ab26cd8
Update planning.py
sofmonk Mar 18, 2017
f69e7c1
Update rl.py
sofmonk Mar 19, 2017
fba8b92
Merge pull request #4 from sofmonk/patch-2
sofmonk Mar 19, 2017
fce259a
Update search.py
sofmonk Mar 19, 2017
6b82783
Update search.py
sofmonk Mar 19, 2017
5e628be
Update search.py
sofmonk Mar 19, 2017
86f10d5
Update search.py
sofmonk Mar 19, 2017
a925fe6
Merge branch 'master' into patch-1
norvig Mar 22, 2017
1bd46b9
Update README.md
sofmonk Mar 23, 2017
6e3fb8e
Update README.md
sofmonk Mar 23, 2017
3f3ef6d
Update README.md
sofmonk Mar 23, 2017
534cfa7
Merge branch 'master' into patch-1
sofmonk Mar 23, 2017
75fcf6e
Merge pull request #3 from sofmonk/patch-1
sofmonk Mar 23, 2017
5be56d4
Merge branch 'master' into sofmonk-planning
sofmonk Mar 23, 2017
430b908
Merge pull request #2 from sofmonk/sofmonk-planning
sofmonk Mar 23, 2017
2d4a0d5
Merge branch 'master' into sofmonk-patch-1
sofmonk Mar 23, 2017
4b4f70e
Merge pull request #1 from sofmonk/sofmonk-patch-1
sofmonk Mar 23, 2017
8bbd8e5
Merge branch 'master' into master
sofmonk Mar 23, 2017
8f0899a
Update planning.py
sofmonk Mar 23, 2017
0ed9512
Update planning.py
sofmonk Mar 23, 2017
8845d4b
Update planning.py
sofmonk Mar 23, 2017
da4733f
Update test_planning.py
sofmonk Mar 23, 2017
32cd0e6
Update test_planning.py
sofmonk Mar 23, 2017
7afe352
Update logic.py
sofmonk Mar 25, 2017
00d29b4
Update logic.py
sofmonk Mar 25, 2017
b5b1b91
Update test_planning.py
sofmonk Mar 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ Here is a table of algorithms, the figure, name of the code in the book and in t
| 9.3 | FOL-FC-Ask | `fol_fc_ask` | [`logic.py`][logic] |
| 9.6 | FOL-BC-Ask | `fol_bc_ask` | [`logic.py`][logic] |
| 9.8 | Append | | |
| 10.1 | Air-Cargo-problem | |
| 10.2 | Spare-Tire-Problem | |
| 10.3 | Three-Block-Tower | |
| 10.7 | Cake-Problem | |
| 10.9 | Graphplan | |
| 10.1 | Air-Cargo-problem |`air_cargo` |[`planning.py`][planning]|
| 10.2 | Spare-Tire-Problem | `spare_tire` |[`planning.py`][planning]|
| 10.3 | Three-Block-Tower | `three_block_tower` |[`planning.py`][planning]|
| 10.7 | Cake-Problem | `have_cake_and_eat_cake_too` |[`planning.py`][planning]|
| 10.9 | Graphplan | `GraphPlan` |[`planning.py`][planning]|
| 10.13 | Partial-Order-Planner | |
| 11.1 | Job-Shop-Problem-With-Resources | |
| 11.5 | Hierarchical-Search | |
| 11.8 | Angelic-Search | |
| 11.10 | Doubles-tennis | |
| 11.10 | Doubles-tennis | `double_tennis_problem` |[`planning.py`][planning]|
| 13 | Discrete Probability Distribution | `ProbDist` | [`probability.py`][probability] |
| 13.1 | DT-Agent | `DTAgent` | [`probability.py`][probability] |
| 14.9 | Enumeration-Ask | `enumeration_ask` | [`probability.py`][probability] |
Expand Down
17 changes: 16 additions & 1 deletion logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,22 @@ def subst(s, x):


def fol_fc_ask(KB, alpha):
raise NotImplementedError
"""A simple forward-chaining algorithm. [Figure 9.3]"""
while new is not None:
new = []
for rule in KB:
p, q = parse_definite_clause(standardize_variables(rule))
for p_ in random.KB.clauses:
if p != p_:
for theta in (subst(theta, p) == subst(theta, p_)):
q_ = subst(theta, q)
if not unify(q_,KB.sentence in KB) or not unify(q_, new):
new.append(q_)
phi = unify(q_,alpha)
if phi is not None:
return phi
KB.tell(new)
return None


def standardize_variables(sentence, dic=None):
Expand Down
17 changes: 9 additions & 8 deletions planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def goal_test(kb):

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


class Level():
"""
Contains the state of the planning problem
Expand Down Expand Up @@ -531,8 +532,8 @@ def double_tennis_problem():
init = [expr('At(A, LeftBaseLine)'),
expr('At(B, RightNet)'),
expr('Approaching(Ball, RightBaseLine)'),
expr('Partner(A,B)'),
expr('Partner(A,B)')]
expr('Partner(A, B)'),
expr('Partner(B, A)')]

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

##actions
#hit
precond_pos=[expr("Approaching(Ball,loc)"), expr("At(actor,loc)")]
precond_pos=[expr("Approaching(Ball, loc)"), expr("At(actor, loc)")]
precond_neg=[]
effect_add=[expr("Returned(Ball)")]
effect_rem = []
hit = Action(expr("Hit(actor,Ball)"), [precond_pos, precond_neg], [effect_add, effect_rem])
hit = Action(expr("Hit(actor, Ball)"), [precond_pos, precond_neg], [effect_add, effect_rem])

#go
precond_pos = [ expr("At(actor,loc)")]
precond_pos = [expr("At(actor, loc)")]
precond_neg = []
effect_add = [expr("At(actor,to)")]
effect_rem = [expr("At(actor,loc)")]
go = Action(expr("Go(actor,to)"), [precond_pos, precond_neg], [effect_add, effect_rem])
effect_add = [expr("At(actor, to)")]
effect_rem = [expr("At(actor, loc)")]
go = Action(expr("Go(actor, to)"), [precond_pos, precond_neg], [effect_add, effect_rem])

return PDLL(init, [hit, go], goal_test)
2 changes: 2 additions & 0 deletions probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,7 @@ def particle_filtering(e, N, HMM):
w[i] = float("{0:.4f}".format(w[i]))

# STEP 2

s = weighted_sample_with_replacement(N, s, w)

return s