euro moneta

annuncio pubblicitario
TESINE PROPOSTE PER LA PARTE DI APPRENDIMENTO PER RINFORZO
1)
Il problema del “n-Armed Bandit” (Sutton, pag. 26)
n-armed bandit problem: n = 10; a = a1, a2, …, ak, …, a10.
La simulazione consiste in un set di 2000 task.
Per ogni task, eseguo 1000 volte la scelta dell’azione:
t = t1, t2, …, t1000
a = a(t1), a(t2), …, a(t1000)
r = r(a(t1)), r(a(t2)), …, r(a(t1000))
r(ak) viene selezionato in modo random da una distribuzione Gaussiana con media µk, diversa per le
diverse azioni, ma costante per tutto il task, e varianza 1. µk = Q*(ak).
Misuro, per ogni istante di tempo t:
Il reward dell’azione (in questo caso viene dato un reward  0 per ogni azione)
Calcolo la ricompensa totale (Value Function).
Valuto la performance dopo le 1000 giocate di ogni task.
Quanto vale µk? Per ogni task vario µk estraendolo da una distribuzione Gaussiana con media = 0 e
varianza = 1.
2)
Recycling Robot (Sutton pag. 55)
Con alcune semplificazioni, il robot raccoglitore può essere modellato come Markov decision
process, ovvero MDP.
Stato: S = {high, low}
Azioni: A = {wait, search, recharge}
Policy:
A(high) = {wait, search}
A(low) = {wait, search, recharge}
Goal: collezionare il maggior numero di lattine.
Funzione stato prossimo:
Ps→s’|a= Pr{st+1 = s’|st = s, at = a}
Se il livello di energia è high (st = high):
se scelgo Wait, st+1 = high.
se scelgo Search, st+1 avrà una certa probabilità di diventare low.
Phigh→low|Search= Pr{st+1 = low|st = high, at = Search} = α
Se il livello di energia è low (st = low):
se scelgo Wait, st+1 = low.
se scelgo Recharge, st+1 = high.
se scelgo Search, st+1 avrà una certa probabilità di fermarsi.
Plow→low|Search= Pr{st+1 = low|st = low, at = Search} = 
Funzione Reward:
Rs→s’|a= E{rt+1 = r’|st = s, at = a, st+1 = s’}
Rsearch reward se il robot sta cercando.
Rwait reward se il robot sta fermo.
-3 se occorre portarlo a ricaricarsi
0 se il robot va autonomamente a ricaricarsi
NB: Rsearch > Rwait
Il comportamento dinamico del robot raccoglitore può essere rappresentato dal seguente transition
graph:
In modo più analitico, si possono tabellare le probabilità di transizione e i rewards attesi come nella
figura che segue:
Esempio:
  0.4,   0.1,   0.8, R search  3, R wait  1
