renaming
This commit is contained in:
parent
06367f0573
commit
76fb452508
|
|
@ -4,23 +4,23 @@ import pandas as pd
|
|||
|
||||
from SimCAD import configs
|
||||
from SimCAD.utils import key_filter
|
||||
from SimCAD.configuration.utils.behaviorAggregation import dict_elemwise_sum
|
||||
from SimCAD.configuration.utils.policyAggregation import dict_elemwise_sum
|
||||
from SimCAD.configuration.utils import exo_update_per_ts
|
||||
|
||||
|
||||
class Configuration(object):
|
||||
def __init__(self, sim_config=None, state_dict=None, seed=None, env_processes=None,
|
||||
exogenous_states=None, mechanisms=None, behavior_ops=[foldr(dict_elemwise_sum())]):
|
||||
def __init__(self, sim_config=None, initial_state=None, seeds=None, env_processes=None,
|
||||
exogenous_states=None, partial_state_updates=None, policy_ops=[foldr(dict_elemwise_sum())]):
|
||||
self.sim_config = sim_config
|
||||
self.state_dict = state_dict
|
||||
self.seed = seed
|
||||
self.initial_state = initial_state
|
||||
self.seeds = seeds
|
||||
self.env_processes = env_processes
|
||||
self.exogenous_states = exogenous_states
|
||||
self.mechanisms = mechanisms
|
||||
self.behavior_ops = behavior_ops
|
||||
self.partial_state_updates = partial_state_updates
|
||||
self.policy_ops = policy_ops
|
||||
|
||||
|
||||
def append_configs(sim_configs, state_dict, seed, raw_exogenous_states, env_processes, mechanisms, _exo_update_per_ts=True):
|
||||
def append_configs(sim_configs, initial_state, seeds, raw_exogenous_states, env_processes, partial_state_updates, _exo_update_per_ts=True):
|
||||
if _exo_update_per_ts is True:
|
||||
exogenous_states = exo_update_per_ts(raw_exogenous_states)
|
||||
else:
|
||||
|
|
@ -31,41 +31,41 @@ def append_configs(sim_configs, state_dict, seed, raw_exogenous_states, env_proc
|
|||
configs.append(
|
||||
Configuration(
|
||||
sim_config=sim_config,
|
||||
state_dict=state_dict,
|
||||
seed=seed,
|
||||
initial_state=initial_state,
|
||||
seeds=seeds,
|
||||
exogenous_states=exogenous_states,
|
||||
env_processes=env_processes,
|
||||
mechanisms=mechanisms
|
||||
partial_state_updates=partial_state_updates
|
||||
)
|
||||
)
|
||||
elif isinstance(sim_configs, dict):
|
||||
configs.append(
|
||||
Configuration(
|
||||
sim_config=sim_configs,
|
||||
state_dict=state_dict,
|
||||
seed=seed,
|
||||
initial_state=initial_state,
|
||||
seeds=seeds,
|
||||
exogenous_states=exogenous_states,
|
||||
env_processes=env_processes,
|
||||
mechanisms=mechanisms
|
||||
partial_state_updates=partial_state_updates
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Identity:
|
||||
def __init__(self, behavior_id={'identity': 0}):
|
||||
self.beh_id_return_val = behavior_id
|
||||
def __init__(self, policy_id={'identity': 0}):
|
||||
self.beh_id_return_val = policy_id
|
||||
|
||||
def b_identity(self, var_dict, step, sL, s):
|
||||
def p_identity(self, var_dict, sub_step, sL, s):
|
||||
return self.beh_id_return_val
|
||||
|
||||
def behavior_identity(self, k):
|
||||
return self.b_identity
|
||||
def policy_identity(self, k):
|
||||
return self.p_identity
|
||||
|
||||
def no_state_identity(self, var_dict, step, sL, s, _input):
|
||||
def no_state_identity(self, var_dict, sub_step, sL, s, _input):
|
||||
return None
|
||||
|
||||
def state_identity(self, k):
|
||||
return lambda var_dict, step, sL, s, _input: (k, s[k])
|
||||
return lambda var_dict, sub_step, sL, s, _input: (k, s[k])
|
||||
|
||||
def apply_identity_funcs(self, identity, df, cols):
|
||||
def fillna_with_id_func(identity, df, col):
|
||||
|
|
@ -77,34 +77,34 @@ class Identity:
|
|||
class Processor:
|
||||
def __init__(self, id=Identity()):
|
||||
self.id = id
|
||||
self.b_identity = id.b_identity
|
||||
self.behavior_identity = id.behavior_identity
|
||||
self.p_identity = id.p_identity
|
||||
self.policy_identity = id.policy_identity
|
||||
self.no_state_identity = id.no_state_identity
|
||||
self.state_identity = id.state_identity
|
||||
self.apply_identity_funcs = id.apply_identity_funcs
|
||||
|
||||
def create_matrix_field(self, mechanisms, key):
|
||||
def create_matrix_field(self, partial_state_updates, key):
|
||||
if key == 'states':
|
||||
identity = self.state_identity
|
||||
elif key == 'behaviors':
|
||||
identity = self.behavior_identity
|
||||
df = pd.DataFrame(key_filter(mechanisms, key))
|
||||
elif key == 'policies':
|
||||
identity = self.policy_identity
|
||||
df = pd.DataFrame(key_filter(partial_state_updates, key))
|
||||
col_list = self.apply_identity_funcs(identity, df, list(df.columns))
|
||||
if len(col_list) != 0:
|
||||
return reduce((lambda x, y: pd.concat([x, y], axis=1)), col_list)
|
||||
else:
|
||||
return pd.DataFrame({'empty': []})
|
||||
|
||||
def generate_config(self, state_dict, mechanisms, exo_proc):
|
||||
def generate_config(self, initial_state, partial_state_updates, exo_proc):
|
||||
|
||||
def no_update_handler(bdf, sdf):
|
||||
if (bdf.empty == False) and (sdf.empty == True):
|
||||
bdf_values = bdf.values.tolist()
|
||||
sdf_values = [[self.no_state_identity] * len(bdf_values) for m in range(len(mechanisms))]
|
||||
sdf_values = [[self.no_state_identity] * len(bdf_values) for m in range(len(partial_state_updates))]
|
||||
return sdf_values, bdf_values
|
||||
elif (bdf.empty == True) and (sdf.empty == False):
|
||||
sdf_values = sdf.values.tolist()
|
||||
bdf_values = [[self.b_identity] * len(sdf_values) for m in range(len(mechanisms))]
|
||||
bdf_values = [[self.b_identity] * len(sdf_values) for m in range(len(partial_state_updates))]
|
||||
return sdf_values, bdf_values
|
||||
else:
|
||||
sdf_values = sdf.values.tolist()
|
||||
|
|
@ -113,19 +113,19 @@ class Processor:
|
|||
|
||||
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())
|
||||
lambda sub_step, sL, s, _input: (k, v) for k, v in zip(state_dict.keys(), state_dict.values())
|
||||
]
|
||||
sdf_values = [sdf_functions]
|
||||
bdf_values = [[self.b_identity] * len(sdf_values)]
|
||||
bdf_values = [[self.p_identity] * len(sdf_values)]
|
||||
return sdf_values, bdf_values
|
||||
|
||||
if len(mechanisms) != 0:
|
||||
bdf = self.create_matrix_field(mechanisms, 'behaviors')
|
||||
sdf = self.create_matrix_field(mechanisms, 'states')
|
||||
if len(partial_state_updates) != 0:
|
||||
bdf = self.create_matrix_field(partial_state_updates, 'policies')
|
||||
sdf = self.create_matrix_field(partial_state_updates, 'states')
|
||||
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)
|
||||
sdf_values, bdf_values = only_ep_handler(initial_state)
|
||||
zipped_list = list(zip(sdf_values, bdf_values))
|
||||
|
||||
return list(map(lambda x: (x[0] + exo_proc, x[1]), zipped_list))
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ class TensorFieldReport:
|
|||
def __init__(self, config_proc):
|
||||
self.config_proc = config_proc
|
||||
|
||||
def create_tensor_field(self, mechanisms, exo_proc, keys=['behaviors', 'states']):
|
||||
dfs = [self.config_proc.create_matrix_field(mechanisms, k) for k in keys]
|
||||
def create_tensor_field(self, partial_state_updates, exo_proc, keys=['policies', 'states']):
|
||||
dfs = [self.config_proc.create_matrix_field(partial_state_updates, k) for k in keys]
|
||||
df = pd.concat(dfs, axis=1)
|
||||
for es, i in zip(exo_proc, range(len(exo_proc))):
|
||||
df['es' + str(i + 1)] = es
|
||||
|
|
@ -25,7 +25,7 @@ class TensorFieldReport:
|
|||
#
|
||||
#
|
||||
def state_update(y, x):
|
||||
return lambda step, sL, s, _input: (y, x)
|
||||
return lambda sub_step, sL, s, _input: (y, x)
|
||||
|
||||
|
||||
def bound_norm_random(rng, low, high):
|
||||
|
|
@ -36,15 +36,15 @@ def bound_norm_random(rng, low, high):
|
|||
|
||||
|
||||
@curried
|
||||
def proc_trigger(trigger_step, update_f, step):
|
||||
if step == trigger_step:
|
||||
def proc_trigger(trigger_time, update_f, time):
|
||||
if time == trigger_time:
|
||||
return update_f
|
||||
else:
|
||||
return lambda x: x
|
||||
|
||||
|
||||
step_t_delta = timedelta(days=0, minutes=0, seconds=30)
|
||||
def time_step(dt_str, dt_format='%Y-%m-%d %H:%M:%S', _timedelta = step_t_delta):
|
||||
tstep_delta = timedelta(days=0, minutes=0, seconds=30)
|
||||
def time_step(dt_str, dt_format='%Y-%m-%d %H:%M:%S', _timedelta = tstep_delta):
|
||||
dt = datetime.strptime(dt_str, dt_format)
|
||||
t = dt + _timedelta
|
||||
return t.strftime(dt_format)
|
||||
|
|
@ -57,11 +57,11 @@ def ep_time_step(s, dt_str, fromat_str='%Y-%m-%d %H:%M:%S', _timedelta = ep_t_de
|
|||
else:
|
||||
return dt_str
|
||||
|
||||
|
||||
def mech_sweep_filter(mech_field, mechanisms):
|
||||
mech_dict = dict([(k, v[mech_field]) for k, v in mechanisms.items()])
|
||||
# mech_sweep_filter
|
||||
def partial_state_sweep_filter(state_field, partial_state_updates):
|
||||
partial_state_dict = dict([(k, v[state_field]) for k, v in partial_state_updates.items()])
|
||||
return dict([
|
||||
(k, dict_filter(v, lambda v: isinstance(v, list))) for k, v in mech_dict.items()
|
||||
(k, dict_filter(v, lambda v: isinstance(v, list))) for k, v in partial_state_dict.items()
|
||||
if contains_type(list(v.values()), list)
|
||||
])
|
||||
|
||||
|
|
@ -69,16 +69,18 @@ def mech_sweep_filter(mech_field, mechanisms):
|
|||
def state_sweep_filter(raw_exogenous_states):
|
||||
return dict([(k, v) for k, v in raw_exogenous_states.items() if isinstance(v, list)])
|
||||
|
||||
# sweep_mech_states
|
||||
@curried
|
||||
def sweep_mechs(_type, in_config):
|
||||
def sweep_partial_states(_type, in_config):
|
||||
configs = []
|
||||
filtered_mech_states = mech_sweep_filter(_type, in_config.mechanisms)
|
||||
if len(filtered_mech_states) > 0:
|
||||
for mech, state_dict in filtered_mech_states.items():
|
||||
# filtered_mech_states
|
||||
filtered_partial_states = partial_state_sweep_filter(_type, in_config.partial_state_updates)
|
||||
if len(filtered_partial_states) > 0:
|
||||
for partial_state, state_dict in filtered_partial_states.items():
|
||||
for state, state_funcs in state_dict.items():
|
||||
for f in state_funcs:
|
||||
config = deepcopy(in_config)
|
||||
config.mechanisms[mech][_type][state] = f
|
||||
config.partial_state_updates[partial_state][_type][state] = f
|
||||
configs.append(config)
|
||||
del config
|
||||
else:
|
||||
|
|
@ -111,9 +113,9 @@ def sweep_states(state_type, states, in_config):
|
|||
|
||||
def exo_update_per_ts(ep):
|
||||
@curried
|
||||
def ep_decorator(f, y, var_dict, step, sL, s, _input):
|
||||
def ep_decorator(f, y, var_dict, sub_step, sL, s, _input):
|
||||
if s['mech_step'] + 1 == 1:
|
||||
return f(var_dict, step, sL, s, _input) # curry_pot
|
||||
return f(var_dict, sub_step, sL, s, _input)
|
||||
else:
|
||||
return y, s[y]
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ def get_base_value(x):
|
|||
return 0
|
||||
|
||||
|
||||
def behavior_to_dict(v):
|
||||
def policy_to_dict(v):
|
||||
return dict(list(zip(map(lambda n: 'b' + str(n + 1), list(range(len(v)))), v)))
|
||||
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ class Executor:
|
|||
create_tensor_field = TensorFieldReport(config_proc).create_tensor_field
|
||||
|
||||
print(self.exec_context+": "+str(self.configs))
|
||||
var_dict_list, states_lists, Ts, Ns, eps, configs_structs, env_processes_list, mechanisms, simulation_execs = \
|
||||
var_dict_list, states_lists, Ts, Ns, eps, configs_structs, env_processes_list, partial_state_updates, simulation_execs = \
|
||||
[], [], [], [], [], [], [], [], []
|
||||
config_idx = 0
|
||||
for x in self.configs:
|
||||
|
|
@ -55,24 +55,24 @@ class Executor:
|
|||
Ts.append(x.sim_config['T'])
|
||||
Ns.append(x.sim_config['N'])
|
||||
var_dict_list.append(x.sim_config['M'])
|
||||
states_lists.append([x.state_dict])
|
||||
states_lists.append([x.initial_state])
|
||||
eps.append(list(x.exogenous_states.values()))
|
||||
configs_structs.append(config_proc.generate_config(x.state_dict, x.mechanisms, eps[config_idx]))
|
||||
configs_structs.append(config_proc.generate_config(x.initial_state, x.partial_state_updates, eps[config_idx]))
|
||||
env_processes_list.append(x.env_processes)
|
||||
mechanisms.append(x.mechanisms)
|
||||
simulation_execs.append(SimExecutor(x.behavior_ops).simulation)
|
||||
partial_state_updates.append(x.partial_state_updates)
|
||||
simulation_execs.append(SimExecutor(x.policy_ops).simulation)
|
||||
|
||||
config_idx += 1
|
||||
|
||||
if self.exec_context == ExecutionMode.single_proc:
|
||||
tensor_field = create_tensor_field(mechanisms.pop(), eps.pop())
|
||||
tensor_field = create_tensor_field(partial_state_updates.pop(), eps.pop())
|
||||
result = self.exec_method(simulation_execs, var_dict_list, states_lists, configs_structs, env_processes_list, Ts, Ns)
|
||||
return result, tensor_field
|
||||
elif self.exec_context == ExecutionMode.multi_proc:
|
||||
if len(self.configs) > 1:
|
||||
simulations = self.exec_method(simulation_execs, var_dict_list, states_lists, configs_structs, env_processes_list, Ts, Ns)
|
||||
results = []
|
||||
for result, mechanism, ep in list(zip(simulations, mechanisms, eps)):
|
||||
results.append((flatten(result), create_tensor_field(mechanism, ep)))
|
||||
for result, partial_state_updates, ep in list(zip(simulations, partial_state_updates, eps)):
|
||||
results.append((flatten(result), create_tensor_field(partial_state_updates, ep)))
|
||||
|
||||
return results
|
||||
|
|
|
|||
|
|
@ -7,41 +7,39 @@ id_exception = engine_exception(KeyError, KeyError, None)
|
|||
|
||||
|
||||
class Executor:
|
||||
def __init__(self, behavior_ops, behavior_update_exception=id_exception, state_update_exception=id_exception):
|
||||
self.behavior_ops = behavior_ops
|
||||
def __init__(self, policy_ops, policy_update_exception=id_exception, state_update_exception=id_exception):
|
||||
self.policy_ops = policy_ops # behavior_ops
|
||||
self.state_update_exception = state_update_exception
|
||||
self.behavior_update_exception = behavior_update_exception
|
||||
self.policy_update_exception = policy_update_exception # behavior_update_exception
|
||||
|
||||
def get_behavior_input(self, var_dict, step, sL, s, funcs):
|
||||
ops = self.behavior_ops[::-1]
|
||||
# get_behavior_input
|
||||
def get_policy_input(self, var_dict, sub_step, sL, s, funcs):
|
||||
ops = self.policy_ops[::-1]
|
||||
|
||||
def get_col_results(var_dict, step, sL, s, funcs):
|
||||
# return list(map(lambda f: curry_pot(f, step, sL, s), funcs))
|
||||
return list(map(lambda f: f(var_dict, step, sL, s), funcs))
|
||||
def get_col_results(var_dict, sub_step, sL, s, funcs):
|
||||
return list(map(lambda f: f(var_dict, sub_step, sL, s), funcs))
|
||||
|
||||
# print(get_col_results(step, sL, s, funcs))
|
||||
return foldr(call, get_col_results(var_dict, step, sL, s, funcs))(ops)
|
||||
return foldr(call, get_col_results(var_dict, sub_step, sL, s, funcs))(ops)
|
||||
|
||||
def apply_env_proc(self, env_processes, state_dict, step):
|
||||
def apply_env_proc(self, env_processes, state_dict, sub_step):
|
||||
for state in state_dict.keys():
|
||||
if state in list(env_processes.keys()):
|
||||
env_state = env_processes[state]
|
||||
if (env_state.__name__ == '_curried') or (env_state.__name__ == 'proc_trigger'):
|
||||
state_dict[state] = env_state(step)(state_dict[state])
|
||||
state_dict[state] = env_state(sub_step)(state_dict[state])
|
||||
else:
|
||||
state_dict[state] = env_state(state_dict[state])
|
||||
|
||||
def mech_step(self, var_dict, m_step, sL, state_funcs, behavior_funcs, env_processes, t_step, run):
|
||||
# mech_step
|
||||
def partial_state_update(self, var_dict, sub_step, sL, state_funcs, policy_funcs, env_processes, time_step, run):
|
||||
last_in_obj = sL[-1]
|
||||
|
||||
_input = self.behavior_update_exception(self.get_behavior_input(var_dict, m_step, sL, last_in_obj, behavior_funcs))
|
||||
# print(_input)
|
||||
_input = self.policy_update_exception(self.get_policy_input(var_dict, sub_step, sL, last_in_obj, policy_funcs))
|
||||
|
||||
# ToDo: add env_proc generator to `last_in_copy` iterator as wrapper function
|
||||
last_in_copy = dict(
|
||||
[
|
||||
# self.state_update_exception(curry_pot(f, m_step, sL, last_in_obj, _input)) for f in state_funcs
|
||||
self.state_update_exception(f(var_dict, m_step, sL, last_in_obj, _input)) for f in state_funcs
|
||||
self.state_update_exception(f(var_dict, sub_step, sL, last_in_obj, _input)) for f in state_funcs
|
||||
]
|
||||
)
|
||||
|
||||
|
|
@ -53,48 +51,47 @@ class Executor:
|
|||
|
||||
self.apply_env_proc(env_processes, last_in_copy, last_in_copy['timestamp'])
|
||||
|
||||
last_in_copy["mech_step"], last_in_copy["time_step"], last_in_copy['run'] = m_step, t_step, run
|
||||
last_in_copy["mech_step"], last_in_copy["time_step"], last_in_copy['run'] = sub_step, time_step, run
|
||||
sL.append(last_in_copy)
|
||||
del last_in_copy
|
||||
|
||||
return sL
|
||||
|
||||
def mech_pipeline(self, var_dict, states_list, configs, env_processes, t_step, run):
|
||||
m_step = 0
|
||||
# mech_pipeline
|
||||
def state_update_pipeline(self, var_dict, states_list, configs, env_processes, time_step, run):
|
||||
sub_step = 0
|
||||
states_list_copy = deepcopy(states_list)
|
||||
genesis_states = states_list_copy[-1]
|
||||
genesis_states['mech_step'], genesis_states['time_step'] = m_step, t_step
|
||||
genesis_states['mech_step'], genesis_states['time_step'] = sub_step, time_step
|
||||
states_list = [genesis_states]
|
||||
|
||||
m_step += 1
|
||||
sub_step += 1
|
||||
for config in configs:
|
||||
s_conf, b_conf = config[0], config[1]
|
||||
states_list = self.mech_step(var_dict, m_step, states_list, s_conf, b_conf, env_processes, t_step, run)
|
||||
m_step += 1
|
||||
s_conf, p_conf = config[0], config[1]
|
||||
states_list = self.partial_state_update(var_dict, sub_step, states_list, s_conf, p_conf, env_processes, time_step, run)
|
||||
sub_step += 1
|
||||
|
||||
t_step += 1
|
||||
time_step += 1
|
||||
|
||||
return states_list
|
||||
|
||||
# ToDo: Rename Run Pipeline
|
||||
def block_pipeline(self, var_dict, states_list, configs, env_processes, time_seq, run):
|
||||
def run_pipeline(self, var_dict, states_list, configs, env_processes, time_seq, run):
|
||||
time_seq = [x + 1 for x in time_seq]
|
||||
simulation_list = [states_list]
|
||||
for time_step in time_seq:
|
||||
pipe_run = self.mech_pipeline(var_dict, simulation_list[-1], configs, env_processes, time_step, run)
|
||||
pipe_run = self.state_update_pipeline(var_dict, simulation_list[-1], configs, env_processes, time_step, run)
|
||||
_, *pipe_run = pipe_run
|
||||
simulation_list.append(pipe_run)
|
||||
|
||||
return simulation_list
|
||||
|
||||
|
||||
# ToDo: Muiltithreaded Runs
|
||||
def simulation(self, var_dict, states_list, configs, env_processes, time_seq, runs):
|
||||
pipe_run = []
|
||||
for run in range(runs):
|
||||
run += 1
|
||||
states_list_copy = deepcopy(states_list)
|
||||
head, *tail = self.block_pipeline(var_dict, states_list_copy, configs, env_processes, time_seq, run)
|
||||
head, *tail = self.run_pipeline(var_dict, states_list_copy, configs, env_processes, time_seq, run)
|
||||
genesis = head.pop()
|
||||
genesis['mech_step'], genesis['time_step'], genesis['run'] = 0, 0, run
|
||||
first_timestep_per_run = [genesis] + tail.pop(0)
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ def retrieve_state(l, offset):
|
|||
return l[last_index(l) + offset + 1]
|
||||
|
||||
|
||||
# exception_function = f(m_step, sL, sL[-2], _input)
|
||||
# try_function = f(m_step, sL, last_mut_obj, _input)
|
||||
# exception_function = f(sub_step, sL, sL[-2], _input)
|
||||
# try_function = f(sub_step, sL, last_mut_obj, _input)
|
||||
@curried
|
||||
def engine_exception(ErrorType, error_message, exception_function, try_function):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from collections import defaultdict
|
||||
from itertools import product
|
||||
|
||||
import warnings
|
||||
|
||||
def pipe(x):
|
||||
return x
|
||||
|
|
@ -77,6 +77,13 @@ def drop_right(l, n):
|
|||
|
||||
|
||||
def key_filter(l, keyname):
|
||||
if (type(l) == list):
|
||||
return [v[keyname] for v in l]
|
||||
# Keeping support to dictionaries for backwards compatibility
|
||||
# Should be removed in the future
|
||||
warnings.warn(
|
||||
"The use of a dictionary to describe Partial State Update Blocks will be deprecated. Use a list instead.",
|
||||
FutureWarning)
|
||||
return [v[keyname] for k, v in l.items()]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from SimCAD.configuration.utils import proc_trigger, bound_norm_random, ep_time_
|
|||
from SimCAD.configuration.utils.parameterSweep import config_sim
|
||||
|
||||
|
||||
seed = {
|
||||
seeds = {
|
||||
'z': np.random.RandomState(1),
|
||||
'a': np.random.RandomState(2),
|
||||
'b': np.random.RandomState(3),
|
||||
|
|
@ -15,20 +15,20 @@ seed = {
|
|||
}
|
||||
|
||||
|
||||
# Behaviors per Mechanism
|
||||
def b1m1(_g, step, sL, s):
|
||||
# Policies per Mechanism
|
||||
def p1m1(_g, step, sL, s):
|
||||
return {'param1': 1}
|
||||
def b2m1(_g, step, sL, s):
|
||||
def p2m1(_g, step, sL, s):
|
||||
return {'param2': 4}
|
||||
|
||||
def b1m2(_g, step, sL, s):
|
||||
def p1m2(_g, step, sL, s):
|
||||
return {'param1': 'a', 'param2': 2}
|
||||
def b2m2(_g, step, sL, s):
|
||||
def p2m2(_g, step, sL, s):
|
||||
return {'param1': 'b', 'param2': 4}
|
||||
|
||||
def b1m3(_g, step, sL, s):
|
||||
def p1m3(_g, step, sL, s):
|
||||
return {'param1': ['c'], 'param2': np.array([10, 100])}
|
||||
def b2m3(_g, step, sL, s):
|
||||
def p2m3(_g, step, sL, s):
|
||||
return {'param1': ['d'], 'param2': np.array([20, 200])}
|
||||
|
||||
|
||||
|
|
@ -67,12 +67,12 @@ proc_one_coef_B = 1.3
|
|||
|
||||
def es3p1(_g, step, sL, s, _input):
|
||||
y = 's3'
|
||||
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
|
||||
x = s['s3'] * bound_norm_random(seeds['a'], proc_one_coef_A, proc_one_coef_B)
|
||||
return (y, x)
|
||||
|
||||
def es4p2(_g, step, sL, s, _input):
|
||||
y = 's4'
|
||||
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
|
||||
x = s['s4'] * bound_norm_random(seeds['b'], proc_one_coef_A, proc_one_coef_B)
|
||||
return (y, x)
|
||||
|
||||
ts_format = '%Y-%m-%d %H:%M:%S'
|
||||
|
|
@ -115,11 +115,11 @@ env_processes = {
|
|||
}
|
||||
|
||||
|
||||
mechanisms = {
|
||||
partial_state_update_block = {
|
||||
"m1": {
|
||||
"behaviors": {
|
||||
"b1": b1m1,
|
||||
"b2": b2m1
|
||||
"policies": {
|
||||
"b1": p1m1,
|
||||
"b2": p2m1
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m1,
|
||||
|
|
@ -127,9 +127,9 @@ mechanisms = {
|
|||
}
|
||||
},
|
||||
"m2": {
|
||||
"behaviors": {
|
||||
"b1": b1m2,
|
||||
"b2": b2m2
|
||||
"policies": {
|
||||
"b1": p1m2,
|
||||
"b2": p2m2
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m2,
|
||||
|
|
@ -137,9 +137,9 @@ mechanisms = {
|
|||
}
|
||||
},
|
||||
"m3": {
|
||||
"behaviors": {
|
||||
"b1": b1m3,
|
||||
"b2": b2m3
|
||||
"policies": {
|
||||
"b1": p1m3,
|
||||
"b2": p2m3
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m3,
|
||||
|
|
@ -159,9 +159,9 @@ sim_config = config_sim(
|
|||
|
||||
append_configs(
|
||||
sim_configs=sim_config,
|
||||
state_dict=genesis_states,
|
||||
seed=seed,
|
||||
initial_state=genesis_states,
|
||||
seeds=seeds,
|
||||
raw_exogenous_states=raw_exogenous_states,
|
||||
env_processes=env_processes,
|
||||
mechanisms=mechanisms
|
||||
partial_state_updates=partial_state_update_block
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from SimCAD.configuration import append_configs
|
|||
from SimCAD.configuration.utils import proc_trigger, bound_norm_random, ep_time_step
|
||||
from SimCAD.configuration.utils.parameterSweep import config_sim
|
||||
|
||||
seed = {
|
||||
seeds = {
|
||||
'z': np.random.RandomState(1),
|
||||
'a': np.random.RandomState(2),
|
||||
'b': np.random.RandomState(3),
|
||||
|
|
@ -14,20 +14,20 @@ seed = {
|
|||
}
|
||||
|
||||
|
||||
# Behaviors per Mechanism
|
||||
def b1m1(_g, step, sL, s):
|
||||
# Policies per Mechanism
|
||||
def p1m1(_g, step, sL, s):
|
||||
return {'param1': 1}
|
||||
def b2m1(_g, step, sL, s):
|
||||
def p2m1(_g, step, sL, s):
|
||||
return {'param2': 4}
|
||||
|
||||
def b1m2(_g, step, sL, s):
|
||||
def p1m2(_g, step, sL, s):
|
||||
return {'param1': 'a', 'param2': 2}
|
||||
def b2m2(_g, step, sL, s):
|
||||
def p2m2(_g, step, sL, s):
|
||||
return {'param1': 'b', 'param2': 4}
|
||||
|
||||
def b1m3(_g, step, sL, s):
|
||||
def p1m3(_g, step, sL, s):
|
||||
return {'param1': ['c'], 'param2': np.array([10, 100])}
|
||||
def b2m3(_g, step, sL, s):
|
||||
def p2m3(_g, step, sL, s):
|
||||
return {'param1': ['d'], 'param2': np.array([20, 200])}
|
||||
|
||||
|
||||
|
|
@ -66,12 +66,12 @@ proc_one_coef_B = 1.3
|
|||
|
||||
def es3p1(_g, step, sL, s, _input):
|
||||
y = 's3'
|
||||
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
|
||||
x = s['s3'] * bound_norm_random(seeds['a'], proc_one_coef_A, proc_one_coef_B)
|
||||
return (y, x)
|
||||
|
||||
def es4p2(_g, step, sL, s, _input):
|
||||
y = 's4'
|
||||
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
|
||||
x = s['s4'] * bound_norm_random(seeds['b'], proc_one_coef_A, proc_one_coef_B)
|
||||
return (y, x)
|
||||
|
||||
ts_format = '%Y-%m-%d %H:%M:%S'
|
||||
|
|
@ -114,11 +114,11 @@ env_processes = {
|
|||
}
|
||||
|
||||
|
||||
mechanisms = {
|
||||
partial_state_update_block = {
|
||||
"m1": {
|
||||
"behaviors": {
|
||||
"b1": b1m1,
|
||||
# "b2": b2m1
|
||||
"policies": {
|
||||
"b1": p1m1,
|
||||
# "b2": p2m1
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m1,
|
||||
|
|
@ -126,9 +126,9 @@ mechanisms = {
|
|||
}
|
||||
},
|
||||
"m2": {
|
||||
"behaviors": {
|
||||
"b1": b1m2,
|
||||
# "b2": b2m2
|
||||
"policies": {
|
||||
"b1": p1m2,
|
||||
# "b2": p2m2
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m2,
|
||||
|
|
@ -136,9 +136,9 @@ mechanisms = {
|
|||
}
|
||||
},
|
||||
"m3": {
|
||||
"behaviors": {
|
||||
"b1": b1m3,
|
||||
"b2": b2m3
|
||||
"policies": {
|
||||
"b1": p1m3,
|
||||
"b2": p2m3
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m3,
|
||||
|
|
@ -158,9 +158,9 @@ sim_config = config_sim(
|
|||
|
||||
append_configs(
|
||||
sim_configs=sim_config,
|
||||
state_dict=genesis_states,
|
||||
seed=seed,
|
||||
initial_state=genesis_states,
|
||||
seeds=seeds,
|
||||
raw_exogenous_states=raw_exogenous_states,
|
||||
env_processes=env_processes,
|
||||
mechanisms=mechanisms
|
||||
partial_state_updates=partial_state_update_block
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from SimCAD.configuration.utils.parameterSweep import config_sim
|
|||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
seed = {
|
||||
seeds = {
|
||||
'z': np.random.RandomState(1),
|
||||
'a': np.random.RandomState(2),
|
||||
'b': np.random.RandomState(3),
|
||||
|
|
@ -24,23 +24,23 @@ g = {
|
|||
'omega': [7]
|
||||
}
|
||||
|
||||
# Behaviors per Mechanism
|
||||
def b1m1(_g, step, sL, s):
|
||||
# Policies per Mechanism
|
||||
def p1m1(_g, step, sL, s):
|
||||
return {'param1': 1}
|
||||
|
||||
def b2m1(_g, step, sL, s):
|
||||
def p2m1(_g, step, sL, s):
|
||||
return {'param2': 4}
|
||||
|
||||
def b1m2(_g, step, sL, s):
|
||||
def p1m2(_g, step, sL, s):
|
||||
return {'param1': 'a', 'param2': _g['beta']}
|
||||
|
||||
def b2m2(_g, step, sL, s):
|
||||
def p2m2(_g, step, sL, s):
|
||||
return {'param1': 'b', 'param2': 0}
|
||||
|
||||
def b1m3(_g, step, sL, s):
|
||||
def p1m3(_g, step, sL, s):
|
||||
return {'param1': np.array([10, 100])}
|
||||
|
||||
def b2m3(_g, step, sL, s):
|
||||
def p2m3(_g, step, sL, s):
|
||||
return {'param1': np.array([20, 200])}
|
||||
|
||||
# Internal States per Mechanism
|
||||
|
|
@ -143,11 +143,11 @@ env_processes = {
|
|||
# sweep exo_state func and point to exo-state in every other funtion
|
||||
# param sweep on genesis states
|
||||
|
||||
mechanisms = {
|
||||
partial_state_update_block = {
|
||||
"m1": {
|
||||
"behaviors": {
|
||||
"b1": b1m1,
|
||||
"b2": b2m1
|
||||
"policies": {
|
||||
"b1": p1m1,
|
||||
"b2": p2m1
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m1,
|
||||
|
|
@ -155,9 +155,9 @@ mechanisms = {
|
|||
}
|
||||
},
|
||||
"m2": {
|
||||
"behaviors": {
|
||||
"b1": b1m2,
|
||||
"b2": b2m2,
|
||||
"policies": {
|
||||
"b1": p1m2,
|
||||
"b2": p2m2,
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m2,
|
||||
|
|
@ -165,9 +165,9 @@ mechanisms = {
|
|||
}
|
||||
},
|
||||
"m3": {
|
||||
"behaviors": {
|
||||
"b1": b1m3,
|
||||
"b2": b2m3
|
||||
"policies": {
|
||||
"b1": p1m3,
|
||||
"b2": p2m3
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m3,
|
||||
|
|
@ -188,9 +188,9 @@ sim_config = config_sim(
|
|||
|
||||
append_configs(
|
||||
sim_configs=sim_config,
|
||||
state_dict=genesis_states,
|
||||
seed=seed,
|
||||
initial_state=genesis_states,
|
||||
seeds=seeds,
|
||||
raw_exogenous_states=raw_exogenous_states,
|
||||
env_processes=env_processes,
|
||||
mechanisms=mechanisms
|
||||
partial_state_updates=partial_state_update_block
|
||||
)
|
||||
Loading…
Reference in New Issue