middleware
This commit is contained in:
parent
3719ead0b1
commit
20a8bd3026
|
|
@ -176,8 +176,8 @@ def create_sweep_config_list(zipped_sweep_lists, states_dict, state_type_ind='me
|
||||||
|
|
||||||
|
|
||||||
def parameterize_states(exo_states):
|
def parameterize_states(exo_states):
|
||||||
pp.pprint(exo_states)
|
# pp.pprint(exo_states)
|
||||||
print()
|
# print()
|
||||||
sweep_lists = []
|
sweep_lists = []
|
||||||
for sk, vfs in exo_states.items():
|
for sk, vfs in exo_states.items():
|
||||||
id_sweep_lists = []
|
id_sweep_lists = []
|
||||||
|
|
@ -190,8 +190,8 @@ def parameterize_states(exo_states):
|
||||||
if len(sweep_lists) == 0:
|
if len(sweep_lists) == 0:
|
||||||
return [exo_states]
|
return [exo_states]
|
||||||
|
|
||||||
pp.pprint(sweep_lists)
|
# pp.pprint(sweep_lists)
|
||||||
print()
|
# print()
|
||||||
|
|
||||||
zipped_sweep_lists = zip_sweep_functions(sweep_lists)
|
zipped_sweep_lists = zip_sweep_functions(sweep_lists)
|
||||||
states_configs = create_sweep_config_list(zipped_sweep_lists, exo_states, "exo_proc")
|
states_configs = create_sweep_config_list(zipped_sweep_lists, exo_states, "exo_proc")
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class Executor:
|
||||||
def get_col_results(step, sL, s, funcs):
|
def get_col_results(step, sL, s, funcs):
|
||||||
return list(map(lambda f: curry_pot(f, step, sL, s), funcs))
|
return list(map(lambda f: curry_pot(f, step, sL, s), funcs))
|
||||||
|
|
||||||
|
print(get_col_results(step, sL, s, funcs))
|
||||||
return foldr(call, get_col_results(step, sL, s, funcs))(ops)
|
return foldr(call, get_col_results(step, sL, s, funcs))(ops)
|
||||||
|
|
||||||
def apply_env_proc(self, env_processes, state_dict, step):
|
def apply_env_proc(self, env_processes, state_dict, step):
|
||||||
|
|
|
||||||
|
|
@ -42,5 +42,3 @@ def fit_param(param, x):
|
||||||
return x + param
|
return x + param
|
||||||
|
|
||||||
# fit_param = lambda param: lambda x: x + param
|
# fit_param = lambda param: lambda x: x + param
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,6 @@ def rename(new_name, f):
|
||||||
f.__name__ = new_name
|
f.__name__ = new_name
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
def curry_pot(f, *argv):
|
def curry_pot(f, *argv):
|
||||||
sweep_ind = f.__name__[0:5] == 'sweep'
|
sweep_ind = f.__name__[0:5] == 'sweep'
|
||||||
arg_len = len(argv)
|
arg_len = len(argv)
|
||||||
|
|
@ -80,6 +79,20 @@ def curry_pot(f, *argv):
|
||||||
else:
|
else:
|
||||||
raise TypeError('curry_pot() needs 3 or 4 positional arguments')
|
raise TypeError('curry_pot() needs 3 or 4 positional arguments')
|
||||||
|
|
||||||
|
# def curry_pot(f, *argv):
|
||||||
|
# sweep_ind = f.__name__[0:5] == 'sweep'
|
||||||
|
# arg_len = len(argv)
|
||||||
|
# if sweep_ind is True and arg_len == 4:
|
||||||
|
# return f(argv[0])(argv[1])(argv[2])(argv[3])
|
||||||
|
# elif sweep_ind is False and arg_len == 4:
|
||||||
|
# return f(argv[0])(argv[1])(argv[2])(argv[3])
|
||||||
|
# elif sweep_ind is True and arg_len == 3:
|
||||||
|
# return f(argv[0])(argv[1])(argv[2])
|
||||||
|
# elif sweep_ind is False and arg_len == 3:
|
||||||
|
# return f(argv[0])(argv[1])(argv[2])
|
||||||
|
# else:
|
||||||
|
# raise TypeError('curry_pot() needs 3 or 4 positional arguments')
|
||||||
|
|
||||||
# def rename(newname):
|
# def rename(newname):
|
||||||
# def decorator(f):
|
# def decorator(f):
|
||||||
# f.__name__ = newname
|
# f.__name__ = newname
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,10 @@ seed = {
|
||||||
# Behaviors per Mechanism
|
# Behaviors per Mechanism
|
||||||
def b1m1(step, sL, s):
|
def b1m1(step, sL, s):
|
||||||
return {'param1': 1}
|
return {'param1': 1}
|
||||||
|
|
||||||
def b2m1(step, sL, s):
|
def b2m1(step, sL, s):
|
||||||
return {'param2': 4}
|
return {'param2': 4}
|
||||||
|
|
||||||
# @curried
|
# @curried
|
||||||
def b1m2(param, step, sL, s):
|
def b1m2(param, step, sL, s):
|
||||||
return {'param1': 'a', 'param2': param}
|
return {'param1': 'a', 'param2': param}
|
||||||
|
|
@ -65,6 +67,7 @@ def s1m3(step, sL, s, _input):
|
||||||
y = 's1'
|
y = 's1'
|
||||||
x = 0
|
x = 0
|
||||||
return (y, x)
|
return (y, x)
|
||||||
|
|
||||||
def s2m3(step, sL, s, _input):
|
def s2m3(step, sL, s, _input):
|
||||||
y = 's2'
|
y = 's2'
|
||||||
x = 0
|
x = 0
|
||||||
|
|
@ -96,8 +99,10 @@ def es5p2(step, sL, s, _input):
|
||||||
|
|
||||||
# Environment States
|
# Environment States
|
||||||
# @curried
|
# @curried
|
||||||
def env_a(param, x):
|
# def env_a(param, x):
|
||||||
return x + param
|
# return x + param
|
||||||
|
def env_a(x):
|
||||||
|
return x
|
||||||
def env_b(x):
|
def env_b(x):
|
||||||
return 10
|
return 10
|
||||||
|
|
||||||
|
|
@ -118,7 +123,7 @@ raw_exogenous_states = {
|
||||||
"s4": sweep(beta, es4p2),
|
"s4": sweep(beta, es4p2),
|
||||||
"timestamp": es5p2
|
"timestamp": es5p2
|
||||||
}
|
}
|
||||||
# exogenous_states_list = list(map(exo_update_per_ts, parameterize_states(raw_exogenous_states)))
|
exogenous_states_list = list(map(exo_update_per_ts, parameterize_states(raw_exogenous_states)))
|
||||||
|
|
||||||
|
|
||||||
# ToDo: make env proc trigger field agnostic
|
# ToDo: make env proc trigger field agnostic
|
||||||
|
|
@ -127,13 +132,13 @@ triggered_env_b = proc_trigger('2018-10-01 15:16:25', env_b)
|
||||||
|
|
||||||
|
|
||||||
env_processes = {
|
env_processes = {
|
||||||
"s3": sweep(beta, env_a),
|
"s3": env_a, #sweep(beta, env_a),
|
||||||
"s4": triggered_env_b #rename('parameterized', triggered_env_b) #sweep(beta, triggered_env_b)
|
"s4": triggered_env_b #rename('parameterized', triggered_env_b) #sweep(beta, triggered_env_b)
|
||||||
}
|
}
|
||||||
parameterized_env_processes = parameterize_states(env_processes)
|
# parameterized_env_processes = parameterize_states(env_processes)
|
||||||
|
#
|
||||||
pp.pprint(parameterized_env_processes)
|
# pp.pprint(parameterized_env_processes)
|
||||||
exit()
|
# exit()
|
||||||
|
|
||||||
# ToDo: The number of values enteren in sweep should be the # of config objs created,
|
# ToDo: The number of values enteren in sweep should be the # of config objs created,
|
||||||
# not dependent on the # of times the sweep is applied
|
# not dependent on the # of times the sweep is applied
|
||||||
|
|
@ -143,8 +148,9 @@ exit()
|
||||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
||||||
# mechanisms = {}
|
# mechanisms = {}
|
||||||
|
|
||||||
|
#middleware(beta, [(m1, states, s2, s2m1), (m2, behaviors, b1, b1m2)], mechanisms)
|
||||||
|
|
||||||
mechanisms = {
|
mechanisms_test = {
|
||||||
"m1": {
|
"m1": {
|
||||||
"behaviors": {
|
"behaviors": {
|
||||||
"b1": b1m1,
|
"b1": b1m1,
|
||||||
|
|
@ -152,12 +158,12 @@ mechanisms = {
|
||||||
},
|
},
|
||||||
"states": {
|
"states": {
|
||||||
"s1": s1m1,
|
"s1": s1m1,
|
||||||
"s2": sweep(beta, s2m1) #s2m1(1) #sweep(beta, s2m1)
|
"s2": "sweep"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"m2": {
|
"m2": {
|
||||||
"behaviors": {
|
"behaviors": {
|
||||||
"b1": sweep(beta, b1m2), #b1m2(1) #sweep(beta, b1m2),
|
"b1": "sweep",
|
||||||
"b2": b2m2
|
"b2": b2m2
|
||||||
},
|
},
|
||||||
"states": {
|
"states": {
|
||||||
|
|
@ -176,14 +182,77 @@ mechanisms = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
from copy import deepcopy
|
||||||
|
from funcy import curry
|
||||||
|
|
||||||
|
|
||||||
|
def sweep_identifier(sweep_list, sweep_id_list, mechanisms):
|
||||||
|
new_mechanisms = deepcopy(mechanisms)
|
||||||
|
for x in sweep_id_list:
|
||||||
|
mech, update_type, update, f = x[0], x[1], x[2], x[3]
|
||||||
|
current_f = new_mechanisms[x[0]][x[1]][x[2]]
|
||||||
|
if current_f is 'sweep':
|
||||||
|
new_mechanisms[x[0]][x[1]][x[2]] = sweep(sweep_list, x[3])
|
||||||
|
|
||||||
|
# for mech, update_types in new_mechanisms.items():
|
||||||
|
# for update_type, fkv in update_types.items():
|
||||||
|
# for sk, current_f in fkv.items():
|
||||||
|
# if current_f != 'sweep' and isinstance(current_f, list) == False:
|
||||||
|
# new_mechanisms[mech][update_type][sk] = curry(f)(0)
|
||||||
|
|
||||||
|
del mechanisms
|
||||||
|
return new_mechanisms
|
||||||
|
|
||||||
|
|
||||||
|
sweep_id_list = [('m1', 'states', 's2', s2m1), ('m2', 'behaviors', 'b1', b1m2)]
|
||||||
|
# pp.pprint(sweep_identifier(beta, sweep_id_list, mechanisms_test))
|
||||||
|
|
||||||
|
|
||||||
|
mechanisms = sweep_identifier(beta, sweep_id_list, mechanisms_test)
|
||||||
|
|
||||||
|
# mechanisms = {
|
||||||
|
# "m1": {
|
||||||
|
# "behaviors": {
|
||||||
|
# "b1": b1m1,
|
||||||
|
# "b2": b2m1
|
||||||
|
# },
|
||||||
|
# "states": {
|
||||||
|
# "s1": s1m1,
|
||||||
|
# "s2": sweep(beta, s2m1) #s2m1(1) #sweep(beta, s2m1)
|
||||||
|
# }
|
||||||
|
# },
|
||||||
|
# "m2": {
|
||||||
|
# "behaviors": {
|
||||||
|
# "b1": sweep(beta, b1m2), #b1m2(1) #sweep(beta, b1m2),
|
||||||
|
# "b2": b2m2
|
||||||
|
# },
|
||||||
|
# "states": {
|
||||||
|
# "s1": s1m2,
|
||||||
|
# "s2": s2m2
|
||||||
|
# }
|
||||||
|
# },
|
||||||
|
# "m3": {
|
||||||
|
# "behaviors": {
|
||||||
|
# "b1": b1m3,
|
||||||
|
# "b2": b2m3
|
||||||
|
# },
|
||||||
|
# "states": {
|
||||||
|
# "s1": s1m3,
|
||||||
|
# "s2": s2m3
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# }
|
||||||
parameterized_mechanism = parameterize_mechanism(mechanisms)
|
parameterized_mechanism = parameterize_mechanism(mechanisms)
|
||||||
|
pp.pprint(parameterized_mechanism)
|
||||||
|
# exit()
|
||||||
|
|
||||||
sim_config = {
|
sim_config = {
|
||||||
"N": 2,
|
"N": 2,
|
||||||
"T": range(5)
|
"T": range(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
for mechanisms, env_processes, exogenous_states in zip(parameterized_mechanism, parameterized_env_processes, exogenous_states_list):
|
for mechanisms, exogenous_states in zip(parameterized_mechanism, exogenous_states_list):
|
||||||
configs.append(
|
configs.append(
|
||||||
Configuration(
|
Configuration(
|
||||||
sim_config=sim_config,
|
sim_config=sim_config,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue