Clustering (Un-supervised Learning)

Similar documents
Introduction to Artificial Intelligence (G51IAI)

Introduction to Artificial Intelligence (G51IAI) Dr Rong Qu. Blind Searches

Informed search algorithms

COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

Introduction to Artificial Intelligence. Informed Search

Overview. Path Cost Function. Real Life Problems. COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

Artificial Intelligence. Informed search methods

Informed search algorithms

COMP9414/ 9814/ 3411: Artificial Intelligence. 5. Informed Search. Russell & Norvig, Chapter 3. UNSW c Alan Blair,

Informed search algorithms. Chapter 4, Sections 1 2 1

Informed Search and Exploration

CS486/686 Lecture Slides (c) 2015 P.Poupart

CS486/686 Lecture Slides (c) 2014 P.Poupart

Solving Problems by Searching

Graphs vs trees up front; use grid too; discuss for BFS, DFS, IDS, UCS Cut back on A* optimality detail; a bit more on importance of heuristics,

Informed Search and Exploration

COSC343: Artificial Intelligence

CS:4420 Artificial Intelligence

PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE

Artificial Intelligence: Search Part 2: Heuristic search

Informed Search Algorithms. Chapter 4

Artificial Intelligence CS 6364

Solving Problems using Search

Problem solving and search

CS414-Artificial Intelligence

Princess Nora University Faculty of Computer & Information Systems ARTIFICIAL INTELLIGENCE (CS 370D) Computer Science Department

PEAS: Medical diagnosis system

Outline. Informed search algorithms. Best-first search. Review: Tree search. A search Heuristics. Chapter 4, Sections 1 2 4

COMP219: Artificial Intelligence. Lecture 7: Search Strategies

Informed Search and Exploration

Planning, Execution & Learning 1. Heuristic Search Planning

Searching and NetLogo

Artificial Intelligence

Artificial Intelligence, CS, Nanjing University Spring, 2018, Yang Yu. Lecture 3: Search 2.

Robot Programming with Lisp

Problem solving and search

Artificial Intelligence

Solving Problems by Searching

Solving Problems by Searching

Week 3: Path Search. COMP9414/ 9814/ 3411: Artificial Intelligence. Motivation. Example: Romania. Romania Street Map. Russell & Norvig, Chapter 3.

4. Solving Problems by Searching

Lecture Plan. Best-first search Greedy search A* search Designing heuristics. Hill-climbing. 1 Informed search strategies. Informed strategies

Informed search algorithms

Solving Problems by Searching. Artificial Intelligence Santa Clara University 2016

AGENTS AND ENVIRONMENTS. What is AI in reality?

Informed Search. Topics. Review: Tree Search. What is Informed Search? Best-First Search

Problem solving and search

TDT4136 Logic and Reasoning Systems

Informed Search and Exploration

Problem Solving and Search. Geraint A. Wiggins Professor of Computational Creativity Department of Computer Science Vrije Universiteit Brussel

AGENTS AND ENVIRONMENTS. What is AI in reality?

Map coloring. 4 colors. From coloring to CSP. Informed Search Methods. Constrained Satisfaction Search. Constrained Satisfaction Search.

Foundations of Artificial Intelligence

CS 771 Artificial Intelligence. Informed Search

CSE 473. Chapter 4 Informed Search. CSE AI Faculty. Last Time. Blind Search BFS UC-BFS DFS DLS Iterative Deepening Bidirectional Search

CS-E4800 Artificial Intelligence

Outline for today s lecture. Informed Search I. One issue: How to search backwards? Very briefly: Bidirectional search. Outline for today s lecture

Artificial Intelligence

Artificial Intelligence

CAP 4630 Artificial Intelligence

Artificial Intelligence, CS, Nanjing University Spring, 2018, Yang Yu. Lecture 2: Search 1.

Algorithm. December 7, Shortest path using A Algorithm. Phaneendhar Reddy Vanam. Introduction. History. Components of A.

Artificial Intelligence: Search Part 1: Uninformed graph search

