Enable: behavior output to be a map of behavior function to value
This commit is contained in:
parent
15c1d2fa8c
commit
2d4d20eb5e
|
|
@ -1,6 +1,9 @@
|
|||
import pandas as pd
|
||||
from functools import reduce
|
||||
|
||||
def no_state_identity(step, sL, s, _input):
|
||||
return None
|
||||
|
||||
def state_identity(k):
|
||||
return lambda step, sL, s, _input: (k, s[k])
|
||||
|
||||
|
|
@ -31,17 +34,27 @@ def create_matrix_field(mechanisms, key):
|
|||
return pd.DataFrame({'empty' : []})
|
||||
|
||||
|
||||
# Maybe Refactor to only use dictionary BUT I used dfs to fill NAs. Perhaps fill
|
||||
def generate_config(state_dict, mechanisms, exo_proc):
|
||||
def no_behavior_handler(bdf, sdf):
|
||||
if bdf.empty == False:
|
||||
sdf_values, bdf_values = sdf.values.tolist(), bdf.values.tolist()
|
||||
|
||||
def no_update_handler(bdf, sdf):
|
||||
if (bdf.empty == False) and (sdf.empty == True):
|
||||
bdf_values = bdf.values.tolist()
|
||||
sdf_values = [ [no_state_identity] * len(bdf_values) for m in range(len(mechanisms)) ]
|
||||
return sdf_values, bdf_values
|
||||
elif (bdf.empty == True) and (sdf.empty == False):
|
||||
sdf_values = sdf.values.tolist()
|
||||
bdf_values = [ [b_identity] * len(sdf_values) for m in range(len(mechanisms)) ]
|
||||
return sdf_values, bdf_values
|
||||
else:
|
||||
sdf_values = sdf.values.tolist()
|
||||
bdf_values = [ [b_identity] * len(sdf_values) for n in range(mechanisms) ]
|
||||
return sdf_values, bdf_values
|
||||
bdf_values = bdf.values.tolist()
|
||||
return sdf_values, bdf_values
|
||||
|
||||
def only_ep_handler(state_dict):
|
||||
sdf_functions = [ lambda step, sL, s, _input: (k, v) for k, v in zip(state_dict.keys(), state_dict.values()) ]
|
||||
sdf_functions = [
|
||||
lambda step, sL, s, _input: (k, v) for k, v in zip(state_dict.keys(), state_dict.values())
|
||||
]
|
||||
sdf_values = [ sdf_functions ]
|
||||
bdf_values = [ [b_identity] * len(sdf_values) ]
|
||||
return sdf_values, bdf_values
|
||||
|
|
@ -50,7 +63,7 @@ def generate_config(state_dict, mechanisms, exo_proc):
|
|||
if len(mechanisms) != 0:
|
||||
bdf = create_matrix_field(mechanisms, 'behaviors')
|
||||
sdf = create_matrix_field(mechanisms, 'states')
|
||||
sdf_values, bdf_values = no_behavior_handler(bdf, sdf)
|
||||
sdf_values, bdf_values = no_update_handler(bdf, sdf)
|
||||
zipped_list = list(zip(sdf_values, bdf_values))
|
||||
else:
|
||||
sdf_values, bdf_values = only_ep_handler(state_dict)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
from copy import deepcopy
|
||||
from fn.op import foldr, call
|
||||
from fn import _
|
||||
from fn.op import foldr, call
|
||||
from ui.config import behavior_ops
|
||||
|
||||
def getColResults(step, sL, s, funcs):
|
||||
return list(map(lambda f: f(step, sL, s), funcs))
|
||||
|
||||
# Data Type reduction
|
||||
def getBehaviorInput(step, sL, s, funcs, ops = behavior_ops[::-1]):
|
||||
def getBehaviorInput(step, sL, s, funcs, ops = behavior_ops):
|
||||
|
||||
if len(ops) == 0:
|
||||
ops = [foldr(_ + _)]
|
||||
else:
|
||||
ops = ops[::-1]
|
||||
|
||||
return foldr(call, getColResults(step, sL, s, funcs))(ops)
|
||||
|
||||
def apply_env_proc(env_processes, state_dict, step):
|
||||
|
|
@ -72,7 +78,7 @@ def pipe(states_list, configs, env_processes, time_seq, run):
|
|||
return simulation_list
|
||||
|
||||
|
||||
# Del head
|
||||
# Del _ / head
|
||||
def simulation(states_list, configs, env_processes, time_seq, runs):
|
||||
pipe_run = []
|
||||
for run in range(runs):
|
||||
|
|
|
|||
22
ui/config.py
22
ui/config.py
|
|
@ -1,6 +1,7 @@
|
|||
from engine.utils import bound_norm_random, ep_time_step, proc_trigger, exo_update_per_ts
|
||||
from fn.op import foldr
|
||||
from fn import _
|
||||
from fn.func import curried
|
||||
|
||||
import numpy as np
|
||||
from decimal import Decimal
|
||||
|
|
@ -94,6 +95,7 @@ state_dict = {
|
|||
'timestamp': '2018-10-01 15:16:24'
|
||||
}
|
||||
|
||||
# remove `exo_update_per_ts` to update every ts
|
||||
exogenous_states = exo_update_per_ts(
|
||||
{
|
||||
"s3": es3p1,
|
||||
|
|
@ -102,6 +104,7 @@ exogenous_states = exo_update_per_ts(
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
env_processes = {
|
||||
"s3": proc_trigger('2018-10-01 15:16:25', env_a),
|
||||
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
|
||||
|
|
@ -110,7 +113,24 @@ env_processes = {
|
|||
# lambdas
|
||||
# genesis Sites should always be there
|
||||
# [1, 2]
|
||||
behavior_ops = [ foldr(_ + _), lambda x: x + 0 ]
|
||||
# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ]
|
||||
def print_fwd(x):
|
||||
print(x)
|
||||
return x
|
||||
|
||||
def behavior_to_dict(v):
|
||||
return dict(list(zip(map(lambda n: 'b_' + str(n), list(range(len(v)))), v)))
|
||||
|
||||
|
||||
def foldr_dict_vals(d, f = _ + _):
|
||||
return foldr(f)(list(d.values()))
|
||||
|
||||
def sum_dict_values(d):
|
||||
return foldr_dict_vals(d)
|
||||
|
||||
# behavior_ops = [ behavior_to_dict, print_fwd, sum_dict_values, lambda x: x + 0 ]
|
||||
behavior_ops = []
|
||||
|
||||
# need at least 1 behaviour and 1 state function for the 1st mech with behaviors
|
||||
mechanisms = {
|
||||
"m1": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue