



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 6
This page cannot be seen from the preview
Don't miss anything!




General Forward Chaining Pseudo code
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)
function antecedent_goal_tree (rule, rules, binding, DB) for each antecedent:
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.
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
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.
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).