Rule Based Systems-Artificial Intelligence-Tutorial Handout, Exercises of Artificial Intelligence

Madam Amrita Ahuja distributed this handout in class of Artificial Intelligence course at Central University of Jammu and Kashmir. This handout explains important concepts including: Rule, Based, Systems, Search, Notes, Chaining, Pseudo, Code, Function, Optimization, Subtree, Algorithm

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

shaina_44kin
shaina_44kin ๐Ÿ‡ฎ๐Ÿ‡ณ

3.9

(9)

64 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Search and RBS Notes
Rule Based Systems and Search Notes
1. Rule-Based Systems:
General Forward Chaining Pseudo code
1. For all rules, and assertions, find all matches, i.e. Rule+Assertion combinations.
2. Check if any of the matches are defunct.
A defunct match is one where the consequents from the match are already in the DB.
3. Fire the first non-defunct match.
4. Repeat until no more matches fire.
NOTE: If rules have a DELETE, then assertions maybe be removed from DB, then matches in
step 2 can become "un"-defuncted. Look at quiz 1 from 2006, for example of a case where
DELETE causes an infinite loop.
General Backchaining Pseudo code:
function rule_match_goal_tree(hypothesis, rules, DB)
1. check hypothesis against DB exit if satisfied
2. Find all matching rules: any rule with a consequent that matches hypothesis
3. For each rule in matching rules:
i) binding <- unify rule.consequent and hypothesis
ii) subtree <- antecedents_goal tree(rule, rules, binding, DB)
iii) Optimization: If subtree evaluation returns true,
we can short-circuit because we are ORing subtrees.
return OR(rule subtrees)
function antecedent_goal_tree(rule, rules, binding, DB)
for each antecedent:
1. new-hypothesis <- antecedent + binding
2. check new-hypothesis against DB, if matched, update binding
3. subtree <- rule_match_goal_tree(new-hypothesis, rules, DB)
4. Optimization: Short circuit if the antecedent logics calls for it
i.e. if in an AND then the first failure fails the whole branch.
if in an OR, the first success implies the whole branch succeeds
return {antecedent logic}(antecedent subtrees)
Note: If during antecedent_goal_tree step 2, there are multiple matches of the hypothesis in
the DB then we can opt to create an OR subtree to represent all those database instantiations.
2. Search:
Terminology:
Informed vs. Uninformed
Whether there is some evaluation function f(x) that help guide your search. Except for
BFS, DFS, and British Museum all the other searches we studied in this class are
informed in some way.
Complete vs. Incomplete
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Rule Based Systems-Artificial Intelligence-Tutorial Handout and more Exercises Artificial Intelligence in PDF only on Docsity!

Rule Based Systems and Search Notes

1. Rule-Based Systems:

General Forward Chaining Pseudo code

  1. For all rules, and assertions, find all matches , i.e. Rule+Assertion combinations.
  2. Check if any of the matches are defunct. A defunct match is one where the consequents from the match are already in the DB.
  3. Fire the first non-defunct match.
  4. Repeat until no more matches fire.

NOTE: If rules have a DELETE, then assertions maybe be removed from DB, then matches in step 2 can become "un"-defuncted. Look at quiz 1 from 2006, for example of a case where DELETE causes an infinite loop.

General Backchaining Pseudo code:

function rule_match_goal_tree (hypothesis, rules, DB)

  1. check hypothesis against DB exit if satisfied
  2. Find all matching rules: any rule with a consequent that matches hypothesis
  3. For each rule in matching rules: i) binding <- unify rule.consequent and hypothesis ii) subtree <- antecedents_goal tree (rule, rules, binding, DB) iii) Optimization: If subtree evaluation returns true, we can short-circuit because we are ORing subtrees. return OR(rule subtrees)

function antecedent_goal_tree (rule, rules, binding, DB) for each antecedent:

  1. new-hypothesis <- antecedent + binding
  2. check new-hypothesis against DB, if matched, update binding
  3. subtree <- rule_match_goal_tree (new-hypothesis, rules, DB)
  4. Optimization: Short circuit if the antecedent logics calls for it i.e. if in an AND then the first failure fails the whole branch. if in an OR, the first success implies the whole branch succeeds return {antecedent logic}(antecedent subtrees)

Note: If during antecedent_goal_tree step 2, there are multiple matches of the hypothesis in the DB then we can opt to create an OR subtree to represent all those database instantiations.

2. Search:

Terminology:

Informed vs. Uninformed Whether there is some evaluation function f(x) that help guide your search. Except for BFS, DFS, and British Museum all the other searches we studied in this class are informed in some way. Complete vs. Incomplete

If there exists a solution (path from s to g) the algorithm will find it.

Optimal vs. Non-optimal The solution found is also the best one (best counted by the cost of the path).

Generic Search Algorithm:

function Search(graph, start, goal):

0. Initialize agenda = [ [start] ] extended_list = []

while agenda is not empty:

**1. path = agenda.pop(0) # get first element from agenda & return it

  1. if is-path-to-goal(path, goal)** **return path
  2. otherwise extend the current path if not already extended** for each connected node **make a new path (don't add paths with loops!)
  3. add new paths from 3 to agenda and reorganize agenda** (algorithms differ here see table below) fail!

The code in red only applies if you are using an extended list.

Agenda keeps track of all the paths under consideration, and the way it is maintained is the key to the difference between most of the search algorithms.

Loops in paths: Thou shall not create or consider paths with cycles in step 3.

Extended list is the list of nodes that has undergone "extension" (step 3). Using an extended list is an optional optimization that could be applied to all algorithms. (some with implications, see A*) In some literature extended list is also referred to as "closed" list, and the agenda the "open" list.

Backtracking : When we talk about DFS or DFS variants (like Hill Climbing) we talk about with or without "backtracking". You can think of backtracking in terms of the agenda. If we make our agenda size 1, then this is equivalent to having no backtracking. Having agenda size > 1 means we have some partial path to go back on, and hence we can backtrack.

Exiting the search: Non-optimal searches may actually exit when it finds or adds a path with a goal node to the agenda (at step 3). But optimal searches must only exit when the path is the first removed from the agenda (step 1,2).

Search Algorithm Properties Required Parameters What is does with the agenda in step 4.

Beam Search

Like BFS but expand nodes in f(x) order.

Incomplete for small k; Complete and like BFS for k = infinity.

Non-optimal

When k = 1, Beam search is analogous to Hill Climbing without backtracking.

  1. the beam width k
  2. f(x) to sort the top paths by.
    1. Keep only k-top paths that are of length n. (So keep a sorted list of paths for every path length)
    2. Keep only top-k paths as sorted by f (x)

British Museum

Brutally exhaustive, Uninformed, Complete

None

Most likely implemented using a breadth-first enumeration of all paths

Branch & Bound Optimal,

g(x) = c(s, x) = the cost of path from s to node x. f(x) = g(x) + 0

Sort paths by f(x)

A* w/o extended list

(or B&B w/o extended list + admissible heuristic)

Optimal if h is admissible

f(x) = g(x) + h(x,g) h(x,g) is the estimate of the cost from x to g.

h(x) must be an admissible heuristic

Sort paths by f(x)

A* w extended list Optimal if h is consistent

f(x) = g(x) + h(x)

h(x) must be a consistent heuristic

Sort paths by f(x)

NOTE: A* with extended list and a non-consistent heuristic may be non-optimal!!

Definitions:

f(x) is the total cost of the path that your algorithm uses to rank paths. g(x) is the cost of the path so far. h(x) is the (under)estimate of the remaining cost to the goal g node. f(x) = g(x) + h(x) c(x, y) is the actual cost to go from node x to node y.

Admissible Heuristic: โ— For all nodes x in Graph, h(x) <= c(n, g) โ— i.e. the heuristic is an underestimate of the actual cost/distance to the goal.

Consistent Heuristic:

โ— For edges in an undirected graph, where m is connected to n. m |h(m) - h(n)| <= c(m, n) โ— For edges in a directed graph n is a descendent of m or m -> n m h(m) - h(n) <= c(m,n) โ— You can verify consistency by checking each edge and see if difference between h values on an edge <= the actual edge cost.

Consistency implies Admissibility If you can verify consistency, then the heuristic must be admissible. But Admissibility does not imply Consistency!!

You can make an admissible heuristic consistent by using the Pathmax algorithm:

Pathmax in a nut shell: When you are extending nodes. If you find an edge that is not consistent, i.e. h(m) - h(n) > c(m,n); make it consistent by setting the end h(n) heuristic value to h(m). Hence the difference becomes 0, which is always <= c(m,n) and consistent.

Short explanation on why Admissibility must be true for A to be optimal:*

Let C* is the actual cost of the optimal path from s to g.

A* search always extend paths in order of increasing f(x), where f(x) = g(x)+h(x) You can think of A* expanding paths on a fringe. Once it has extended some path of value f(x) we are guaranteed that it has seen all paths lower than f(x).

If h(x) is admissible, (i.e. h(x) is an underestimate of the actual path cost to node g) then we know that any partial path leading to the optimal path solution must have f(x) <= C*.

f(x) = g(x) + h(x) <= C*

So as we expand the fringe, we are guaranteed to extend through all partial paths leading to the optimal path C*

However If h(x) is an overestimate, then optimality may not be guaranteed; Because there may be a partial paths that lead to the optimal path where:

f(x) = g(x) + h(x) > C*

Because of the fringe property, such a partial paths will be visited after we visit any path with cost C*. So we will end up by either by-passing the optimal solution and/or mistaken a non- optimal path as the solution.

Consistency ensures that f(x) is always non-decreasing. That is if p_1, p_2, p_3...p_n are partial paths leading to the optimal path, a consistent heuristic ensures that f(p_1) <= f(p_2) <=....<= f(p_n). This strictly non-decreasing property or monotonicity, ensures that once a node has been extended it is the absolute best f(x) path out of that node; it is safe to not visit that node again.

How Different Heuristics in A affect performance*

General rule: More closely h(x) approximates the actual cost to the goal the faster A* will find the solution (or A* will do less work extending paths).