Enable: behavior output to be a map of behavior function to value pt.2
This commit is contained in:
parent
2d4d20eb5e
commit
f6f6e7b3fd
|
|
@ -15,12 +15,14 @@ def getBehaviorInput(step, sL, s, funcs, ops = behavior_ops):
|
|||
ops = ops[::-1]
|
||||
|
||||
return foldr(call, getColResults(step, sL, s, funcs))(ops)
|
||||
# return getColResults(step, sL, s, funcs)
|
||||
|
||||
def apply_env_proc(env_processes, state_dict, step):
|
||||
for state in state_dict.keys():
|
||||
if state in list(env_processes.keys()):
|
||||
state_dict[state] = env_processes[state](step)(state_dict[state])
|
||||
|
||||
# remove / modify
|
||||
def exception_handler(f, m_step, sL, last_mut_obj, _input):
|
||||
try:
|
||||
return f(m_step, sL, last_mut_obj, _input)
|
||||
|
|
@ -35,8 +37,9 @@ def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step, ru
|
|||
_input = exception_handler(getBehaviorInput, m_step, sL, last_in_obj, behavior_funcs)
|
||||
|
||||
last_in_copy = dict([ exception_handler(f, m_step, sL, last_in_obj, _input) for f in state_funcs ])
|
||||
del last_in_obj # print(str(m_step) + ': ' + str(last_in_copy))
|
||||
del last_in_obj
|
||||
|
||||
# make env proc trigger field agnostic
|
||||
apply_env_proc(env_processes, last_in_copy, last_in_copy['timestamp']) # mutating last_in_copy
|
||||
|
||||
last_in_copy["mech_step"], last_in_copy["time_step"], last_in_copy['run'] = m_step, t_step, run
|
||||
|
|
|
|||
62
ui/config.py
62
ui/config.py
|
|
@ -13,49 +13,61 @@ seed = {
|
|||
'c': np.random.RandomState(3)
|
||||
}
|
||||
|
||||
# # Behaviors per Mechanism
|
||||
# def b1m1(step, sL, s):
|
||||
# return np.array([1, 2])
|
||||
# def b2m1(step, sL, s):
|
||||
# return np.array([3, 4])
|
||||
# # Internal States per Mechanism
|
||||
# def s1m1(step, sL, s, _input):
|
||||
# y = 's1'
|
||||
# x = _input['b1'] * s['s1'] + _input['b2']
|
||||
# return (y, x)
|
||||
|
||||
# Behaviors per Mechanism
|
||||
# Different return types per mechanism ??
|
||||
def b1m1(step, sL, s):
|
||||
return s['s1'] + 1
|
||||
return {'param1': 1, 'param2': 2}
|
||||
def b2m1(step, sL, s):
|
||||
return s['s1'] + 1
|
||||
return {'param1': 3, 'param2': 4}
|
||||
|
||||
def b1m2(step, sL, s):
|
||||
return s['s1'] + 1
|
||||
return {'param1': 1, 'param2': 2}
|
||||
def b2m2(step, sL, s):
|
||||
return s['s1'] + 1
|
||||
return {'param1': 3, 'param2': 4}
|
||||
|
||||
def b1m3(step, sL, s):
|
||||
return s['s1'] + 1
|
||||
return {'param1': 1, 'param2': 2}
|
||||
def b2m3(step, sL, s):
|
||||
return s['s2'] + 1
|
||||
return {'param1': 3, 'param2': 4}
|
||||
|
||||
|
||||
# Internal States per Mechanism
|
||||
def s1m1(step, sL, s, _input):
|
||||
y = 's1'
|
||||
x = s['s1'] + _input
|
||||
x = s['s1'] + _input['param1']
|
||||
return (y, x)
|
||||
def s2m1(step, sL, s, _input):
|
||||
y = 's2'
|
||||
x = s['s2'] + _input
|
||||
x = s['s2'] + _input['param2']
|
||||
return (y, x)
|
||||
|
||||
def s1m2(step, sL, s, _input):
|
||||
y = 's1'
|
||||
x = s['s1'] + _input
|
||||
x = s['s1'] + _input['param1']
|
||||
return (y, x)
|
||||
def s2m2(step, sL, s, _input):
|
||||
y = 's2'
|
||||
x = s['s2'] + _input
|
||||
x = s['s2'] + _input['param2']
|
||||
return (y, x)
|
||||
|
||||
def s1m3(step, sL, s, _input):
|
||||
y = 's1'
|
||||
x = s['s1'] + _input
|
||||
x = s['s1'] + _input['param1']
|
||||
return (y, x)
|
||||
def s2m3(step, sL, s, _input):
|
||||
y = 's2'
|
||||
x = s['s2'] + s['s3'] + _input
|
||||
x = s['s2'] + s['s3'] + _input['param2']
|
||||
return (y, x)
|
||||
|
||||
# Exogenous States
|
||||
|
|
@ -104,7 +116,7 @@ exogenous_states = exo_update_per_ts(
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
# make env proc trigger field agnostic
|
||||
env_processes = {
|
||||
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
|
||||
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
|
||||
|
|
@ -119,19 +131,29 @@ def print_fwd(x):
|
|||
return x
|
||||
|
||||
def behavior_to_dict(v):
|
||||
return dict(list(zip(map(lambda n: 'b_' + str(n), list(range(len(v)))), v)))
|
||||
return dict(list(zip(map(lambda n: 'b' + str(n), list(range(len(v)))), v)))
|
||||
|
||||
|
||||
def foldr_dict_vals(d, f = _ + _):
|
||||
@curried
|
||||
def foldr_dict_vals(f, d):
|
||||
return foldr(f)(list(d.values()))
|
||||
|
||||
def sum_dict_values(d):
|
||||
return foldr_dict_vals(d)
|
||||
def sum_dict_values(f = _ + _):
|
||||
return foldr_dict_vals(f)
|
||||
|
||||
# behavior_ops = [ behavior_to_dict, print_fwd, sum_dict_values, lambda x: x + 0 ]
|
||||
behavior_ops = []
|
||||
@curried
|
||||
def dict_op(f, d1, d2):
|
||||
return {k: f(d1[k], d2[k]) for k in d2}
|
||||
|
||||
def dict_elemwise_sum(f = _ + _):
|
||||
return dict_op(f)
|
||||
|
||||
# [1, 2] = {'b1': ['a'], 'b2', [1]} =
|
||||
# behavior_ops = [ behavior_to_dict, print_fwd, sum_dict_values ]
|
||||
behavior_ops = [ print_fwd, foldr(dict_elemwise_sum()) ]
|
||||
# behavior_ops = []
|
||||
|
||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
||||
# mechanisms = {}
|
||||
mechanisms = {
|
||||
"m1": {
|
||||
"behaviors": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue