Compare commits

...

9 Commits

Author SHA1 Message Date
Michael Zargham 0814ae3408 running again 2018-10-18 09:28:21 -07:00
Michael Zargham 99edb688e7 dont lost things~ 2018-10-18 09:21:48 -07:00
Michael Zargham ff69455681 re-merge staging 2018-10-18 09:14:00 -07:00
Michael Zargham 249dfc22e3 Revert "Merge remote-tracking branch 'origin/staging' into mz-dead"
This reverts commit 4113fb4202, reversing
changes made to 8f35856348.
2018-10-18 09:11:49 -07:00
Michael Zargham 4587c377f9 Revert "testing fun"
This reverts commit 8f35856348.
2018-10-18 08:57:24 -07:00
Michael Zargham 4113fb4202 Merge remote-tracking branch 'origin/staging' into mz-dead 2018-10-18 08:51:09 -07:00
Michael Zargham 8f35856348 testing fun 2018-10-17 21:15:33 -07:00
Michael Zargham cf00305963 zargham test success! 2018-10-16 17:38:23 -07:00
Zargham 59542928c8 mikes edits 2018-10-16 15:33:35 -07:00
18 changed files with 946 additions and 62 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -21,12 +21,8 @@ def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step):
_input = getBehaviorInput(m_step, sL, last_in_obj, behavior_funcs)
# OLD: no bueno! Mutation Bad
# for f in state_funcs:
# f(m_step, sL, last_mut_obj, _input)
# New
last_mut_obj = dict([ f(m_step, sL, last_mut_obj, _input) for f in state_funcs ])
for f in state_funcs:
f(m_step, sL, last_mut_obj, _input)
apply_env_proc(env_processes, last_mut_obj, last_mut_obj['timestamp'])

View File

@ -1,4 +1,7 @@
from ui.config import state_dict, mechanisms, exogenous_states, env_processes, sim_config
#from ui.config import state_dict, mechanisms, exogenous_states, env_processes, sim_config
#from ui.toyConfig import state_dict, mechanisms, exogenous_states, env_processes, sim_config
from ui.simpleBC_Config import state_dict, mechanisms, exogenous_states, env_processes, sim_config
#from ui.<config_filename> import state_dict, mechanisms, exogenous_states, env_processes, sim_config
from engine.configProcessor import generate_config
from engine.mechanismExecutor import simulation
from engine.utils import flatten
@ -11,7 +14,8 @@ def main():
configs = generate_config(mechanisms, exogenous_states)
# p = pipeline(states_list, configs, env_processes, range(10))
N = sim_config['N']
r = range(5)
r = range(sim_config["R"])
#r = range(5)
# Dimensions: N x r x mechs
s = simulation(states_list, configs, env_processes, r, N)
result = pd.DataFrame(flatten(s))

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,2 @@
from engine import run
from tabulate import tabulate
result = run.main()
print(tabulate(result, headers='keys', tablefmt='psql'))
run.main()

Binary file not shown.

View File

@ -29,47 +29,29 @@ def b2m3(step, sL, s):
# Internal States per Mechanism
def s1m1(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input
return (y, x)
s['s1'] = s['s1'] + _input
def s2m1(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input
return (y, x)
s['s2'] = s['s2'] + _input
def s1m2(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input
return (y, x)
s['s1'] = s['s1'] + _input
def s2m2(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input
return (y, x)
s['s2'] = s['s2'] + _input
def s1m3(step, sL, s, _input):
y = 's1'
x = s['s1'] + _input
return (y, x)
s['s1'] = s['s1'] + _input
def s2m3(step, sL, s, _input):
y = 's2'
x = s['s2'] + _input
return (y, x)
s['s2'] = s['s2'] + _input
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
def es3p1(step, sL, s, _input):
y = 's3'
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
s['s3'] = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
def es4p2(step, sL, s, _input):
y = 's4'
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
s['s4'] = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params
y = 'timestamp'
x = ep_time_step(s, s['timestamp'], seconds=1)
return (y, x)
s['timestamp'] = ep_time_step(s, s['timestamp'], seconds=1)
# Environment States
def env_a(x):

168
ui/simpleBC_Config.py Normal file
View File

@ -0,0 +1,168 @@
from engine.utils import bound_norm_random, ep_time_step, env_proc
import numpy as np
from decimal import Decimal
alpha = Decimal('.7') #forgetting param
theta = Decimal('.75') #weight param for rational price
beta = Decimal('0.5') #agant response gain
gamma = Decimal('.03') #action friction param
delta = Decimal('.3') #bounds on price change
omega = Decimal('.5') #bound on burn frac per period
seed = {
'z': np.random.RandomState(1),
'a': np.random.RandomState(2),
'b': np.random.RandomState(3),
'c': np.random.RandomState(3)
}
# Behaviors per Mechanism
#arbit X Bond
def b1m1(step, sL, s):
#returns "delta p"
if s['Price']< s['Pool']/s['Supply']-gamma:
return (s['Pool']/s['Supply']-s['Price'])/s['Price']*s['Pool']*beta
else :
return 0
#invest X Bond
def b2m1(step, sL, s):
#returns "delta p"
if s['Belief']< (alpha*s['Belief']+s['Pool']/s['Supply'])*(1-alpha):
return s['Supply']*((alpha*s['Belief']+s['Pool']/s['Supply'])*(1-alpha)-s['Belief'])*beta
else :
return 0
#arbit X Burn
def b1m2(step, sL, s):
#returns "delta s"
if Decimal('1')/s['Price']< s['Supply']/s['Pool']-gamma:
return (s['Supply']/s['Pool']-Decimal('1')/s['Price'])*s['Price']*s['Supply']*beta
else :
return 0
#invest X Burn
def b2m2(step, sL, s):
#returns "delta s"
if Decimal('1')/s['Belief']< Decimal('1')/s['Price']:
return np.min([ s['Pool']*(Decimal('1')/s['Price']-Decimal('1')/s['Belief'])*beta, omega*s['Supply']])
else :
return 0
#
#def b1m3(step, sL, s):
# return s['s1']
#def b2m3(step, sL, s):
# return s['s2']
# Internal States per Mechanism
#Pool X Bond
def s1m1(step, sL, s, _input):
#_input = "delta p"
s['Pool'] = s['Pool']+_input
#Supply X Bond
def s2m1(step, sL, s, _input):
#_input = "delta p"
s['Supply'] = s['Supply']+_input*s['Supply']/s['Pool']
# Pool X Burn
def s1m2(step, sL, s, _input):
#_input is "delta s"
s['Pool'] = s['Pool']- _input*s['Pool']/s['Supply']
# Supply X Burn
def s2m2(step, sL, s, _input):
s['Supply'] = s['Supply'] - _input
#def s1m3(step, sL, s, _input):
# s['s1'] = s['s1']+Decimal(.25)*(s['s2']-s['s1']) + Decimal(.25)*(_input-s['s1'])
#
#def s2m3(step, sL, s, _input):
# s['s2'] = s['s2']+Decimal(.25)*(s['s1']-s['s2']) + Decimal(.25)*(_input-s['s2'])
# Exogenous States
proc_one_coef_A = -delta
proc_one_coef_B = delta
def es3p1(step, sL, s, _input):
rv = bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
s['Price'] = theta*s['Price'] * (Decimal('1')+rv) +(Decimal('1')-theta)*s['Pool']/s['Supply']
def es4p2(step, sL, s, _input):
s['Belief'] = alpha*s['Belief']+s['Pool']/s['Supply']*(Decimal('1')-alpha)
def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params
s['timestamp'] = ep_time_step(s, s['timestamp'], seconds=1)
# Environment States
#from numpy.random import randn as rn
def env_a(x):
return 3
def env_b(x):
return 7
# def what_ever(x):
# return x + 1
# Genesis States
state_dict = {
'Pool': Decimal(10.0),
'Supply': Decimal(5.0),
'Price': Decimal(.01),
'Belief': Decimal(10.0),
'timestamp': '2018-10-01 15:16:24'
}
exogenous_states = {
"Price": es3p1,
"Belief": es4p2,
"timestamp": es5p2
}
env_processes = {
"Price": env_proc('2018-10-01 15:16:25', env_a),
"Belief": env_proc('2018-10-01 15:16:25', env_b)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"bond": {
"behaviors": {
"arbit": b1m1, # lambda step, sL, s: s['s1'] + 1,
"invest": b2m1
},
"states": {
"Pool": s1m1,
"Supply": s2m1,
}
},
"burn": {
"behaviors": {
"arbit": b1m2,
"invest": b2m2
},
"states": {
"Pool": s1m2,
"Supply": s2m2,
}
},
# "m3": {
# "behaviors": {
# "b1": b1m3,
# "b2": b2m3
# },
# "states": {
# "s1": s1m3,
# "s2": s2m3,
# }
# }
}
sim_config = {
"N": 1,
"R": 1000
}

121
ui/toyConfig.py Normal file
View File

@ -0,0 +1,121 @@
from engine.utils import bound_norm_random, ep_time_step, env_proc
import numpy as np
from decimal import Decimal
seed = {
'z': np.random.RandomState(1),
'a': np.random.RandomState(2),
'b': np.random.RandomState(3),
'c': np.random.RandomState(3)
}
# Behaviors per Mechanism
def b1m1(step, sL, s):
return s['s1']
def b2m1(step, sL, s):
return s['s2']-s['s1']
def b1m2(step, sL, s):
return s['s1']-s['s2']
def b2m2(step, sL, s):
return s['s2']
def b1m3(step, sL, s):
return s['s1']
def b2m3(step, sL, s):
return s['s2']
# Internal States per Mechanism
def s1m1(step, sL, s, _input):
s['s1'] = (s['s1']-Decimal('0.5')*_input)/(s['s1']+s['s2']+s['s3']+s['s4'])**2
def s2m1(step, sL, s, _input):
s['s2'] = (s['s2']-Decimal('0.5')*_input)/(s['s2']+s['s1']+s['s3']+s['s4'])**2
def s1m2(step, sL, s, _input):
s['s1'] = s['s3']*(_input*s['s1']/s['s2']+Decimal('1.0'))
def s2m2(step, sL, s, _input):
s['s2'] = s['s4']*(s['s2']/s['s1']+Decimal('1.0'))
def s1m3(step, sL, s, _input):
s['s1'] = s['s1']+Decimal(.25)*(s['s2']-s['s1']) + Decimal(.25)*(_input-s['s1'])
def s2m3(step, sL, s, _input):
s['s2'] = s['s2']+Decimal(.25)*(s['s1']-s['s2']) + Decimal(.25)*(_input-s['s2'])
# Exogenous States
proc_one_coef_A = 0.7
proc_one_coef_B = 1.3
def es3p1(step, sL, s, _input):
s['s3'] = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
def es4p2(step, sL, s, _input):
s['s4'] = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params
s['timestamp'] = ep_time_step(s, s['timestamp'], seconds=1)
# Environment States
def env_a(x):
return 3
def env_b(x):
return 7
# def what_ever(x):
# return x + 1
# Genesis States
state_dict = {
's1': Decimal(5.0),
's2': Decimal(10.0),
's3': Decimal(1.0),
's4': Decimal(1.0),
'timestamp': '2018-10-01 15:16:24'
}
exogenous_states = {
"s3": es3p1,
"s4": es4p2,
"timestamp": es5p2
}
env_processes = {
"s3": env_proc('2018-10-01 15:16:25', env_a),
"s4": env_proc('2018-10-01 15:16:25', env_b)
}
# test return vs. non-return functions as lambdas
# test fully defined functions
mechanisms = {
"m1": {
"behaviors": {
"b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
"b2": b2m1
},
"states": {
"s1": s1m1,
"s2": s2m1,
}
},
"m2": {
"behaviors": {
"b1": b1m2,
"b2": b2m2
},
"states": {
"s1": s1m2,
"s2": s2m2,
}
},
"m3": {
"behaviors": {
"b1": b1m3,
"b2": b2m3
},
"states": {
"s1": s1m3,
"s2": s2m3,
}
}
}
sim_config = {
"N": 1,
"R": 100
}