Pārlūkot izejas kodu

Fixed lesson number

Federico Amedeo Izzo 9 gadi atpakaļ
vecāks
revīzija
5197f4aa5a

+ 46 - 72
Artificial Intelligence/lesson_06.md

@@ -1,100 +1,74 @@
 # 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
+###### 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 

+ 78 - 34
Artificial Intelligence/lesson_07.md

@@ -1,56 +1,100 @@
 # AI - lesson 07
 #### Francesco Arrigoni
-###### 6 November 2015
-## Adversarial games
+###### 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
 
-### $\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
+There are different kind of games:
+- __Perfect information__ games: we completely know the status of the game
+- __Imperfect information__ games:
 
-The order of the nodes determines which nodes are discovered or not
+Another distinction is:
+- __Deterministic__ games: There are no randomness factors
+- __Chance__ games: there are elements of chance for example rolling dices or drawing cards.
 
-#### Complexity
+#### 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.
 
-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)$
+For this time will focus of __Perfect information__ and __deterministic__ games like chess.
 
-This means that with $\alpha - \beta pruning$ we can obtain a tree with __double the depth__ comparing to minimax
+- We have two players: Max and Min,  
+- They are playing in turns,
+- Max will play first
 
-#### Meaning of the name
+An __initial state__ is an initial configuration of the game.
 
-In the first public version of this algorithm, the current best option for MAX was called $\alpha$
+### Tic Tac Toe
 
-In a dual way $\beta$ was the value of the current best option for MIN.
+Max: X
+Min: O
 
-#### General case
+Initial state:
 
-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$
+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\}$
 
-$\alpha$ and $\beta$ are not the extremens of a node interval.
+Next we define a utility function
+- $\text{UTLITY}(s,p)\in R$
 
-## Games with chance
+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 this games certain authors say that there are three players: MAX,MIN and Nature, but this is misleading.
+For example
+X|O|O
+---|---|---
+|X|
+||
+$\text{RESULT}$Will give __no__ as a result
 
-### Expectiminimax algorithm
-We have a similar tree to the minimax one, With chance nodes with  probability on the descending arcs.
+While
+X|O|O
+---|---|---
+|X|
+||X
 
-The procedure of calculating and backing up the minimax values for the normal nodes is the same as minimax.
+$\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
 
-#### Alternative strategy
+### minimax
 
-We know that our utility function from design will return values in a given interval e.g $[-2,2]$
+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.
 
-From this we know that for every node, the minimax value will be between $[-2,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
 
-Expectiminimax is dependent on the __actual values__ of the utility function, while in standard minimax it does not mattes.
+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_08.md

@@ -0,0 +1,56 @@
+# AI - lesson 08
+#### 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.

+ 0 - 74
Artificial Intelligence/lesson_0x.md

@@ -1,74 +0,0 @@
-# AI - lesson 06
-#### Francesco Arrigoni
-###### 28 October 2015
-## Informed search strategies
-
-### Evaluation function $f(n)$ types
-
-### 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__
-
-#### example
-- The nodes of the graph are __cities__ and the heuristic function can be the cartesian distance of the cities
-
-- In the game of 15 an heuristic can be an estimate of the number of moves needed to complete the game
-
-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.
-
-According to how heuristic functions are defines, there can be loops in __greedy best first__
-
-#### Optimality
-
-This strategy is __not optimal__ in general
-
-#### 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)$
-
-### $A^*$
-
-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
-
-Doing so $f(n)$ is the estimated cost of the solution passing through n
-
-#### Optimality
-
-$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.
-
-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.
-
-##### example
-
-$$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)$$
-
-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')$$
-
-__Consistency__ of heuristic function implies __admissibilitu__
-
-- $f(n) is not decreasing along every path
-
-$A^*$ will choose nodes from the frontier with value that in a non decreasing order.
-
-#### Complexity
-- Time complexity $O(\square^{|h-h^*|})
-
-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
-
-