3)
Jack’s Car Rental (Sutton pag. 98)
Jack gestisce due locazioni di autonoleggio per conto di una compagnia nazionale.
In ogni locazione, se quando arriva un cliente l’auto è disponibile, Jack guadagna 10 Euro.
Se l’auto non è disponibile, perde l’affare. Le auto diventano disponibili il giorno dopo che sono
state restituite dopo il noleggio.
Jack può muovere di notte le auto da un sito all’altro al costo di 2 Euro per auto.
Assumiamo che il numero di auto richieste e restituite in ognuno dei due autonoleggi sia
rappresentato da una distribuzione di Poisson: la probabilità che vengano richieste n auto è (n/n!)e, dove  è il valore atteso (media) di auto richieste o restituite.
In particolare si assume  pari a 3 e 4 per le richieste di noleggio nella prima e seconda locazione, e
3 e 2 per la restituzione.
Supponiamo che non ci possono essere più di 20 auto in uno dei due autonoleggi (le auto in più
vengono inviate al centro di raccolta nazionale della compagnia).
Supponiamo anche che il numero di auto che si possono spostare per notte sia di 5.
Questo problema si può formulare con un MDP dove lo stato è rappresentato dal numero di auto
presenti in ciascuno dei due autonoleggi al termine di una giornata e le azioni il numero di auto che
vengono spostate durante la notte.
Considerare  = 0.9. Il reward sarà il reward accumulato durante il giorno + notte.
Si parta dalla policy (s,a) = 0: nessuna auto viene mossa. Applicare la “Policy Iteration”.
4)
Gambler’s Problem (Sutton pag.101)
Consideriamo uno scommettitore che scommette su testa o croce.
Se esce testa, vince tanti euro quanti ne ha scommesso. Se esce croce, perde gli euro che ha
scommesso.
Il gioco termina quando lo scommettitore arriva ad accumulare 100 euro o perde tutto il suo
capitale.
Il suo capitale di partenza è variabile tra 1 e 99 euro. Ad ogni lancio della moneta, lo scommettitore
può decidere quanto scommettere sul fatto che esca testa.
Undiscounted, episodic, finite MDP.
Lo stato è il capitale accumulato dal giocatore: s = {1, 2,…,99}.
L’azione è quanto viene scommesso ad ogni lancio: a = {1, 2,…,min(s, 100-s)}.
La ricompensa è zero per tutte le transizione eccetto quella per cui lo scommettitore raggiunge il
goal, cioè i 100 euro, in qual caso è +1.
Una state-value function allora dà la probabilità di vincere da ciascun stato.
Una policy è un mapping tra i livelli di capitale e le scommesse.
La policy ottima massimizza la probabilità di raggiungere il goal.
Conosciamo la probabilità p con cui esce testa (la moneta può essere truccata e quindi le due
condizioni testa/croce possono non essere equiprobabili).
La dinamica dell’ambiente non dipende da a ed è rappresentata dalla transizione da uno stato
all’altro che a sua volta è funzione del fatto che esca testa o meno.
Vogliamo massimizzare la probabilità di vincere (supponiamo p=0.4). Si può fare tramite la Value
Iteration.
Provare con diversi valori di p (es.: 0.4, 0.5, 0.6)
5)
Windy Gridworld (Sutton pag. 146)
Sia data una gridworld standard come nella figura seguente, con uno stato start S ed uno goal G, ma
con una differenza: nella parte centrale della griglia c’è vento.
Le azioni sono le solite, {up, down, right, left}, ma nella regione centrale gli stati prossimi risultanti
sono traslati in su da un vento la cui forza varia da colonna a colonna.
La forza del vento è fornita sotto ciascuna colonna, come numero di celle di traslazione in su.
Per esempio, se si è nella cella a destra del goal, l’azione left ci porta nella cella appena sopra il
goal.
Trattare questo caso come undiscounted episodic task, con rewards costanti di -1 finché non si
raggiunge il goal.
Si può applicare a questo task l’algoritmo Sarsa -greedy, con  = 0.1 e α = 0.1, e con i valori Q(s,
a) = 0 per tutti gli s, a.
6)
Playing cat and mouse (Robert Schapire's formulation)
The assignment is to use your code to compute optimal policies for a mouse who lives with a cat in
the following grid world:
The mouse (M) can occupy any of the 31 blank squares. The cat (C) also can occupy any square,
except for square (6,1) which is the mouse's hole (too small for the cat to squeeze in). There is
cheese (z) in squares (2,3) and (7,3) that never moves. Thus, this MDP has 31*30=930 states.
The cat and the mouse can each move one square in any direction -- vertically, horizontally or
diagonally. They also can choose not to move at all. Thus, there are nine possible moves from each
square. If an action is attempted that causes the creature to bump into a wall, then it simply stays
where it is.
In this problem, we will always take the point of view of the mouse. When the mouse is on the
cheese, it receives a reward of 1. When the cat is on the mouse, it (the mouse) receives a reward of
-11. When the cat is on the mouse, and the mouse is on the cheese, the reward is -10. All other
configurations have a reward of 0. Thus, the mouse is trying to eat cheese while simultaneously
avoiding the cat.
We will consider three different cats. The first cat, poor thing, is blind and oblivious, and simply
wanders randomly around its environment choosing randomly among its nine available actions at
every step. The second cat is hungry, alert and unrelenting. This cat always heads straight for the
mouse following the shortest path possible. Thus, after the mouse makes its move, the cat chooses
the action that will move it as close as possible to the mouse's new position. (If there is a tie among
the cat's best available options, the cat chooses randomly among these equally good best actions.)
However, when the mouse is in its hole and out of sight, the cat reverts to aimless (i.e., random)
wandering. The third cat is also alert, but has a more sporting disposition, and therefore follows a
combination of these two strategies: half the time, it wanders aimlessly, and half the time, it heads
straight for the mouse.
States are encoded as four tuples, the first two numbers indicating the position of the mouse, and the
second two numbers the position of the cat. Thus, 2:2:5:2 indicates that the mouse is in (2,2) and
the cat is in (5,2). The cat and the mouse alternate moves. However, in encoding the MDP, we
collapse both moves into a single state transition. For instance, from the configuration above, if the
mouse moves to (3,1) and the cat responds by moving to (4,1), this would be encoded as a single
transition from state 2:2:5:2 to 3:1:4:1. Actions in the MDP refer to action's that the mouse can
make; the cat's actions are effectively "hard-wired" into the dynamics of the MDP itself.
For each of the three cats, your job will be to compute the mouse's optimal policy, i.e., the action
that should be taken at each state to maximize the mouse's expected discounted reward, where we
fix the discount factor (gamma) to be 0.95. You can then watch the cat and the mouse go at it using
a primitive animator that we are providing.
Exploring optimal behavior
Once you have everything working, you should take some time to understand the mouse's behavior
in each of the three cases. Then briefly write up your observations in 2-4 paragraphs (all together,
not per case). You can make observations that are either anecdotal or quantitative or both. Think
about questions like the following: How is the mouse behaving in each case and why does this
behavior make sense? Is it what you would have expected, or are there aspects of the mouse's
behavior that you found surprising? What happens if you take the mouse's optimal policy for cat A
and have the mouse follow that policy when playing against cat B? Since there are three cats, there
are nine possibilities here. Construct a matrix showing the utility (say, averaged over all possible
starting states), for all nine possibilities. Which policy should the mouse follow if it doesn't know
which cat it's up against? Why? You may also wish to explore the performance of the algorithms
themselves. For instance, how many iterations does it take to reach convergence?
7)
General Cat and Mouse (n x n grid):
There are several solid obstacles, several stationary pieces of cheese, one mouse hole and a nonstationary cat. The cat moves (after the mouse moves) to minimize its distance to the mouse,
choosing randomly between equal quality moves. The cat cannot see or move to the mouse if it is
hiding in its hole. Each map is randomly generated (on init) at the beginning of each trial, but does
not change between consecutive episodes. The agent gets a small positive reward for each step that
the mouse occupies the same grid space as a piece of cheese and a large negative reward if the cat
and mouse occupy the same grid space. An episode ends when the cat catches the mouse. The
agent's objective is to navigate the mouse through the maze, collecting as much cheese as possible
while avoiding the cat.
This is a generalization of Robert Schapire's formulation.
Episodic task
Action Space:
mouse movement
a ∈ [0,7]
|a| = 8
Observation Space:
mouse's position and cat's position and if mouse is in hole
[mp, cp, flag] where each {mp,cp}∈ [0, n*n -1 and flag ∈ [0,1]
Reward:
if [{mp} == {cheese position}] then +5
if [{cp} == {mp}] then -100
0 otherwise
Performance measure:
cumulative reward
Rmax = +5
Rmin = -100
8)
Blackjack (Sutton, pag.112)
È il gioco di carte popolare dei Casinò. L’obiettivo è ottenere carte la cui somma dei valori è più
grande possibile ma non eccede 21. Tutte le figure valgono 10, e l’asso può valere o 1 o 11. Si
consideri la versione in cui ciascun giocatore compete indipendentemente contro chi fa le carte
(tiene banco). Il gioco inizia con due carte date sia al giocatore sia a chi tiene banco.Una delle carte
di chi tiene banco è coperta l’altra è scoperta. Se il giocatore ha immediatamente 21 (un asso e una
figura), è chiamato un natural. Egli ha vinto a meno che chi distribuisce le carte non abbia anche lui
un natural, in qual caso è patta. Se il giocatore non ha un natural, può chiedere altre carte, una alla
volta (hits), finché non si ferma (sticks) o supera 21 (goes bust). Se va fuori, ha perso. Se si ferma,
allora è il turno di chi tiene banco. Questi tira o si ferma secondo una strategia fissa, senza scelta: si
ferma per una somma pari o superiore a 17, in tutti gli altri casi tira. E chi tiene il banco va fuori,
allora il giocatore vince; negli altri casi il risultato - vincita, perdita o pareggio – è determinato da
quale somma finale è più vicina a 21.
Il gioco del blackjack può essere formulato come un MDP episodico finito. Ciascuna giocata di
blackjack è un episodio. Le ricompense (rewards) di +1, -1 e 0 sono assegnate per vincita, perdita o
pareggio. Le ricompense per tutte le altre situazioni sia 0. Non si usa lo sconto ( = 1), pertanto i
rewards terminali sono anche i Returns. Le azioni del giocatore sono hit o stick. Gli stati dipendono
dalle carte del giocatore e dalla carta scoperta di chi tiene banco. Si assuma che le carte siano
estratte da un mazzo infinito (cioè con rimpiazzo) così che non vi è alcun vantaggio a tener traccia
delle carte già uscite. Se il giocatore ha un asso che può essere contato come 11 senza scassare
(going bust), allora l’asso è detto usable. In questi casi è sempre contato come 11 perché contarlo 1
farebbe la somma 11 o meno, in qual caso non ci sarebbe nessuna decisione da prendere perché,
ovviamente, il giocatore dovrebbe tirare (hit) sempre. Pertanto il giocatore prende una decisione in
base a tre elementi (tre variabili): la sua somma corrente (12-21), la carta scoperta del banco (asso –
10), se ha o meno un asso usable. Questo porta ad un totale di 200 stati. Si consideri la policy in cui
il giocatore si ferma (stick) se la somma delle carte è 20 o 21, tira (chiede carta) altrimenti. Qual è la
state-value function? Dopo averla plottata, che interpretazione darle?
Scarica