|
@@ -1,100 +1,74 @@
|
|
# AI - lesson 06
|
|
# AI - lesson 06
|
|
#### Francesco Arrigoni
|
|
#### Francesco Arrigoni
|
|
-###### 4 November 2015
|
|
|
|
-## Adversarial search
|
|
|
|
-Is usually employed in situations called *games*, in which there are multiple agents that interact together in a __strategic way__
|
|
|
|
-For example in the game of chess we play against another player, and so our moves can be represented by a tree
|
|
|
|
|
|
+###### 28 October 2015
|
|
|
|
+## Informed search strategies
|
|
|
|
|
|
-There are different kind of games:
|
|
|
|
-- __Perfect information__ games: we completely know the status of the game
|
|
|
|
-- __Imperfect information__ games:
|
|
|
|
|
|
+### Evaluation function $f(n)$ types
|
|
|
|
|
|
-Another distinction is:
|
|
|
|
-- __Deterministic__ games: There are no randomness factors
|
|
|
|
-- __Chance__ games: there are elements of chance for example rolling dices or drawing cards.
|
|
|
|
|
|
+### Greedy best first
|
|
|
|
+$$f(n)=h(n)$$
|
|
|
|
+$h(n)$ is called *heuristic function* and is an estimate of __how far__ is a node __from the goal__
|
|
|
|
|
|
-#### examples
|
|
|
|
-- An example of perfect information and deterministic game is chess,
|
|
|
|
-- An imperfect and deterministic game is battleship
|
|
|
|
-- A perfect information based on chance is backgammon, or gioco dell'oca, or Monopoly
|
|
|
|
-- An imperfect information and chance game is poker or cards games.
|
|
|
|
|
|
+#### example
|
|
|
|
+- The nodes of the graph are __cities__ and the heuristic function can be the cartesian distance of the cities
|
|
|
|
|
|
-For this time will focus of __Perfect information__ and __deterministic__ games like chess.
|
|
|
|
|
|
+- In the game of 15 an heuristic can be an estimate of the number of moves needed to complete the game
|
|
|
|
|
|
-- We have two players: Max and Min,
|
|
|
|
-- They are playing in turns,
|
|
|
|
-- Max will play first
|
|
|
|
|
|
+By definition the heuristic function is defined over __nodes__, but commonly are defined over a __state__, in fact
|
|
|
|
+the heuristic function of two nodes referring to the same node is the same.
|
|
|
|
|
|
-An __initial state__ is an initial configuration of the game.
|
|
|
|
|
|
+According to how heuristic functions are defines, there can be loops in __greedy best first__
|
|
|
|
|
|
-### Tic Tac Toe
|
|
|
|
|
|
+#### Optimality
|
|
|
|
|
|
-Max: X
|
|
|
|
-Min: O
|
|
|
|
|
|
+This strategy is __not optimal__ in general
|
|
|
|
|
|
-Initial state:
|
|
|
|
|
|
+#### Complexity
|
|
|
|
|
|
-||
|
|
|
|
----|---|---
|
|
|
|
-||
|
|
|
|
-||
|
|
|
|
|
|
+Setting a not clever heuristic function, this strategy is equivalent to the depht first
|
|
|
|
+But with a good heuristic function, we can exploit this to achieve better results.
|
|
|
|
+__time__:$O(b^m)$
|
|
|
|
+__space__:$O(b^n)$
|
|
|
|
|
|
-We can define a __function "player(s)" that given a state will return which is the next player
|
|
|
|
-- $\text{PLAYER}(s)\in \{max,min\}$
|
|
|
|
-- $\text{ACTIONS}(s)= \{a_1,a_2,...\}$
|
|
|
|
-- $\text{RESULT}(s,a)=s'$
|
|
|
|
-- $\text{TERMINAL-TEST}(s)=\{yes,no\}$
|
|
|
|
|
|
+### $A^*$
|
|
|
|
|
|
-Next we define a utility function
|
|
|
|
-- $\text{UTLITY}(s,p)\in R$
|
|
|
|
|
|
+In this case the __evaluation function__ is defined as $f(n)=g(n)+h(n)$
|
|
|
|
+$g(n)$ is the cost for going from the root to node n
|
|
|
|
+$h(n)$ is an estimation of the costs for going from node n to the goal g
|
|
|
|
|
|
-We consider __zero-based__ games, in which the utility of the two players in a final state are always summing up to zero
|
|
|
|
-$\text{UTILITY}(s,\text{MAX})+\text{UTILITY}(s,\text{MIN})=0$
|
|
|
|
|
|
+Doing so $f(n)$ is the estimated cost of the solution passing through n
|
|
|
|
|
|
-For example
|
|
|
|
-X|O|O
|
|
|
|
----|---|---
|
|
|
|
-|X|
|
|
|
|
-||
|
|
|
|
-$\text{RESULT}$Will give __no__ as a result
|
|
|
|
|
|
+#### Optimality
|
|
|
|
|
|
-While
|
|
|
|
-X|O|O
|
|
|
|
----|---|---
|
|
|
|
-|X|
|
|
|
|
-||X
|
|
|
|
|
|
+$A^*$ is optimal when using __tree search__, that is when the heuristic function is *admissible*
|
|
|
|
+$h^*()$ is admissible when $\forall n\;h(n)\le h^*(n)$ The heuristic function never overestimates the cost of reaching a node.
|
|
|
|
|
|
-$\text{RESULT}$Will give __yes__ as a result
|
|
|
|
-While $\text{UTILITY(s,MAX}$Will give -1 as a result
|
|
|
|
-And $\text{UTILITY(s,MIN}$Will give +1 as a result
|
|
|
|
|
|
+Returning to the road example:
|
|
|
|
+The straight distance (line of sight) between two cities is a valid heuristic by definition, in fact the real distance
|
|
|
|
+can not be smaller than this.
|
|
|
|
|
|
-### minimax
|
|
|
|
|
|
+##### example
|
|
|
|
|
|
-Is an algorithm for solving __game trees__
|
|
|
|
-- The root is called "MAX" node because t corresponds to MAX's turn
|
|
|
|
-- All children of MAX are called MIN nodes for the same reason
|
|
|
|
-- The third row contains the __terminal nodes__, and the number associated to every node is the utility for max to be in that node.
|
|
|
|
|
|
+$$f(g_2)=g(g_2)+h(g_2)>c^*$$
|
|
|
|
+$$f(n)=g(n)+h(n)\le c^*$$
|
|
|
|
+$$f(n)\le c^*<f(g_2)$$
|
|
|
|
|
|
-The minimax algorithm is based on the idea of a __minimax value__ for each node, that represents:
|
|
|
|
-> The utility for max of being in (reaching) that node assuming that the other players will play optimally from that node to the end of the game
|
|
|
|
|
|
+An Heuristic function is __consistent__ if for every node that is a successor of n
|
|
|
|
+$$\foralln,n' h(n)\le c(n,n')+h(n')$$
|
|
|
|
|
|
-The general rule for calculating the minimax value is the following:
|
|
|
|
-- The minimax value of a __terminal node__ is the utility of MAX
|
|
|
|
-- The minimax value of a __MIN node__ is the minimum of the minimax value of the children
|
|
|
|
-- The minimax value of a __MAX node__ is the maximum of the minimax value of the children
|
|
|
|
|
|
+__Consistency__ of heuristic function implies __admissibilitu__
|
|
|
|
|
|
-#### The minimax algorithm
|
|
|
|
-- Build all the game tree
|
|
|
|
-- Starting from the bottom we have to back-up the minimax value to the upper nodes.
|
|
|
|
-- Knowing the minimax value of all the children of a node, we can calculate the value of a node.
|
|
|
|
|
|
+- $f(n) is not decreasing along every path
|
|
|
|
|
|
-The minimax value can be __minimized__ building a tree in a *depth first* fashion.
|
|
|
|
|
|
+$A^*$ will choose nodes from the frontier with value that in a non decreasing order.
|
|
|
|
|
|
-The problem of a possible *cutoff strategy* is that not completing the tree, we don't have terminal nodes, and i need an __evaluation function__
|
|
|
|
|
|
+#### Complexity
|
|
|
|
+- Time complexity $O(\square^{|h-h^*|})
|
|
|
|
|
|
-#### Cutoff strategy
|
|
|
|
|
|
+If the heuristic function is always zero, $A^*$ degerates in uniform cost.
|
|
|
|
+
|
|
|
|
+If we have a perfect heuristic function, the time complexity is constant
|
|
|
|
+$A^*$ is called __optimally efficient__, this means that given a fixed heuristic function. $A^*$ is guaranteed to expand the
|
|
|
|
+minimum number of nodes
|
|
|
|
|
|
-Usually in chess or checkers i can cut-off the tree at a given level, but i can not do so at a random level
|
|
|
|
|
|
|
|
-An option is implementing a __quiescence evaluation function__ that tells us if a certain level is stable,
|
|
|
|
-otherwise we continue
|
|
|