From ed2f31cffc7012e63a3c81fb08a0f80fd26d52d3 Mon Sep 17 00:00:00 2001 From: "Joshua E. Jodesty" Date: Thu, 14 Feb 2019 10:29:45 -0500 Subject: [PATCH] merge heaven: working --- SimCAD/configuration/utils/parameterSweep.py | 1 + SimCAD/engine/__init__.py | 1 - simulations/example_run.py | 2 +- simulations/validation/config1.py | 74 +++++++++---------- simulations/validation/config2.py | 75 +++++++++----------- 5 files changed, 72 insertions(+), 81 deletions(-) diff --git a/SimCAD/configuration/utils/parameterSweep.py b/SimCAD/configuration/utils/parameterSweep.py index 1260da0..7d5024c 100644 --- a/SimCAD/configuration/utils/parameterSweep.py +++ b/SimCAD/configuration/utils/parameterSweep.py @@ -16,4 +16,5 @@ def config_sim(d): for M in process_variables(d["M"]) ] else: + d["M"] = [{}] return d diff --git a/SimCAD/engine/__init__.py b/SimCAD/engine/__init__.py index 5c05c1b..33fb8ef 100644 --- a/SimCAD/engine/__init__.py +++ b/SimCAD/engine/__init__.py @@ -55,7 +55,6 @@ 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]) eps.append(list(x.exogenous_states.values())) configs_structs.append(config_proc.generate_config(x.state_dict, x.mechanisms, eps[config_idx])) diff --git a/simulations/example_run.py b/simulations/example_run.py index cf2bba9..8b265aa 100644 --- a/simulations/example_run.py +++ b/simulations/example_run.py @@ -2,7 +2,7 @@ import pandas as pd from tabulate import tabulate # The following imports NEED to be in the exact order from SimCAD.engine import ExecutionMode, ExecutionContext, Executor -from simulations.validation import sweep_config +from simulations.validation import config1, config2 # sweep_config from SimCAD import configs exec_mode = ExecutionMode() diff --git a/simulations/validation/config1.py b/simulations/validation/config1.py index a016842..f1bfe70 100644 --- a/simulations/validation/config1.py +++ b/simulations/validation/config1.py @@ -2,10 +2,9 @@ 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 +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 = { @@ -17,46 +16,46 @@ seed = { # Behaviors per Mechanism -def b1m1(step, sL, s): +def b1m1(_g, step, sL, s): return {'param1': 1} -def b2m1(step, sL, s): +def b2m1(_g, step, sL, s): return {'param2': 4} -def b1m2(step, sL, s): +def b1m2(_g, step, sL, s): return {'param1': 'a', 'param2': 2} -def b2m2(step, sL, s): +def b2m2(_g, step, sL, s): return {'param1': 'b', 'param2': 4} -def b1m3(step, sL, s): +def b1m3(_g, step, sL, s): return {'param1': ['c'], 'param2': np.array([10, 100])} -def b2m3(step, sL, s): +def b2m3(_g, step, sL, s): return {'param1': ['d'], 'param2': np.array([20, 200])} # Internal States per Mechanism -def s1m1(step, sL, s, _input): +def s1m1(_g, step, sL, s, _input): y = 's1' x = _input['param1'] return (y, x) -def s2m1(step, sL, s, _input): +def s2m1(_g, step, sL, s, _input): y = 's2' x = _input['param2'] return (y, x) -def s1m2(step, sL, s, _input): +def s1m2(_g, step, sL, s, _input): y = 's1' x = _input['param1'] return (y, x) -def s2m2(step, sL, s, _input): +def s2m2(_g, step, sL, s, _input): y = 's2' x = _input['param2'] return (y, x) -def s1m3(step, sL, s, _input): +def s1m3(_g, step, sL, s, _input): y = 's1' x = _input['param1'] return (y, x) -def s2m3(step, sL, s, _input): +def s2m3(_g, step, sL, s, _input): y = 's2' x = _input['param2'] return (y, x) @@ -66,19 +65,19 @@ def s2m3(step, sL, s, _input): proc_one_coef_A = 0.7 proc_one_coef_B = 1.3 -def es3p1(step, sL, s, _input): +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) return (y, x) -def es4p2(step, sL, s, _input): +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) 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): +def es5p2(_g, 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) @@ -103,14 +102,11 @@ genesis_states = { } -# remove `exo_update_per_ts` to update every ts -exogenous_states = exo_update_per_ts( - { +raw_exogenous_states = { "s3": es3p1, "s4": es4p2, "timestamp": es5p2 - } -) +} env_processes = { @@ -153,19 +149,19 @@ mechanisms = { } -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 - ) +sim_config = config_sim( + { + "N": 2, + "T": range(5), + } +) + + +append_configs( + sim_configs=sim_config, + state_dict=genesis_states, + seed=seed, + raw_exogenous_states=raw_exogenous_states, + env_processes=env_processes, + mechanisms=mechanisms ) diff --git a/simulations/validation/config2.py b/simulations/validation/config2.py index 703dace..98705e6 100644 --- a/simulations/validation/config2.py +++ b/simulations/validation/config2.py @@ -2,11 +2,9 @@ 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 - +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 = { 'z': np.random.RandomState(1), @@ -17,46 +15,46 @@ seed = { # Behaviors per Mechanism -def b1m1(step, sL, s): +def b1m1(_g, step, sL, s): return {'param1': 1} -def b2m1(step, sL, s): +def b2m1(_g, step, sL, s): return {'param2': 4} -def b1m2(step, sL, s): +def b1m2(_g, step, sL, s): return {'param1': 'a', 'param2': 2} -def b2m2(step, sL, s): +def b2m2(_g, step, sL, s): return {'param1': 'b', 'param2': 4} -def b1m3(step, sL, s): +def b1m3(_g, step, sL, s): return {'param1': ['c'], 'param2': np.array([10, 100])} -def b2m3(step, sL, s): +def b2m3(_g, step, sL, s): return {'param1': ['d'], 'param2': np.array([20, 200])} # Internal States per Mechanism -def s1m1(step, sL, s, _input): +def s1m1(_g, step, sL, s, _input): y = 's1' x = _input['param1'] return (y, x) -def s2m1(step, sL, s, _input): +def s2m1(_g, step, sL, s, _input): y = 's2' x = _input['param2'] return (y, x) -def s1m2(step, sL, s, _input): +def s1m2(_g, step, sL, s, _input): y = 's1' x = _input['param1'] return (y, x) -def s2m2(step, sL, s, _input): +def s2m2(_g, step, sL, s, _input): y = 's2' x = _input['param2'] return (y, x) -def s1m3(step, sL, s, _input): +def s1m3(_g, step, sL, s, _input): y = 's1' x = _input['param1'] return (y, x) -def s2m3(step, sL, s, _input): +def s2m3(_g, step, sL, s, _input): y = 's2' x = _input['param2'] return (y, x) @@ -66,19 +64,19 @@ def s2m3(step, sL, s, _input): proc_one_coef_A = 0.7 proc_one_coef_B = 1.3 -def es3p1(step, sL, s, _input): +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) return (y, x) -def es4p2(step, sL, s, _input): +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) 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): +def es5p2(_g, 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) @@ -103,14 +101,11 @@ genesis_states = { } -# remove `exo_update_per_ts` to update every ts -exogenous_states = exo_update_per_ts( - { +raw_exogenous_states = { "s3": es3p1, "s4": es4p2, "timestamp": es5p2 - } -) +} env_processes = { @@ -153,19 +148,19 @@ mechanisms = { } -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 - ) +sim_config = config_sim( + { + "N": 2, + "T": range(5), + } +) + + +append_configs( + sim_configs=sim_config, + state_dict=genesis_states, + seed=seed, + raw_exogenous_states=raw_exogenous_states, + env_processes=env_processes, + mechanisms=mechanisms )