refactored
This commit is contained in:
parent
2bb378fbf2
commit
4f9e320109
|
|
@ -6,6 +6,7 @@ import pandas as pd
|
||||||
from pathos.threading import ThreadPool
|
from pathos.threading import ThreadPool
|
||||||
|
|
||||||
from SimCAD.utils import groupByKey, dict_filter, contains_type
|
from SimCAD.utils import groupByKey, dict_filter, contains_type
|
||||||
|
from SimCAD.utils import flatMap
|
||||||
|
|
||||||
class TensorFieldReport:
|
class TensorFieldReport:
|
||||||
def __init__(self, config_proc):
|
def __init__(self, config_proc):
|
||||||
|
|
@ -127,3 +128,15 @@ def sweep_states(state_type, states, in_config):
|
||||||
configs = [in_config]
|
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)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
@ -7,7 +7,7 @@ from SimCAD import configs
|
||||||
from SimCAD.utils import flatMap
|
from SimCAD.utils import flatMap
|
||||||
from SimCAD.configuration import Configuration
|
from SimCAD.configuration import Configuration
|
||||||
from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \
|
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
|
from SimCAD.engine.utils import sweep
|
||||||
|
|
||||||
pp = pprint.PrettyPrinter(indent=4)
|
pp = pprint.PrettyPrinter(indent=4)
|
||||||
|
|
@ -28,16 +28,19 @@ def b1m1(step, sL, s):
|
||||||
def b2m1(step, sL, s):
|
def b2m1(step, sL, s):
|
||||||
return {'param2': 4}
|
return {'param2': 4}
|
||||||
|
|
||||||
|
# @curried
|
||||||
|
# def b1m2(param, step, sL, s):
|
||||||
|
# return {'param1': 'a', 'param2': param}
|
||||||
|
|
||||||
@curried
|
def b1m2(step, sL, s):
|
||||||
def b1m2(param, step, sL, s):
|
return {'param1': 'a', 'param2': 2}
|
||||||
return {'param1': 'a', 'param2': param}
|
|
||||||
|
|
||||||
def b2m2(step, sL, s):
|
def b2m2(step, sL, s):
|
||||||
return {'param1': 'b', 'param2': 4}
|
return {'param1': 'b', 'param2': 4}
|
||||||
|
|
||||||
def b1m3(step, sL, s):
|
def b1m3(step, sL, s):
|
||||||
return {'param1': ['c'], 'param2': np.array([10, 100])}
|
return {'param1': ['c'], 'param2': np.array([10, 100])}
|
||||||
|
|
||||||
def b2m3(step, sL, s):
|
def b2m3(step, sL, s):
|
||||||
return {'param1': ['d'], 'param2': np.array([20, 200])}
|
return {'param1': ['d'], 'param2': np.array([20, 200])}
|
||||||
|
|
||||||
|
|
@ -49,19 +52,18 @@ def s1m1(step, sL, s, _input):
|
||||||
return (y, x)
|
return (y, x)
|
||||||
|
|
||||||
|
|
||||||
# decorator
|
param = Decimal(11.0)
|
||||||
# param = Decimal(11.0)
|
def s2m1(step, sL, s, _input):
|
||||||
# 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'
|
y = 's2'
|
||||||
x = _input['param2'] + param
|
x = _input['param2'] + param
|
||||||
return (y, x)
|
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):
|
def s1m2(step, sL, s, _input):
|
||||||
y = 's1'
|
y = 's1'
|
||||||
x = _input['param1']
|
x = _input['param1']
|
||||||
|
|
@ -84,27 +86,17 @@ def s2m3(step, sL, s, _input):
|
||||||
proc_one_coef_A = 0.7
|
proc_one_coef_A = 0.7
|
||||||
proc_one_coef_B = 1.3
|
proc_one_coef_B = 1.3
|
||||||
|
|
||||||
# def es3p1(step, sL, s, _input):
|
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):
|
|
||||||
y = 's3'
|
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)
|
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):
|
def es4p2(step, sL, s, _input):
|
||||||
y = 's4'
|
y = 's4'
|
||||||
x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)
|
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
|
# Environment States
|
||||||
@curried
|
# @curried
|
||||||
def env_a(param, x):
|
# def env_a(param, x):
|
||||||
return x + param
|
# return x + param
|
||||||
|
def env_a(x):
|
||||||
|
return x
|
||||||
def env_b(x):
|
def env_b(x):
|
||||||
return 10
|
return 10
|
||||||
# def what_ever(x):
|
# def what_ever(x):
|
||||||
|
|
@ -138,7 +132,7 @@ genesis_states = {
|
||||||
|
|
||||||
# remove `exo_update_per_ts` to update every ts
|
# remove `exo_update_per_ts` to update every ts
|
||||||
raw_exogenous_states = {
|
raw_exogenous_states = {
|
||||||
"s3": sweep(beta, es3p1),
|
"s3": es3p1, #sweep(beta, es3p1),
|
||||||
"s4": es4p2,
|
"s4": es4p2,
|
||||||
"timestamp": es5p2
|
"timestamp": es5p2
|
||||||
}
|
}
|
||||||
|
|
@ -146,9 +140,10 @@ exogenous_states = exo_update_per_ts(raw_exogenous_states)
|
||||||
|
|
||||||
# ToDo: make env proc trigger field agnostic
|
# ToDo: make env proc trigger field agnostic
|
||||||
# ToDo: input json into function renaming __name__
|
# ToDo: input json into function renaming __name__
|
||||||
|
triggered_env_b = proc_trigger('2018-10-01 15:16:25', env_b)
|
||||||
env_processes = {
|
env_processes = {
|
||||||
"s3": sweep(beta, env_a, 'env_a'),
|
"s3": env_a, #sweep(beta, env_a, 'env_a'),
|
||||||
"s4": proc_trigger('2018-10-01 15:16:25', env_b)
|
"s4": sweep(beta, triggered_env_b, 'triggered_env_b')
|
||||||
}
|
}
|
||||||
|
|
||||||
# lambdas
|
# lambdas
|
||||||
|
|
@ -171,12 +166,12 @@ mechanisms = {
|
||||||
},
|
},
|
||||||
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
|
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
|
||||||
"s1": s1m1,
|
"s1": s1m1,
|
||||||
"s2": sweep(beta, s2m1)
|
"s2": s2m1 #sweep(beta, s2m1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"m2": {
|
"m2": {
|
||||||
"behaviors": {
|
"behaviors": {
|
||||||
"b1": sweep(beta, b1m2),
|
"b1": b1m2, #sweep(beta, b1m2),
|
||||||
"b2": b2m2
|
"b2": b2m2
|
||||||
},
|
},
|
||||||
"states": {
|
"states": {
|
||||||
|
|
@ -201,18 +196,6 @@ sim_config = {
|
||||||
"T": range(5)
|
"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(
|
c = Configuration(
|
||||||
sim_config=sim_config,
|
sim_config=sim_config,
|
||||||
state_dict=genesis_states,
|
state_dict=genesis_states,
|
||||||
|
|
@ -222,23 +205,12 @@ c = Configuration(
|
||||||
mechanisms=mechanisms
|
mechanisms=mechanisms
|
||||||
)
|
)
|
||||||
|
|
||||||
|
configs = configs + param_sweep(c, raw_exogenous_states)
|
||||||
l = flatMap(
|
|
||||||
sweep_states('environmental', env_processes),
|
|
||||||
flatMap(
|
|
||||||
sweep_states('exogenous', raw_exogenous_states),
|
|
||||||
flatMap(
|
|
||||||
sweep_mechs('states'),
|
|
||||||
sweep_mechs('behaviors', c)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print(len(l))
|
print(len(configs))
|
||||||
print()
|
print()
|
||||||
for g in l:
|
for g in configs:
|
||||||
print()
|
print()
|
||||||
print('Configuration')
|
print('Configuration')
|
||||||
print()
|
print()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue