refactored

This commit is contained in:
Joshua E. Jodesty 2018-12-16 10:26:52 -05:00
parent 2bb378fbf2
commit 4f9e320109
2 changed files with 51 additions and 66 deletions

View File

@ -6,6 +6,7 @@ import pandas as pd
from pathos.threading import ThreadPool
from SimCAD.utils import groupByKey, dict_filter, contains_type
from SimCAD.utils import flatMap
class TensorFieldReport:
def __init__(self, config_proc):
@ -126,4 +127,16 @@ def sweep_states(state_type, states, in_config):
else:
configs = [in_config]
return configs
return configs
def param_sweep(config, raw_exogenous_states):
return flatMap(
sweep_states('environmental', config.env_processes),
flatMap(
sweep_states('exogenous', raw_exogenous_states),
flatMap(
sweep_mechs('states'),
sweep_mechs('behaviors', config)
)
)
)

View File

@ -7,7 +7,7 @@ from SimCAD import configs
from SimCAD.utils import flatMap
from SimCAD.configuration import Configuration
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
ep_time_step, sweep_states, sweep_mechs
ep_time_step, param_sweep
from SimCAD.engine.utils import sweep
pp = pprint.PrettyPrinter(indent=4)
@ -28,16 +28,19 @@ def b1m1(step, sL, s):
def b2m1(step, sL, s):
return {'param2': 4}
# @curried
# def b1m2(param, step, sL, s):
# return {'param1': 'a', 'param2': param}
@curried
def b1m2(param, step, sL, s):
return {'param1': 'a', 'param2': param}
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])}
@ -49,19 +52,18 @@ def s1m1(step, sL, s, _input):
return (y, x)
# decorator
# param = Decimal(11.0)
# def s2m1(step, sL, s, _input):
# y = 's2'
# x = _input['param2'] + param
# return (y, x)
@curried
def s2m1(param, step, sL, s, _input):
param = Decimal(11.0)
def s2m1(step, sL, s, _input):
y = 's2'
x = _input['param2'] + param
return (y, x)
# @curried
# def s2m1(param, step, sL, s, _input):
# y = 's2'
# x = _input['param2'] + param
# return (y, x)
def s1m2(step, sL, s, _input):
y = 's1'
x = _input['param1']
@ -84,27 +86,17 @@ def s2m3(step, sL, s, _input):
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)
# es3p1 = sweep(
# params = [Decimal(11.0), Decimal(22.0)],
# sweep_f = lambda param: lambda step, sL, s, _input: (
# 's3',
# s['s3'] + param
# )
# )
@curried
def es3p1(param, step, sL, s, _input):
def es3p1(step, sL, s, _input):
y = 's3'
x = s['s3'] + param
x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)
return (y, x)
# @curried
# def es3p1(param, step, sL, s, _input):
# y = 's3'
# x = s['s3'] + param
# 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)
@ -119,9 +111,11 @@ def es5p2(step, sL, s, _input):
# Environment States
@curried
def env_a(param, x):
return x + param
# @curried
# def env_a(param, x):
# return x + param
def env_a(x):
return x
def env_b(x):
return 10
# def what_ever(x):
@ -138,7 +132,7 @@ genesis_states = {
# remove `exo_update_per_ts` to update every ts
raw_exogenous_states = {
"s3": sweep(beta, es3p1),
"s3": es3p1, #sweep(beta, es3p1),
"s4": es4p2,
"timestamp": es5p2
}
@ -146,9 +140,10 @@ exogenous_states = exo_update_per_ts(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": sweep(beta, env_a, 'env_a'),
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
"s3": env_a, #sweep(beta, env_a, 'env_a'),
"s4": sweep(beta, triggered_env_b, 'triggered_env_b')
}
# lambdas
@ -171,12 +166,12 @@ mechanisms = {
},
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"s1": s1m1,
"s2": sweep(beta, s2m1)
"s2": s2m1 #sweep(beta, s2m1)
}
},
"m2": {
"behaviors": {
"b1": sweep(beta, b1m2),
"b1": b1m2, #sweep(beta, b1m2),
"b2": b2m2
},
"states": {
@ -201,18 +196,6 @@ sim_config = {
"T": range(5)
}
# configs.append(
# Configuration(
# sim_config=sim_config,
# state_dict=genesis_states,
# seed=seed,
# env_processes=env_processes,
# exogenous_states=exogenous_states,
# mechanisms=mechanisms
# )
# )
c = Configuration(
sim_config=sim_config,
state_dict=genesis_states,
@ -222,23 +205,12 @@ c = Configuration(
mechanisms=mechanisms
)
l = flatMap(
sweep_states('environmental', env_processes),
flatMap(
sweep_states('exogenous', raw_exogenous_states),
flatMap(
sweep_mechs('states'),
sweep_mechs('behaviors', c)
)
)
)
configs = configs + param_sweep(c, raw_exogenous_states)
print()
print(len(l))
print(len(configs))
print()
for g in l:
for g in configs:
print()
print('Configuration')
print()