瀏覽代碼

Added last two lessons of AI

Federico Amedeo Izzo 9 年之前
父節點
當前提交
a28d4da236
共有 2 個文件被更改,包括 156 次插入0 次删除
  1. 100 0
      Artificial Intelligence/lesson_06.md
  2. 56 0
      Artificial Intelligence/lesson_07.md

+ 100 - 0
Artificial Intelligence/lesson_06.md

@@ -0,0 +1,100 @@
+# AI - lesson 06
+#### 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
+
+There are different kind of games:
+- __Perfect information__ games: we completely know the status of the game
+- __Imperfect information__ games: 
+
+Another distinction is:
+- __Deterministic__ games: There are no randomness factors
+- __Chance__ games: there are elements of chance for example rolling dices or drawing cards.
+
+#### 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.
+
+For this time will focus of __Perfect information__ and __deterministic__ games like chess.
+
+- We have two players: Max and Min,  
+- They are playing in turns,
+- Max will play first
+
+An __initial state__ is an initial configuration of the game.
+
+### Tic Tac Toe
+
+Max: X
+Min: O
+
+Initial state:
+
+||
+---|---|---
+||
+||
+
+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\}$
+
+Next we define a utility function
+- $\text{UTLITY}(s,p)\in R$
+
+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$
+
+For example
+X|O|O
+---|---|---
+|X|
+||
+$\text{RESULT}$Will give __no__ as a result
+
+While
+X|O|O
+---|---|---
+|X|
+||X
+
+$\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
+
+### minimax
+
+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.
+
+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
+
+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
+
+#### 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.
+
+The minimax value can be __minimized__ building a tree in a *depth first* fashion.
+
+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__
+
+#### Cutoff strategy
+
+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 

+ 56 - 0
Artificial Intelligence/lesson_07.md

@@ -0,0 +1,56 @@
+# AI - lesson 07
+#### Francesco Arrigoni
+###### 6 November 2015
+## Adversarial games
+
+### $\alpha - \beta pruning$ 
+#### Iteration
+- We start from the root, that will be labeled after the starting player.
+- From the root the first set of arcs representing actions is called a1,a2,a3...
+- The arcs starting from a 2nd level node are named b1,b2,b3...
+- For a MIN node (e.g 2nd level) we not necessarily know the minimax value, 
+but we can tell it is lower than the values of the known children (minimum value)
+- We can have an hint about the minimax value of the root only when we have at least one branch completely built
+- After we have found the minimax value of a node, we can remove from memory his children.
+I do not need to generate the complete tree of a node if MAX has already found a node of higher value
+
+The order of the nodes determines which nodes are discovered or not
+
+#### Complexity
+
+Using the most efficient $\alpha - \beta pruning$
+We have a __time complexity__ of $O(b^{m/2})$
+With respect of classic minimax $O(b^n)$
+
+This means that with $\alpha - \beta pruning$ we can obtain a tree with __double the depth__ comparing to minimax
+
+#### Meaning of the name
+
+In the first public version of this algorithm, the current best option for MAX was called $\alpha$
+
+In a dual way $\beta$ was the value of the current best option for MIN.
+
+#### General case
+
+In a general case, known a MAX node value $\alpha$, while discovering MAX nodes of lower levels, all children with value higher than $\alpha$ are pruned.
+
+We can repeat the same reasoning for MIN and $\beta$
+
+$\alpha$ and $\beta$ are not the extremens of a node interval.
+
+## Games with chance
+
+For this games certain authors say that there are three players: MAX,MIN and Nature, but this is misleading.
+
+### Expectiminimax algorithm
+We have a similar tree to the minimax one, With chance nodes with  probability on the descending arcs.
+
+The procedure of calculating and backing up the minimax values for the normal nodes is the same as minimax.
+
+#### Alternative strategy
+
+We know that our utility function from design will return values in a given interval e.g $[-2,2]$
+
+From this we know that for every node, the minimax value will be between $[-2,2]$
+
+Expectiminimax is dependent on the __actual values__ of the utility function, while in standard minimax it does not mattes.