Skip to content

Commit

Permalink
stochastic_control: include qmax in trading example; allow variable a…
Browse files Browse the repository at this point in the history
…lpha
  • Loading branch information
jflatow committed May 10, 2013
1 parent 9098fcc commit 2f95ea7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions stochastic_control/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def cost(self, t, n, k, n_):
return self.tests[k][2]
return self.tests[k][2] + self.r * min(n_, self.N - n_)

def plot(policy, T=0):
def plot(policy, T=0, alpha=.1):
import mpl_toolkits.mplot3d
import pylab
f = pylab.figure()
o = policy[T]
a = f.add_subplot(111, projection='3d')
a.scatter([n for n in o], [u for v, u in o.values()], [v for v, u in o.values()], alpha=.1)
a.scatter([n for n in o], [u for v, u in o.values()], [v for v, u in o.values()], alpha=alpha)
a.set_title('T = %s' % T)
a.set_xlabel('State')
a.set_ylabel('Test')
Expand Down
2 changes: 1 addition & 1 deletion stochastic_control/trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def transition(n):
return {n + 1: a, n - 1: b, n: 1 - a - b}
prices = self.prices = dict((n, (1 + gamma) ** n) for n in range(-N, N + 1))
ptrans = self.ptrans = dict((n, transition(n)) for n in range(-N, N + 1))
states = [(q, n) for q in range(qmin, qmax) for n in range(-N, N + 1)]
states = [(q, n) for q in range(qmin, qmax + 1) for n in range(-N, N + 1)]
self.T = T
self.X = lambda t: states
self.U = lambda t, (q, n): range(qmin - q, qmax - q + 1)
Expand Down

0 comments on commit 2f95ea7

Please sign in to comment.