Outline. Best-first search

CS:4420 Artificial Intelligence

ARTIFICIAL INTELLIGENCE SOLVING PROBLEMS BY SEARCHING. Chapter 3

Informatics 2D: Tutorial 2 (Solutions)

Informed search methods

Foundations of Artificial Intelligence

ARTIFICIAL INTELLIGENCE (CSC9YE ) LECTURES 2 AND 3: PROBLEM SOLVING

Ar#ficial)Intelligence!!

TDDC17. Intuitions behind heuristic search. Recall Uniform-Cost Search. Best-First Search. f(n) =... + h(n) g(n) = cost of path from root node to n

16.1 Introduction. Foundations of Artificial Intelligence Introduction Greedy Best-first Search 16.3 A Weighted A. 16.

A.I.: Informed Search Algorithms. Chapter III: Part Deux

Shortest path using A Algorithm

Problem solving and search

Outline. Solving Problems by Searching. Introduction. Problem-solving agents

Automated Planning & Artificial Intelligence

Informed Search. Dr. Richard J. Povinelli. Copyright Richard J. Povinelli Page 1

Optimal Control and Dynamic Programming

Lecture 4: Search 3. Victor R. Lesser. CMPSCI 683 Fall 2010

Informed search algorithms

Foundations of Artificial Intelligence

Informed search algorithms

Seminar: Search and Optimization

Problem Solving and Search

S A E RC R H C I H NG N G IN N S T S A T T A E E G R G A R PH P S

TDDC17. Intuitions behind heuristic search. Best-First Search. Recall Uniform-Cost Search. f(n) =... + h(n) g(n) = cost of path from root node to n

Outline. Best-first search

Warm- up. IteraAve version, not recursive. class TreeNode TreeNode[] children() boolean isgoal() DFS(TreeNode start)

Planning and search. Lecture 1: Introduction and Revision of Search. Lecture 1: Introduction and Revision of Search 1

Informed Search Lecture 5

Chapter 3: Informed Search and Exploration. Dr. Daisy Tang

Introduction to Artificial Intelligence (G51IAI) Dr Rong Qu. Problem Space and Search Tree

Informed Search (Ch )

Lecture 4: Informed/Heuristic Search

Basic Search. Fall Xin Yao. Artificial Intelligence: Basic Search

Solving problems by searching

Uninformed Search. Problem-solving agents. Tree search algorithms. Single-State Problems

Transcription:

Clustering (Un-supervised Learning) Partition-based clustering: k-mean Goal: minimize sum of square of distance o Between each point and centers of the cluster. o Between each pair of points in the cluster Algorithm: Initialize K cluster centers Random K separated points o Repeat until stabilization: Assign each point to closest cluster center Generate new cluster centers Adjust clusters by merging or splitting Centers

