Docsity

Gambler's Ruin Assignment for CS 416 Artificial Intelligence - Prof. David Brogan, Assignments of Computer Science

Toggle sidebar
bg1
Assignment: Gambler's Ruin
CS 416 Artificial Intelligence
Spring 2003
Due: 5:00 Thursday, April 24th
A gambler1 has the opportunity to make bets on the outcomes of a sequence of coin flips. If the
coin comes up heads, then he wins as many dollars as he has staked on that flip, but if it is tails
then he loses his stake. The game ends when the gambler wins by reaching his goal of 100
dollars, or loses by running out of money. On each flip, the gambler must decide what portion of
his capital to stake, in integer numbers of dollars. This problem can be formulated as a MDP.
The state is the gambler's capital, }99...,,2,1{
∈
s, and the actions are stakes,
. The reward is zero on all transitions except those on which the
gambler reaches his goal, when it is +1. The state-value function then gives the probability of
winning from each state. A policy is a mapping from levels of capital to stakes. The optimal policy
maximizes the probability of reaching the goal. Let p denote the probability of the coin coming up
heads. If p is known, then the entire problem is known and it can be solved, e.g., by value
iteration. Figure 1 shows the change in the value function over successive sweeps of value
iteration, and the final policy found, for the case of p = 0.4.
)}100,min(...,,1,0{ ssa −∈
Figure 1: The solution to the gamblers problem for p = 0.4. The upper graph shows the value
function found by successive sweeps of value iteration. The lower graph shows the final policy.
1 Problem excerpted from Reinforcement Learning by Sutton and Barto
pf3
pf4

Partial preview of the text

Download Gambler's Ruin Assignment for CS 416 Artificial Intelligence - Prof. David Brogan and more Assignments Computer Science in PDF only on Docsity!

Assignment: Gambler's Ruin

CS 416 Artificial Intelligence

Spring 2003

Due: 5:00 Thursday, April 24th

A gambler^1 has the opportunity to make bets on the outcomes of a sequence of coin flips. If the coin comes up heads, then he wins as many dollars as he has staked on that flip, but if it is tails then he loses his stake. The game ends when the gambler wins by reaching his goal of 100 dollars, or loses by running out of money. On each flip, the gambler must decide what portion of his capital to stake, in integer numbers of dollars. This problem can be formulated as a MDP.

The state is the gambler's capital, s ∈{ 1 , 2 ,..., 99 }, and the actions are stakes,

. The reward is zero on all transitions except those on which the

gambler reaches his goal, when it is +1. The state-value function then gives the probability of winning from each state. A policy is a mapping from levels of capital to stakes. The optimal policy maximizes the probability of reaching the goal. Let p denote the probability of the coin coming up heads. If p is known, then the entire problem is known and it can be solved, e.g., by value iteration. Figure 1 shows the change in the value function over successive sweeps of value iteration, and the final policy found, for the case of p = 0..

a ∈{ 0 , 1 ,...,min( s , 100 − s )}

Figure 1: The solution to the gamblers problem for p = 0.4. The upper graph shows the value function found by successive sweeps of value iteration. The lower graph shows the final policy.

(^1) Problem excerpted from Reinforcement Learning by Sutton and Barto

Exercise 1: Why does the optimal policy for the gambler's problem have such a curious form? In particular, for capital of 50 it bets it all on one flip, but for capital of 51 it does not. Why is this a good policy?

Exercise 2: Implement value iteration for the gambler's problem and solve it for p = 0.25 and p = 0.55. In programming, you may find it convenient to introduce two dummy states corresponding to termination with capital of 0 and 100 dollars, giving them values of 0 and 1 respectively. Show your results graphically as in Figure 1. Does γ influence your rate of convergence (monitor the number of iterations before your algorithm terminates)?

Feedback

As with any assignment, we cannot foresee all possible sources of confusion. E-mail [email protected] with any questions or comments about the assignment. However, in general such e-mails will not be answered directly. Rather, this section of this document will be updated to reflect those questions or comments worth addressing (i.e., those not addressing problems specific to a student’s particular block of code, etc.), so check back before e-mailing us to make sure you issue has not already been addressed.

± Is there a reward for each state? ³ The reward for every state except the final state is zero. ± How is the program to receive input? ³ The program should take a single float as a command line argument. That float represents p, the probability of getting heads on a single coin flip. ± What should the program output, and in what format? ³ The output should be to stdout and should contain two lines. The first line should contain 99 floats, separated by spaces, where the first float corresponds to the value estimate for having capital=1, etc. The second line should contain 99 integers, separated by spaces, where the first integer corresponds to the policy (i.e., how much to stake) for having capital=1, etc. Part of your submission includes graphs generated from this output data. You can use the program of your choice (e.g., Excel, MatLab, GIMP) to create these graphs. ± How close to the "true" utility should we be before terminating the search? ³ Continue until the utilities no longer change from time step to time step, or if that is taking too long, choose an epsilon (e.g., 10-7) such that if no change in utility exceeds epsilon the program will halt. You should mention in your README file which option you choose. ± What gamma should we use for the graphs we submit? ³ Use gamma = 0.999999. (1-10-6)

Late Days

Students have five late days to use during the semester. Each late day provides a 24-hour extension.

Honor

Do not use the web to acquire any information related to the algorithmic portion of this assignment. All necessary information can be found in the textbook. You may use the web to look up programming questions, graphing software, tomorrow’s weather, etc. Let the instructor or TA know if you have particular questions. Also, do not consult with others in the class about the nature of their solutions or their algorithms. Unlike the first assignment, you cannot communicate with others in the class about your work. This is a small assignment and the assistance granted by the TA and the instructor will be carefully allocated to avoid simplifying things too much.