コード例 #1
0
ファイル: ponzi4.py プロジェクト: zsh1313/bellman
def plotF(n, aroundPoint=None, aroundN=None, colorStates=False, **kwargs):
	opt_d = bellman.getIter(n)['opt_d']
	opt_r = bellman.getIter(n)['opt_r']
	# k = d + D - M
	k_fn = lambda x: opt_d(x) + x[1] - x[0]	
	f_fn = lambda x: p_fns.testf(k_fn(x), opt_r(x))
	return plotSurface(f_fn, 'f', aroundPoint, aroundN, colorStates=colorStates, colorFn=iterColorFn(n), **kwargs)
コード例 #2
0
ファイル: ponzi4.py プロジェクト: zsh1313/bellman
def getNextMD(M, D, n, zState):
	optdFn = bellman.getIter(n)['opt_d']
	optrFn = bellman.getIter(n)['opt_r']
	# k = d + D - M
	k_fn = lambda x: optdFn(x) + x[1] - x[0]	
	f_fn = lambda x: p_fns.testf(k_fn(x), optrFn(x))
	inflow = lambda x: f_fn(x) * g.z_space[zState]
	M_fn = lambda x: (inflow(x) - k_fn(x))/g.z_space[zState]
	D_fn = lambda x: optrFn(x) * f_fn(x)
	return (M_fn([M,D]), D_fn([M,D]))
コード例 #3
0
ファイル: ponzi4.py プロジェクト: zsh1313/bellman
def testPlotF():
	fig = plt.figure()
	ax = Axes3D(fig)
	f_fn = lambda x: p_fns.testf(x[0], x[1])
	grid_k = linspace(0, 2, 50)
	grid_r = linspace(1, 3, 50)
	(mesh_k, mesh_r) = meshgrid(grid_k, grid_r)
	meshlist_k = mesh_k.ravel()
	meshlist_r = mesh_r.ravel()
	
	ax.scatter(meshlist_k, meshlist_r, array(map(f_fn, zip(meshlist_k, meshlist_r))))	
	ax.set_xlabel('k')
	ax.set_ylabel('r')
	ax.set_zlabel('f')
コード例 #4
0
ファイル: ponzi4.py プロジェクト: zsh1313/bellman
def getNextStateArray(n, zState):
	opt_d = bellman.getIter(n)['opt_d']
	opt_r = bellman.getIter(n)['opt_r']
	# k = d + D - M
	k_fn = lambda x: opt_d(x) + x[1] - x[0]	
	f_fn = lambda x: p_fns.testf(k_fn(x), opt_r(x))
	rho_fn = lambda x: rhoFn(x, f_fn, k_fn)

	def nextStateFn(M,D):
		(nextM, nextD) = getNextMD(M, D, n, zState)
		# if current state is A (bankrupt with certainty), then next state has no meaning.  color it black
		currentState = classifyState(M, D, rho_fn, opt_d)
		if (currentState == g.STATE_RED):
			return g.STATE_BLACK
		# if current state is B (bankrupt if zLow occurs) and zLow occurs, next state is in bankruptcy
		if (currentState == g.STATE_BLUE and zState == 0):
			return g.STATE_BLACK
		return classifyState(nextM, nextD, rho_fn, opt_d)
	
	nextStateArray = scipy.vectorize(nextStateFn)(g.mesh_M, g.mesh_D)
	return scipy.transpose(nextStateArray)