Clustering (Un-supervised Learning) Distance functions Consider two records x=(x 1,,x d ), y=(y 1,,y d ): Special cases: p=1: Manhattan distance p=2: Euclidean distance p p d d p p y x y x y x y x d... ), ( 2 2 1 1... ), ( 2 2 1 1 p x p y y x y x y x d 2 2 2 2 2 1 1 ) (... ) ( ) ( ), ( d d y x y x y x y x d

Foundations of Artificial Intelligence Problems, Problem Spaces and Search

Problems, Problem Spaces and Search Defining Problems as Search Spaces Weak Search Techniques Strong Search Techniques Things to achieve : Understand the difference between blind and heuristic search. Know what a blind and heuristic method is. Use some of the search techniques on real problems.

Defining a Problem as a Search Space Many problems exhibit no detectable regular structure to be exploited, they appear chaotic, and do not yield to efficient algorithms. Exhaustive search of large state spaces appears to be the only viable approach. We introduce techniques for exhaustive (blind) search and present some examples of intelligent, heuristic search.

Defining a Problem as a Search Space The concept of search plays an ambivalent role in science and engineering, in one way, any problem whatsoever can be seen as a search for the right answer.

Defining a Problem as a Search Space Often we can't simply write down and solve the equations for a problem. This is not to dismiss mathematical approaches to problem solving, especially the mechanistic, deterministic variety that are the central concern of science and engineering. These problems can be augmented by other kinds of problem solving approaches that will make engineering better.

Defining a Problem as a Search Space Formulation and Representation of Problems To solve problems that are of interest to scientists and engineers we need to apply a common vocabulary. State space, or search space Goal, or search criterion Search algorithm Data structures Nodes Search Trees Decision Trees Search Graphs Search Space

Search Tree Parents and Ancestors Children and Descendants

Combinatorial Explosion The travelling sales problem n! n=10 3,628,800

Combinatorial Explosion Claude Shannon delivered a paper in 1949 at a New York conference on how a computer could play chess. Chess has 10 120 unique games (with an average of 40 moves - the average length of a master game). Working at 200 million positions per second, Deep Blue would require 10 100 years to evaluate all possible games. To put this is some sort of perspective, the universe is only about 10 10 years old and 10 120 is larger than the number of atoms in the universe.

Representing The Problem A chessboard layout is a matrix, e.g. if the white queen is at d1. If 2 represents white queen, 2d1 can represent this fact. To play the game a computer needs to search for the wining position (state) in a huge tree of game states.

A game tree

Foxes and Chickens

Foxes and Chickens The Problem Three foxes and three chickens seek to cross a river. A boat is available which can hold two animals and which can be navigated by any combination of foxes and chickens involving one or two animals. The chickens insist on never being left in a minority on either riverbank, for fear of being eaten by a majority of foxes. Find a schedule of crossings that will permit all the foxes and chickens to cross the river safely.

Foxes and Chickens Representing The Problem

Foxes and Chickens Representing The Problem F F F C C C B

Foxes and Chickens Many questions arise If all the generated nodes are expanded we generate multiple copies of many nodes. Also many nodes which are generated are unacceptable.

Foxes and Chickens Untenable States

Foxes and Chickens Solving the Problem

Foxes and Chickens Untenable States

Foxes and Chickens Solving the Problem

Foxes and Chickens Solving the Problem Copy of start state

Foxes and Chickens START COL 1 COL 2 COL 3 COL 4 COL 5 COL 6 COL 7 COL 8 COL 9 ROW 1 ROW 2 ROW 3 ROW 4 ROW 5

Foxes and Chickens Copy of start state Copy of start state

Foxes and Chickens START COL 1 COL 2 COL 3 COL 4 COL 5 COL 6 COL 7 COL 8 COL 9 ROW 1 ROW 2 ROW 3 ROW 4 ROW 5

Define the Problem as a Search Space Questions come to mind. For example, is there more than one ordering sequence to performing the node expansion? Does our search method actually find a solution? Is it a good solution? Does it find the optimal solution? Which of method should be used?

Define the Problem as a Search Space Two categories of search methods Blind (exhaustive) search depth/breadth first search Heuristic search A* search

Define the Problem as a Search Space We ll evaluate all the later search techniques w.r.t the below 4 criteria 1. Completeness Is the strategy guaranteed to find a solution if one exist? 2. Time Complexity How long does it take to find a solution?

Define the Problem as a Search Space We ll evaluate all the later search techniques w.r.t the below 4 criteria 3. Space Complexity How much memory does it take to perform the search? 4. Optimality Does the strategy find the optimal solution where there are several solutions?

Blind Search Strategies Since search forms the core of many intelligent processes, it is useful to structure AI programs in a way that facilitates describing and performing the search process. We need to study the question of how to decide which strategy to apply and even what the strategies are.

Blind Search The algorithms and strategies for exhaustive search - that is those methods for straightforwardly expanding every single node in a search tree - are sometimes called the blind search methods because although they are very general they lack the power of knowledge-guided search. Thus, their very generality implies a certain weakness. Blind searches can usually be broken down into two forms of search, depth-first search and breadth-first search.

Blind Search Blind searches have no preference as to which state (node) that is expanded next The different types of blind searches are characterised by the order in which they expand the nodes This can have a dramatic effect on how well the search performs when measured against the four criteria we defined earlier

Blind Search Breadth first search Depth first search Uniform cost search Depth limited search

Blind Search Breadth First Search Expand Root Node First Expand all nodes at level 1 before expanding level 2 OR Expand all nodes at level d before expanding nodes at level d+1 A B C D E D E F G

Blind Search Breadth First Search Whereas depth-first search is a policy for quickly penetrating as deeply as possible, its cautious partner breadth-first search can be likened to a wave propagating through the search space at equal speed in all directions. The memory cost of maintaining the wave front is significant, since all states in the front must be stored in their entirety.

Blind Search Breadth First Search Very systematic If there is a solution breadth first search is guaranteed to find it If there are several solutions then breadth first search will always find the shallowest goal state first and if the cost of a solution is a non-decreasing function of the depth then it will always find the cheapest solution

Blind Search Breadth First Search Evaluating against four criteria Optimal Complete Time complexity Space complexity

Blind Search Breadth First Search Evaluating against four criteria Optimal yes Complete yes Time complexity b + b 2 + b 3 +... + b d-1 i.e. O(b d ) Space complexity b + b 2 + b 3 +... + b d-1 i.e. O(b d ) b: the branching factor d: is the depth of the search tree Note : The space/time complexity could be less as the solution may be found somewhere before the d th level (depends on the problem).

Blind Search Breadth First Search Exponential growth quickly makes complete state space searches unrealistic If the branch factor was 10, by level 5 we would need to search 100,000 nodes, i.e. 10 5

Blind Search Breadth First Search Space is more of a factor to breadth first search than time Time is still an issue Who has 35 years to wait for an answer to a level 12 problem (or even 128 days to a level 10 problem) It could be argued that as technology gets faster then exponential growth will not be a problem But even if technology is 100 times faster we would still have to wait 35 years for a level 14 problem and what if we hit a level 15 problem!

Blind Search Breadth First Search Is BFS (or DFS later) a better option for - Maze - TSP - n-queen - 8-puzzle -

Blind Search Depth First Search Depth-first search (DFS) is the prime candidate. It s simple logic: keep going as long as you see anything new, and when that is not possible, back up as far as necessary and proceed in a new direction. Expand Root Node First Explore one branch of the tree before exploring another branch

Blind Search Depth First Search Expand Root Node First Explore one branch of the tree before exploring another branch

Blind Search Depth First Search Evaluating DFS by four criteria Space complexity Only needs to store the path from the root to the leaf node as well as the unexpanded nodes For a state space with a branching factor of b and a maximum depth of m, DFS requires storage of bm nodes Time complexity b m in the worst case

Blind Search Depth First Search Evaluating DFS by four criteria If DFS goes down a infinite branch it will not terminate if it does not find a goal state If it does find a solution there may be a better solution at a lower level in the tree Therefore, depth first search is neither complete nor optimal

Blind Search Uniform Cost Search (vs. BFS) BFS will find the optimal (shallowest) solution as long as the cost is a function of the depth Suppose that we have a tree in which all the weights of branches are one Weight of a path from the root to a node N is just the depth of node N

Blind Search Uniform Cost Search (vs. BFS) Uniform Cost Search can be used when this is not the case will find the cheapest solution provided that the cost of the path never decreases as we proceed along the path Uniform Cost Search works by expanding the lowest cost node on the fringe (leaf)

Blind Search Uniform Cost Search (vs. BFS) Cost of a node n the total cost of the path from the root to n Search all nodes of cost c before those of cost c+1 In BFS deeper nodes always arrive after shallower nodes In UCS the costs of new nodes do not have such a nice pattern

Blind Search Uniform Cost Search (vs. BFS) In UCS we need to 1.explicitly store the cost g of a node 2.explicitly use such costs in deciding the ordering in the queue Always remove the smallest cost node first sort the queue in increasing order alternatively, search the queue and remove the smallest cost Nodes removed by cost, not by order of arrival

Blind Search Uniform Cost Search (vs. BFS) A 1 10 S 5 B 5 15 5 C G BFS will find the path SAG, with a cost of 11, but SBG is cheaper with a cost of 10 UCS will find the cheaper solution (SBG). It will find SAG but will not see it as it has a higher cost so won t be explored

Blind Search Uniform Cost Search (vs. BFS) Completeness: If there is a path to a goal then UCS will find it If there is no path, then UCS will eventually report that the goal is unreachable Optimality: UCS will report a minimum cost path (there might be many)

Blind Search Uniform Cost Search (vs. BFS) Breadth First Search Optimal Only if the branch cost is the same Uniform Cost Search Optimal Even if the branch cost is different Complete Systematic search throughout the whole tree

Blind Search Uniform Cost Search (vs. BFS) Time and space complexity O(b d ) (bounded by b d ) UCS is usually better than BFS UCS = BFS When all solutions rather than just one solution is needed When all branches have the same cost

Blind Search Depth Limited Search DFS may never terminate as it could follow a path that has no solution on it DLS solves this by imposing a depth limit, at which point the search terminates at that particular branch Can be implemented by the general search algorithm using operators which keep track of the depth Choice of depth parameter is important Too deep is wasteful of time and space Too shallow and we may never reach a goal state

Blind Search Completeness Depth Limited Search If the depth parameter, l, is set deep enough then we are guaranteed to find a solution if one exists Therefore it is complete if l>=d (d=depth of solution) Space requirements O(bl) Time requirements O(b l ) DLS is not optimal

Blind Search Depth Limited Search Odarea Map of Romania Neamt Zerind Iasi Arad Sibiu Fararas Vaslui Timisoara Lugoj Rimnicu Vilcea Pitesti Urziceni Hirsova Mehadia Bucharest Dobreta Craiova On the Romania map there are 20 towns so any town is reachable in 19 steps Giurgui G51IAI Blind Searches Eforie In fact, any town is reachable in 10 steps

Heuristic Search Techniques Do you drive? Have you thought about how the route plan is created for you in your TomTom? How do you find the sequence of moves in 8-puzzle with the minimum number of steps?

Heuristic Search Techniques Do you drive? How does your GPS create the shortest (or the quickest) route between A and B for you? A* search

Heuristic Search Techniques The general search methods discussed do not make use of domain knowledge and are considered as weak methods simply because they do not exploit such knowledge. In order to solve many problems efficiently it is often necessary to construct a control structure that is no longer guaranteed to find the best answer, but will almost always find a very good answer. thus we introduce the idea of an heuristic.

Heuristic Methods Heuristics Heuristic : A technique which improves the efficiency of a search process, possibly by sacrificing claims of completeness. Heuristics are key terms in many branches of AI. A heuristic is best defined as a 'rule of thumb' or piece of advice that is usually based on prior experience and not guaranteed to work.

Heuristic Methods Heuristics A moment's reflection will show ourselves constantly using heuristics in the course of our everyday lives. If the sky is grey we conclude that it would be better to put on a coat before going out. We book our holidays in August because that is when the weather is best.

Heuristic Search A search algorithm to find the shortest path through a search space to a goal state using a heuristic. f = g + h f - function that gives an evaluation of the state g - the cost of getting from the initial state to the current state h - the cost of getting from the current state to a goal state

Heuristic Search Heuristic searches vs. Uniform Cost Search Uniform cost search expand the path with the lowest path cost chooses the lowest cost node thus far Heuristic search estimate how close the solution is to the goal not how cheap the solution is thus far

Heuristic Search Heuristic searches vs. Uniform Cost Search Uniform Cost Search path cost function g(n): the cost of the path thus far Heuristic searches evaluation function h(n): how close is the current node to the solution

The A* Search Heuristic A search algorithm to find the shortest path through a search space to a goal state using a heuristic. f = g + h f - function that gives an evaluation of the state g - the cost of getting from the initial state to the current state h - the cost of getting from the current state to a goal state

The A* Search Heuristic A search algorithm to find the shortest path through a search space to a goal state using a heuristic. f = g + h Combines the cost so far and the estimated cost to the goal That is f(n) = g(n) + h(n) This gives us an estimated cost of the cheapest solution through n

The A* Search Heuristic A search algorithm to find the shortest path through a search space to a goal state using a heuristic. f = g + h We need to have a proper way to estimate h outline of graph goal start g A B A h A h B g B

The A* Search Heuristic A search algorithm to find the shortest path through a search space to a goal state using a heuristic. f = g + h h=0 A* becomes UCS complete & optimal but search pattern undirected h too large if h is large enough to dominate g then becomes like Greedy, lose optimality

Nodes Expanded ANIMATION OF A*. 1.Sibiu 2.Rimnicu 3.Pitesti 4.Fagaras 5.Bucharest 278 GOAL!! Zerind Arad 118 111 75 Timisoara 70 71 Lugoj 75 140 Mehadia Dobreta 120 Oradea 140+366=506 0+253=253 Sibiu 99 80 80+193=273 Rimnicu 146 Annotations: g+h=f 97 177+98=275 Pitesti 138 99+178=277 Fagaras 101 Fringe in RED Visited in BLUE 211 226+160=386(R) 90 Craiova 315+160=475(R, P) Giurgui 86 Neamt 87 Optimal route is (80+97+101) = 278 miles Why not 211? Urziceni Bucharest 310+0=310 (F) 278+0=278 (R,P) 98 Iasi 92 Vaslui 142 Hirsova 86 Eforie

Zerind 71 Oradea Neamt 87 Iasi Zerind 71 Oradea Neamt 87 Iasi 75 Arad Optimal route is (80+97+101) = 278 miles 140 118 Timisoara Sibiu 99 Faragas 111 80 Lugoj Rimnicu 211 Urziceni 70 97 86 Pitesti Mehadia 146 101 75 138 Bucharest Dobreta 90 98 92 Vaslui 142 Hirsova 86 75 Arad 118 Timisoara 111 Lugoj 70 Mehadia 75 Dobreta Optimal route is (80+97+101) = 278 miles 140 Sibiu 99 80 Rimnicu 97 Fagaras 211 98 Urziceni 86 Pitesti 146 101 Bucharest 138 90 92 Vaslui 142 Hirsova 86 120 Craiova Giurgui Eforie 120 Craiova Giurgui Eforie UCS A* Nodes expanded: 1.Sibiu; 2.Rimnicu; 3.Faragas; 4.Arad; 5.Pitesti; 6.Zerind; 7.Craiova; 8.Timisoara; 9.Bucharest 278 Nodes Expanded: 1.Sibiu; 2.Rimnicu; 3.Pitesti; 4.Fagaras; 5.Bucharest 278

The A* Search Heuristic Clearly the expansion of the fringe is much more directed towards the goal The number of expansions is significantly reduced A* is optimal and complete, but it is not all good news It can be shown that the number of nodes that are searched is still exponential to the size of most problems This has implications not only for the time taken to perform the search but also the space required Of these two problems the space complexity is more serious

The A* Search Heuristic If you examine the animation on the previous slide you will notice an interesting phenomenon Along any path from the root, the f-cost never decreases This is no accident It holds true for all admissible heuristics

The A* Search Heuristic 8 puzzle problem Initial State Goal State 1 3 4 1 2 3 8 6 2 8 4 7 5 7 6 5 Online demo of A* algorithm for 8 puzzle Noyes Chapman s 15 puzzle

The A* Search Heuristic Possible Heuristics in A* Algorithm H 1 H 2 = the number of tiles that are in the wrong position = the sum of the distances of the tiles from their goal positions using the Manhattan Distance We need admissible heuristics (never over estimate) Both are admissible but which one is better?

The A* Search Heuristic Possible Heuristics in A* Algorithm H 1 H 2 = the number of tiles that are in the wrong position (=4) = the sum of the distances of the tiles from their goal positions using the Manhattan Distance (=5) 1 3 4 1 2 3 8 6 2 8 4 7 5 7 6 5

The A* Search Heuristic Possible Heuristics in A* Algorithm 1 3 4 8 6 2 7 5 5 1 3 4 8 6 2 7 5 4 1 3 4 8 2 7 6 5 4 1 3 4 6 1 3 4 8 6 2 7 5 8 6 2 7 5 6 1 3 4 8 6 2 7 5 5 1 3 4 1 3 4 3 8 2 8 6 2 7 6 5 7 5 6 H 1 = the number of tiles that are in the wrong position (=4) H 2 = the sum of the distances G51IAI of the - Heuristic tiles from their goal positions using the Manhattan Distance (=5)

The A* Search Heuristic 1 3 4 Possible Heuristics 8 6 in 2 A* Algorithm 7 5 5 1 3 4 8 2 7 6 5 4 1 3 4 6 1 3 4 8 6 2 7 5 8 6 2 7 5 6 1 4 8 3 2 7 6 5 5 1 3 4 5 1 3 4 8 2 7 6 5 8 2 7 6 5 3 1 3 8 2 4 7 6 5 2 1 3 4 8 2 5 7 6 4 1 3 8 2 4 7 6 5 1 H 2 = the sum of the distances of the tiles from their goal positions using the Manhattan Distance (=5)

The A* Search Heuristic 1 3 4 8 6 2 7 5 Possible Heuristics in A* Algorithm 4 1 3 4 8 2 7 6 5 3 1 3 4 5 1 3 4 8 6 2 7 5 8 6 2 7 5 5 1 4 8 3 2 7 6 5 3 1 3 4 4 1 3 4 8 2 7 6 5 8 2 7 6 5 3 1 4 8 3 2 7 6 5 4 1 4 8 3 2 7 6 5 3 1 4 2 8 3 7 6 5 3 H 1 = the number of tiles that are in the wrong position (=4)

The A* Search Heuristic

The A* Search Heuristic A 8 B 9 C 6 D 4 E 5 F 2 G 0 D 3 3 A C 2 1 2 2 B 4 Distance to destination 5 4 3 E Start Point: A Goal Point: G G 2 F Distance Between Cities

The A* Search Heuristic A 8 B 9 C 6 D 4 E 5 F 2 G 0 D 3 3 A C 2 1 2 2 B 4 Distance to destination 5 4 3 E Travel From City A to City C Distance travelled (g) = 2 miles Distance still to go (h) = 6 miles G 2 F Value of Current State (f) = g + h = 8 Distance Between Cities

The Game of Nim In this game there are initially 9 tokens and two players take it in turns to remove 1, or 2, or 3 tokens at a time. The player who has to remove the last token is the loser.

Minmax Algorithm Generate and Test Remember that the algorithm aims for the computer to win the game. The computer needs to assess each possible move before actually making a move. This can be done by giving each node a value, a big value to any nodes are is good for the computer and a small value to the node that is bad for it. Once the values for the leaf nodes (those at the bottom of the tree) are known we know the computer will try to move to the nodes with big values and the opponent naturally will try to move to the nodes with small values.

Minmax Algorithm Generate and Test Following this logic we can back the values of the leaf nodes up according to whose turn it is to move: if it is the computer s move, the maximum value is backed up and if it is the opponent s move the minimum value is backed up. Once all the nodes have been assigned a value, the computer player is now able to play the perfect game. At each node it just moves to the next node that has the highest value.

The Game of Nim Player MIN Computer MAX Player MIN Computer MAX 9 8 1 7 1 6 1 7-1 6-1 5 1 4-1 3-1 6 1 5-1 4 1 3 1 2 1 1-1 Player MIN 5 1 4-1 3-1 2-1 1 1 Computer MAX 4 1 3 1 2 1 1-1 Player 3 2 1 MIN -1-1 Computer MAX 2 1 1-1 Player MIN 1 1 1

Concluding Search space (state space) Search tree Search methods Depth-, breath- first search Depth limited search Uniform cost search A* algorithm Minmax Combinatorial explosion Heuristics Untenable states