Last active
August 29, 2015 14:22
-
-
Save arashaga/a99934b0aa54feef938e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
from src.optimization import tangency | |
from bokeh.io import vform | |
from bokeh.plotting import figure, output_file, show | |
from bokeh.models import * | |
from numpy import * | |
def cobbDouglas_points(xs,px,py,z): | |
y =[] | |
for x in xs: | |
if x==0: x=1 | |
y.append(pow(z/(pow(x,px)),(1/py))) | |
return y | |
def cobbDouglas(x,px,y,py): | |
return x**(px)*y**py | |
def budgetLine(x1,px,py,m): | |
y= [] | |
for x in x1: | |
y.append(((m/py)-((px*x)/py))) | |
return y | |
print(cobbDouglas(5,0.5,5,0.5)) | |
output_file("test.html") | |
x2 = list(range(0,100)) | |
yBL= budgetLine(x2,1,1,10) | |
##find the optimal point using this method | |
result = tangency(1,1,10) | |
u = cobbDouglas(result[0],0.5,result[1],0.5) | |
def utility_func(m): | |
result = tangency(1,1,m) | |
return cobbDouglas(result[0],0.5,result[1],0.5) | |
y2= cobbDouglas_points(x2,0.5,0.5,u) | |
p= figure(y_range=(0, max(yBL)),x_range=(0,15), plot_width=400, plot_height=400) | |
source1 = ColumnDataSource(data=dict(x=x2,y=yBL)) | |
#source2 = ColumnDataSource(data=dict(x=x2,y=y2,u=u)) | |
p.line(x2,yBL,source=source1, line_width=2) | |
p.line(x2,y2,source=source2, line_width=1) | |
callback = Callback(args=dict(source1=source1,source2=source2,), code=""" | |
var data1 = source1.get('data'); | |
var data2 = source2.get('data'); | |
var f = cb_obj.get('value'); | |
x1 = data1['x'] | |
y1 = data1['y'] | |
// x2 = data2['x'] | |
// y2 = data2['y'] | |
// u = data2['u'] | |
for (i = 0; i < x1.length; i++) { | |
y1[i]= 5-f*x1[i]; | |
// y2[i] = Math.pow(u/(Math.pow(x2[i],0.5)),(1/0.5)); | |
// console.log(u); | |
} | |
source1.trigger('change'); | |
// source2.trigger('change'); | |
""") | |
#I was trying to call this callback to get the new value to keep the tangency | |
def myCallBack(): | |
result = tangency(slider.value,1,10) | |
u = cobbDouglas(result[0],0.5,result[1],0.5) | |
print(u) | |
slider = Slider(start=1, end=100, value=1, step=1, | |
title="value", callback=callback) | |
#none of the following worked! | |
#slider.setup_events() | |
#slider.on_change('value', 'input_change') | |
# print(x1,y1) | |
#def input_change(): | |
# print("input has changed!") | |
layout = vform(slider, p) | |
show(layout) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment