From 522d6dd34307cd6ddfc380c15f4c945c19791567 Mon Sep 17 00:00:00 2001 From: "Joshua E. Jodesty" Date: Wed, 13 Feb 2019 08:16:58 -0500 Subject: [PATCH] param sweep full spec working pre-release --- SimCAD/configuration/__init__.py | 24 ++- SimCAD/configuration/utils/__init__.py | 6 +- SimCAD/configuration/utils/parameterSweep.py | 20 ++- SimCAD/engine/__init__.py | 6 +- simulations/validation/base_config1.py | 171 ------------------ simulations/validation/base_config2.py | 180 ------------------- simulations/validation/config1.py | 71 +++----- simulations/validation/config_1.py | 178 ------------------ simulations/validation/config_2.py | 180 ------------------- 9 files changed, 56 insertions(+), 780 deletions(-) delete mode 100644 simulations/validation/base_config1.py delete mode 100644 simulations/validation/base_config2.py delete mode 100644 simulations/validation/config_1.py delete mode 100644 simulations/validation/config_2.py diff --git a/SimCAD/configuration/__init__.py b/SimCAD/configuration/__init__.py index 248c9b0..bd5e063 100644 --- a/SimCAD/configuration/__init__.py +++ b/SimCAD/configuration/__init__.py @@ -10,7 +10,6 @@ from SimCAD.configuration.utils.behaviorAggregation 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())]): @@ -23,30 +22,29 @@ class Configuration(object): self.behavior_ops = behavior_ops -def append_configs(sim_config, genesis_states, seed, raw_exogenous_states, env_processes, mechanisms, _exo_update_per_ts=True): - if 'M' in sim_config.keys(): +def append_configs(sim_configs, state_dict, seed, raw_exogenous_states, env_processes, mechanisms, _exo_update_per_ts=True): + if _exo_update_per_ts is True: + exogenous_states = exo_update_per_ts(raw_exogenous_states) + else: + exogenous_states = raw_exogenous_states - for mechanisms, exogenous_states in sim_config['M']: + if isinstance(sim_configs, list): + for sim_config in sim_configs: configs.append( Configuration( sim_config=sim_config, - state_dict=genesis_states, + state_dict=state_dict, seed=seed, exogenous_states=exogenous_states, env_processes=env_processes, mechanisms=mechanisms ) ) - else: - if _exo_update_per_ts is True: - exogenous_states = exo_update_per_ts(raw_exogenous_states) - else: - exogenous_states = raw_exogenous_states - + elif isinstance(sim_configs, dict): configs.append( Configuration( - sim_config=sim_config, - state_dict=genesis_states, + sim_config=sim_configs, + state_dict=state_dict, seed=seed, exogenous_states=exogenous_states, env_processes=env_processes, diff --git a/SimCAD/configuration/utils/__init__.py b/SimCAD/configuration/utils/__init__.py index c21f57c..68b68ab 100644 --- a/SimCAD/configuration/utils/__init__.py +++ b/SimCAD/configuration/utils/__init__.py @@ -113,14 +113,12 @@ def sweep_states(state_type, states, in_config): def exo_update_per_ts(ep): @curried - def ep_decorator(f, y, step, sL, s, _input): + def ep_decorator(f, y, var_dict, step, sL, s, _input): if s['mech_step'] + 1 == 1: - return curry_pot(f, step, sL, s, _input) + return f(var_dict, step, sL, s, _input) # curry_pot else: return y, s[y] return {es: ep_decorator(f, es) for es, f in ep.items()} -def process_variables(d): - return flatten_tabulated_dict(tabulate_dict(d)) \ No newline at end of file diff --git a/SimCAD/configuration/utils/parameterSweep.py b/SimCAD/configuration/utils/parameterSweep.py index 1c9815f..3801b5f 100644 --- a/SimCAD/configuration/utils/parameterSweep.py +++ b/SimCAD/configuration/utils/parameterSweep.py @@ -2,10 +2,28 @@ import inspect from copy import deepcopy from funcy import curry -from SimCAD.utils import rename +from SimCAD.utils import rename, flatten_tabulated_dict, tabulate_dict from SimCAD.configuration.utils import exo_update_per_ts +def process_variables(d): + return flatten_tabulated_dict(tabulate_dict(d)) + + +def config_sim(d): + if "M" in d: + return [ + { + "N": d["N"], + "T": d["T"], + "M": M + } + for M in process_variables(d["M"]) + ] + else: + return d + + class ParamSweep: def __init__(self, sweep_list, mechs=None, raw_exogenous_states=None, _exo_update_per_ts=True): self.sweep_list = sweep_list diff --git a/SimCAD/engine/__init__.py b/SimCAD/engine/__init__.py index 3a31be6..5c05c1b 100644 --- a/SimCAD/engine/__init__.py +++ b/SimCAD/engine/__init__.py @@ -51,10 +51,12 @@ class Executor: [], [], [], [], [], [], [], [], [] config_idx = 0 for x in self.configs: - var_dict_list.append(x.sim_config['M']) - states_lists.append([x.state_dict]) + 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]) eps.append(list(x.exogenous_states.values())) configs_structs.append(config_proc.generate_config(x.state_dict, x.mechanisms, eps[config_idx])) env_processes_list.append(x.env_processes) diff --git a/simulations/validation/base_config1.py b/simulations/validation/base_config1.py deleted file mode 100644 index 3bf83ba..0000000 --- a/simulations/validation/base_config1.py +++ /dev/null @@ -1,171 +0,0 @@ -from decimal import Decimal -import numpy as np -from datetime import timedelta - -from SimCAD import configs -from SimCAD.configuration import Configuration -from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \ - ep_time_step - -seed = { - 'z': np.random.RandomState(1), - 'a': np.random.RandomState(2), - 'b': np.random.RandomState(3), - 'c': np.random.RandomState(3) -} - -# Behaviors per Mechanism -# Different return types per mechanism ?? *** No *** -def b1m1(step, sL, s): - return {'param1': 1} -def b2m1(step, sL, s): - return {'param1': 1} - -def b1m2(step, sL, s): - return {'param1': 1, 'param2': 2} -def b2m2(step, sL, s): - return {'param1': 1, 'param2': 4} - -def b1m3(step, sL, s): - return {'param1': 1, 'param2': np.array([10, 100])} -def b2m3(step, sL, s): - return {'param1': 1, 'param2': np.array([20, 200])} - -# deff not more than 2 -# Internal States per Mechanism -def s1m1(step, sL, s, _input): - y = 's1' - x = s['s1'] + _input['param1'] - return (y, x) -def s2m1(step, sL, s, _input): - y = 's2' - x = s['s2'] + _input['param1'] - return (y, x) - -def s1m2(step, sL, s, _input): - y = 's1' - x = s['s1'] + _input['param1'] - return (y, x) -def s2m2(step, sL, s, _input): - y = 's2' - x = s['s2'] + _input['param1'] - return (y, x) - -def s1m3(step, sL, s, _input): - y = 's1' - x = s['s1'] + _input['param1'] - return (y, x) -def s2m3(step, sL, s, _input): - y = 's2' - x = s['s2'] + _input['param1'] - return (y, x) - -# 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) - -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) - -ts_format = '%Y-%m-%d %H:%M:%S' -t_delta = timedelta(days=0, minutes=0, seconds=1) -def es5p2(step, sL, s, _input): - y = 'timestamp' - x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta) - return (y, x) - - -# Environment States -def env_a(x): - return 10 -def env_b(x): - return 10 -# def what_ever(x): -# return x + 1 - -# Genesis States -genesis_states = { - 's1': Decimal(0.0), - 's2': Decimal(0.0), - 's3': Decimal(1.0), - 's4': Decimal(1.0), - 'timestamp': '2018-10-01 15:16:24' -} - -# remove `exo_update_per_ts` to update every ts -exogenous_states = exo_update_per_ts( - { - "s3": es3p1, - "s4": es4p2, - "timestamp": es5p2 - } -) - -# make env proc trigger field agnostic - -# ToDo: Bug - Can't use environments without proc_trigger. TypeError: 'int' object is not callable -# "/Users/jjodesty/Projects/DiffyQ-SimCAD/SimCAD/engine/simulation.py" -env_processes = { - # "s3": env_a, - # "s4": env_b - "s3": proc_trigger('2018-10-01 15:16:25', env_a), - "s4": proc_trigger('2018-10-01 15:16:25', env_b) -} - -# need at least 1 behaviour and 1 state function for the 1st mech with behaviors -# mechanisms = {} -mechanisms = { - "m1": { - "behaviors": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, - "b2": b2m1 - }, - "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value - "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": 2, - "T": range(5) -} - -configs.append( - Configuration( - sim_config=sim_config, - state_dict=genesis_states, - seed=seed, - exogenous_states=exogenous_states, - env_processes=env_processes, - mechanisms=mechanisms - ) -) \ No newline at end of file diff --git a/simulations/validation/base_config2.py b/simulations/validation/base_config2.py deleted file mode 100644 index 6b9469e..0000000 --- a/simulations/validation/base_config2.py +++ /dev/null @@ -1,180 +0,0 @@ -from decimal import Decimal -import numpy as np -from datetime import timedelta - -from SimCAD import configs -from SimCAD.configuration import Configuration -from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \ - ep_time_step - - -seed = { - 'z': np.random.RandomState(1), - 'a': np.random.RandomState(2), - 'b': np.random.RandomState(3), - 'c': np.random.RandomState(3) -} - -# Behaviors per Mechanism -# Different return types per mechanism ?? *** No *** -def b1m1(step, sL, s): - return {'param1': 1} -def b2m1(step, sL, s): - return {'param2': 4} - -def b1m2(step, sL, s): - return {'param1': 'a', 'param2': 2} -def b2m2(step, sL, s): - return {'param1': 'b', 'param2': 4} - - -def b1m3(step, sL, s): - return {'param1': ['c'], 'param2': np.array([10, 100])} -def b2m3(step, sL, s): - return {'param1': ['d'], 'param2': np.array([20, 200])} - - -# Internal States per Mechanism -def s1m1(step, sL, s, _input): - y = 's1' - x = _input['param1'] - return (y, x) -def s2m1(step, sL, s, _input): - y = 's2' - x = _input['param2'] - return (y, x) - -def s1m2(step, sL, s, _input): - y = 's1' - x = _input['param1'] - return (y, x) -def s2m2(step, sL, s, _input): - y = 's2' - x = _input['param2'] - return (y, x) - -def s1m3(step, sL, s, _input): - y = 's1' - x = _input['param1'] - return (y, x) -def s2m3(step, sL, s, _input): - y = 's2' - x = _input['param2'] - return (y, x) - -# 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) - -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) - -ts_format = '%Y-%m-%d %H:%M:%S' -t_delta = timedelta(days=0, minutes=0, seconds=1) -def es5p2(step, sL, s, _input): - y = 'timestamp' - x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta) - return (y, x) - - -# Environment States -def env_a(x): - return 10 -def env_b(x): - return 10 -# def what_ever(x): -# return x + 1 - -# Genesis States -genesis_states = { - 's1': Decimal(0.0), - 's2': Decimal(0.0), - 's3': Decimal(1.0), - 's4': Decimal(1.0), - 'timestamp': '2018-10-01 15:16:24' -} - -# remove `exo_update_per_ts` to update every ts -# why `exo_update_per_ts` here instead of `env_processes` -exogenous_states = exo_update_per_ts( - { - "s3": es3p1, - "s4": es4p2, - "timestamp": es5p2 - } -) - -# 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) -} - -# lambdas -# genesis Sites should always be there -# [1, 2] -# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ] - - -# [1, 2] = {'b1': ['a'], 'b2', [1]} = -# behavior_ops = [behavior_to_dict, print_fwd, sum_dict_values] -# behavior_ops = [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": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, - # "b2": b2m1 - }, - "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value - "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": 2, - "T": range(5) -} - -configs.append( - Configuration( - sim_config=sim_config, - state_dict=genesis_states, - seed=seed, - exogenous_states=exogenous_states, - env_processes=env_processes, - mechanisms=mechanisms - ) -) \ No newline at end of file diff --git a/simulations/validation/config1.py b/simulations/validation/config1.py index b67d04e..e2d1880 100644 --- a/simulations/validation/config1.py +++ b/simulations/validation/config1.py @@ -3,9 +3,9 @@ import numpy as np from datetime import timedelta import pprint -from SimCAD import configs -from SimCAD.configuration import Configuration -from SimCAD.configuration.utils import proc_trigger, ep_time_step, process_variables, exo_update_per_ts +from SimCAD.configuration import append_configs +from SimCAD.configuration.utils import proc_trigger, ep_time_step +from SimCAD.configuration.utils.parameterSweep import config_sim pp = pprint.PrettyPrinter(indent=4) @@ -24,11 +24,6 @@ g = { 'omega': [7] } - -# beta = 1 - -# middleware(f1,f2,f3,f4) - # Behaviors per Mechanism def b1m1(_g, step, sL, s): return {'param1': 1} @@ -41,15 +36,14 @@ def b1m2(_g, step, sL, s): def b2m2(_g, step, sL, s): return {'param1': 'b', 'param2': 0} -# @curried + def b1m3(_g, step, sL, s): return {'param1': np.array([10, 100])} -# @curried + def b2m3(_g, step, sL, s): return {'param1': np.array([20, 200])} # Internal States per Mechanism -# @curried def s1m1(_g, step, sL, s, _input): y = 's1' x = 0 @@ -126,7 +120,7 @@ genesis_states = { # remove `exo_update_per_ts` to update every ts raw_exogenous_states = { - "s3": es3p1, #es3p1, #sweep(beta, es3p1), + "s3": es3p1, "s4": es4p2, "timestamp": es5p2 } @@ -135,8 +129,6 @@ raw_exogenous_states = { # ToDo: make env proc trigger field agnostic # ToDo: input json into function renaming __name__ triggered_env_b = proc_trigger('2018-10-01 15:16:25', env_b) - - env_processes = { "s3": env_a, #sweep(beta, env_a), "s4": triggered_env_b #rename('parameterized', triggered_env_b) #sweep(beta, triggered_env_b) @@ -185,43 +177,20 @@ mechanisms = { } -# process_variables(g) -def gen_sim_configs(N, T, Ms): - return [ - { - "N": 2, - "T": range(5), - "M": M - } - for M in process_variables(Ms) - ] - - -sim_configs = gen_sim_configs( - N=2, - T=range(5), - Ms=g +sim_config = config_sim( + { + "N": 2, + "T": range(5), + "M": g + } ) -for sim_config in sim_configs: - configs.append( - Configuration( - sim_config=sim_config, - state_dict=genesis_states, - seed=seed, - exogenous_states=raw_exogenous_states, # exo_update_per_ts - env_processes=env_processes, - mechanisms=mechanisms - ) - ) - -# append_configs( -# sim_config=sim_config, -# genesis_states=genesis_states, -# seed=seed, -# raw_exogenous_states=raw_exogenous_states, -# env_processes=env_processes, -# mechanisms=mechanisms, -# _exo_update_per_ts=True #Default -# ) \ No newline at end of file +append_configs( + sim_configs=sim_config, + state_dict=genesis_states, + seed=seed, + raw_exogenous_states=raw_exogenous_states, + env_processes=env_processes, + mechanisms=mechanisms +) \ No newline at end of file diff --git a/simulations/validation/config_1.py b/simulations/validation/config_1.py deleted file mode 100644 index 7bdd5ac..0000000 --- a/simulations/validation/config_1.py +++ /dev/null @@ -1,178 +0,0 @@ -from decimal import Decimal -import numpy as np -from datetime import timedelta - -from SimCAD import configs -from SimCAD.configuration import Configuration -from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \ - ep_time_step - -seed = { - 'z': np.random.RandomState(1), - 'a': np.random.RandomState(2), - 'b': np.random.RandomState(3), - 'c': np.random.RandomState(3) -} - -# Behaviors per Mechanism -# Different return types per mechanism ?? *** No *** -def b1m1(step, sL, s): - return {'param1': 1} -def b2m1(step, sL, s): - return {'param2': 4} - -def b1m2(step, sL, s): - return {'param1': 'a', 'param2': 2} -def b2m2(step, sL, s): - return {'param1': 'b', 'param2': 4} - -def b1m3(step, sL, s): - return {'param1': ['c'], 'param2': np.array([10, 100])} -def b2m3(step, sL, s): - return {'param1': ['d'], 'param2': np.array([20, 200])} - -# deff not more than 2 -# Internal States per Mechanism -def s1m1(step, sL, s, _input): - y = 's1' - x = _input['param1'] #+ [Coef1 x 5] - return (y, x) -def s2m1(step, sL, s, _input): - y = 's2' - x = _input['param2'] #+ [Coef2 x 5] - return (y, x) - -def s1m2(step, sL, s, _input): - y = 's1' - x = _input['param1'] - return (y, x) -def s2m2(step, sL, s, _input): - y = 's2' - x = _input['param2'] - return (y, x) - -def s1m3(step, sL, s, _input): - y = 's1' - x = _input['param1'] - return (y, x) -def s2m3(step, sL, s, _input): - y = 's2' - x = _input['param2'] - return (y, x) - -# 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) - -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) - -ts_format = '%Y-%m-%d %H:%M:%S' -t_delta = timedelta(days=0, minutes=0, seconds=1) -def es5p2(step, sL, s, _input): - y = 'timestamp' - x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta) - return (y, x) - - -# Environment States -def env_a(x): - return 5 -def env_b(x): - return 10 -# def what_ever(x): -# return x + 1 - -# Genesis States -genesis_states = { - 's1': Decimal(0.0), - 's2': Decimal(0.0), - 's3': Decimal(1.0), - 's4': Decimal(1.0), - 'timestamp': '2018-10-01 15:16:24' -} - -# remove `exo_update_per_ts` to update every ts -exogenous_states = exo_update_per_ts( - { - "s3": es3p1, - "s4": es4p2, - "timestamp": es5p2 - } -) - -# ToDo: make env proc trigger field agnostic -# ToDo: input json into function renaming __name__ -env_processes = { - "s3": env_a, - "s4": proc_trigger('2018-10-01 15:16:25', env_b) -} - -# lambdas -# genesis Sites should always be there -# [1, 2] -# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ] - -# [1, 2] = {'b1': ['a'], 'b2', [1]} = -# behavior_ops = [ behavior_to_dict, print_fwd, sum_dict_values ] -# behavior_ops = [foldr(dict_elemwise_sum())] -# behavior_ops = [foldr(lambda a, b: a + b)] - -# need at least 1 behaviour and 1 state function for the 1st mech with behaviors -# mechanisms = {} - -mechanisms = { - "m1": { - "behaviors": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, - "b2": b2m1 - }, - "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value - "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": 2, - "T": range(5) -} - -configs.append( - Configuration( - sim_config=sim_config, - state_dict=genesis_states, - seed=seed, - exogenous_states=exogenous_states, - env_processes=env_processes, - mechanisms=mechanisms - ) -) \ No newline at end of file diff --git a/simulations/validation/config_2.py b/simulations/validation/config_2.py deleted file mode 100644 index 6b9469e..0000000 --- a/simulations/validation/config_2.py +++ /dev/null @@ -1,180 +0,0 @@ -from decimal import Decimal -import numpy as np -from datetime import timedelta - -from SimCAD import configs -from SimCAD.configuration import Configuration -from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \ - ep_time_step - - -seed = { - 'z': np.random.RandomState(1), - 'a': np.random.RandomState(2), - 'b': np.random.RandomState(3), - 'c': np.random.RandomState(3) -} - -# Behaviors per Mechanism -# Different return types per mechanism ?? *** No *** -def b1m1(step, sL, s): - return {'param1': 1} -def b2m1(step, sL, s): - return {'param2': 4} - -def b1m2(step, sL, s): - return {'param1': 'a', 'param2': 2} -def b2m2(step, sL, s): - return {'param1': 'b', 'param2': 4} - - -def b1m3(step, sL, s): - return {'param1': ['c'], 'param2': np.array([10, 100])} -def b2m3(step, sL, s): - return {'param1': ['d'], 'param2': np.array([20, 200])} - - -# Internal States per Mechanism -def s1m1(step, sL, s, _input): - y = 's1' - x = _input['param1'] - return (y, x) -def s2m1(step, sL, s, _input): - y = 's2' - x = _input['param2'] - return (y, x) - -def s1m2(step, sL, s, _input): - y = 's1' - x = _input['param1'] - return (y, x) -def s2m2(step, sL, s, _input): - y = 's2' - x = _input['param2'] - return (y, x) - -def s1m3(step, sL, s, _input): - y = 's1' - x = _input['param1'] - return (y, x) -def s2m3(step, sL, s, _input): - y = 's2' - x = _input['param2'] - return (y, x) - -# 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) - -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) - -ts_format = '%Y-%m-%d %H:%M:%S' -t_delta = timedelta(days=0, minutes=0, seconds=1) -def es5p2(step, sL, s, _input): - y = 'timestamp' - x = ep_time_step(s, dt_str=s['timestamp'], fromat_str=ts_format, _timedelta=t_delta) - return (y, x) - - -# Environment States -def env_a(x): - return 10 -def env_b(x): - return 10 -# def what_ever(x): -# return x + 1 - -# Genesis States -genesis_states = { - 's1': Decimal(0.0), - 's2': Decimal(0.0), - 's3': Decimal(1.0), - 's4': Decimal(1.0), - 'timestamp': '2018-10-01 15:16:24' -} - -# remove `exo_update_per_ts` to update every ts -# why `exo_update_per_ts` here instead of `env_processes` -exogenous_states = exo_update_per_ts( - { - "s3": es3p1, - "s4": es4p2, - "timestamp": es5p2 - } -) - -# 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) -} - -# lambdas -# genesis Sites should always be there -# [1, 2] -# behavior_ops = [ foldr(_ + _), lambda x: x + 0 ] - - -# [1, 2] = {'b1': ['a'], 'b2', [1]} = -# behavior_ops = [behavior_to_dict, print_fwd, sum_dict_values] -# behavior_ops = [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": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, - # "b2": b2m1 - }, - "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value - "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": 2, - "T": range(5) -} - -configs.append( - Configuration( - sim_config=sim_config, - state_dict=genesis_states, - seed=seed, - exogenous_states=exogenous_states, - env_processes=env_processes, - mechanisms=mechanisms - ) -) \ No newline at end of file