240 likes | 481 Views
Heuristic Search. Intro to Prolog. Heuristic Algorithm. Two Parts Heuristic Measure Algorithm that uses it to search the state space. Tic Tac Toe. Exhaustive Search Total Number of States 9x8x7x6… =9!. How to Decrease Search Space?. Configuration Equivalent under symmetric operation
E N D
Heuristic Search Intro to Prolog
Heuristic Algorithm • Two Parts • Heuristic Measure • Algorithm that uses it to search the state space
Tic Tac Toe • Exhaustive Search • Total Number of States • 9x8x7x6… • =9!
How to Decrease Search Space? • Configuration Equivalent under symmetric operation • Reduced to 12x7! • Still Exponential
Winning Lines • 4 2 Move to the board in which X has the most winning lines 2/3 of the space is pruned away with the first move
8 Puzzle • Four Heuristics • 283 283 283 • 164 1 4 164 • 75 765 75
Good Heuristics • The Design of a good Heuristic is an empirical problem, judgment and in tuition help, but the final measure of a heuristic must be its actual performance on problem instances • Fallible. It is possible that a search algorithm can be misled down some path that fails to lead to a goal-depth count of search may be used
Bias Search in favor of states found shallower in the graph • If two states have the same or nearly the same heuristic evaluations it is generally preferable to examine the state that is nearest to the root state of the graph • Evaluation function Sum of two components • F(n) = g(n) + h(n)
Best-First Search • Best First Search, which is a way of combining the advantages of both depth-first and breadth-first search into a single method • In hill climbing, one move is selected and all others are rejected, never to be reconsidered. • In Best first, one move is selected but the others are kept around so they can be revisited later if the selected path becomes less promising • Hill climbing will stop if there are no successor states with better values than the current state
Two Lists of Nodes • OPEN- Nodes that have been generated and have had the heuristic function applied to them but have not yet been examined(had their successors generated). Priority Queue in which highest priority nodes are those with the most promising heuristic value • CLOSED- Nodes that have already been examined. Check to see if node has been generated before(For Graphs)
Algorithm • Start with OPEN containing just the initial state • Until a goal is found or there are no nodes left on OPEN do • A) pick the best node on open • B) Generate its successors • C) For each successor do • if it has not been generated before, evaluate it, add it to open, and record its parent • If it has been generated before, change the parent if this new path is better than the previous one. In that case, update the cost of getting to this node and to any successors that this node may already have
Presentation on A* • Explanation of Algorithm Ahmed Zia Tassadaq Shahid Hani Umar • Overestimation and Underestimation (Significance) Minhajuddin Asad Bilal Taimur Hashim Sajid • Advantages and Disadvantages Amin Ali Salman Fahad Sana Atif Ali Haseeb • Admissibility Talha Mubeen Shehryar Infraz Safdar
Facts, Rules and Queries • A collection of facts and rules is called a knowledge base • How do we use a Prolog Program? • By Posing Queries. • KB1 (Collection of facts) • man(kasim). • man(khurram). • man(bhatti). • Playsguitar(bhatti).
Queries • ?- man(kasim). • Yes • ?-Playguitar(kasim). • No • ?-man(amir). • No. • Drivestaxi(amir). • No.
KB2 • Listenstomusic(asim). • Happy(bashir). • Playsguitar(asim) :- listenstomusic(asim). • Playsguitar(bashir) :- listenstomusic(bashir). • Listenstomusic(bashir) :- happy(bashir). • 2 facts and 3 rules
:- • Should be read as ‘if’ or ‘is implied by’ • Rule head :- body • If Prolog knows that body follows from the information in the knowledge base Prolog can infer head • This fundamental deduction step is what logicians call modus ponens • ?- playsguitar(asim). • Yes (Although fact not explicitly stated)
Chain Rule • ?-playsguitar(bashir). • Yes (inferred knowledge) • The facts and rules contained in a knowledge base are called clauses • Thus KB2 contains 5 clauses and three predicates which are • listensToMusic • Happy • playsguitar
KB3 • 5 clauses • Happy(asim). • Listentomusic(khurram). • Playsguitar(asim):-listenstomusic(asim),happy(asim). • Playsguitar(khurram):-happy(khurram). • Playsguitar(khurram):-Listentomusic(khurram).
Logical Conjunction • Playsguitar(asim):-listenstomusic(asim),happy(asim). • Note that the rule has two item in its body (two goals) • , AND • ?- Playsguitar(asim)?
Logical Disjunction • Playsguitar(khurram):-happy(khurram). • Playsguitar(khurram):-Listentomusic(khurram). • It is a way of saying either --- or --- • ?-Playsguitar(khurram).
Another way to express OR • Playsguitar(khurram):-happy(khurram);Listentomusic(khurram). • Woman(sara). • Woman(marium). • Woman(rubab). • Loves(khurram,sara). • Loves(asim,sara). • Loves(abc,xyz). • Loves(xyz,abc).
Queries with Variables • ?-Woman(X). • Prolog works its way top to bottom trying to match or unify the expression woman(X) • Use ; to find start prolog searching on from the last point onwards • ?-Loves(asim,X), woman(X). • Write a Query for jealous
Prolog Syntax • Atoms A string of characters which may be upper or lower case, digits and the underscore character that begins with lowercase letter Arbitrary sequence of chars in single quotes ‘’ String of special chars @= or ===> ; or :-
Numbers • 23, 1001, 0, -365 • Variables • Start with capital or underscore • Variable starting with underscore _ is called anonymous variable • Complex terms • Hide(X,father(father(father(asim))))