identity fix pt.1
This commit is contained in:
parent
b4f4bc8b96
commit
16fe59c106
|
|
@ -1,21 +0,0 @@
|
|||
from ui.config import state_dict, mechanisms, exogenous_states, env_processes, sim_config
|
||||
from engine.configProcessor import generate_config
|
||||
from engine.mechanismExecutor import simulation
|
||||
from engine.utils import flatten
|
||||
|
||||
#from tabulate import tabulate
|
||||
import pandas as pd
|
||||
|
||||
def main():
|
||||
states_list = [state_dict]
|
||||
configs = generate_config(mechanisms, exogenous_states)
|
||||
# p = pipeline(states_list, configs, env_processes, range(10))
|
||||
N = sim_config['N']
|
||||
r = range(5)
|
||||
# Dimensions: N x r x mechs
|
||||
s = simulation(states_list, configs, env_processes, r, N)
|
||||
result = pd.DataFrame(flatten(s))
|
||||
print('Test')
|
||||
# print(tabulate(result, headers='keys', tablefmt='psql'))
|
||||
# remove print and tabulate functions, so it returns a dataframe
|
||||
return result
|
||||
|
|
@ -1,13 +1,36 @@
|
|||
# if beh list empty, repeat 0 x n_states in list
|
||||
def generate_config(mechanisms, exogenous_states):
|
||||
es_funcs = [exogenous_states[state] for state in list(exogenous_states.keys())]
|
||||
config = list(
|
||||
map(
|
||||
lambda m: (
|
||||
list(mechanisms[m]["states"].values()) + es_funcs,
|
||||
list(mechanisms[m]["behaviors"].values())
|
||||
),
|
||||
list(mechanisms.keys())
|
||||
)
|
||||
)
|
||||
return config
|
||||
import pandas as pd
|
||||
from functools import partial, reduce
|
||||
|
||||
def state_identity(k):
|
||||
def identity(step, sL, s, _input):
|
||||
return (k, s[k])
|
||||
return identity
|
||||
|
||||
def behavior_identity(k):
|
||||
def identity(step, sL, s):
|
||||
return s[k]
|
||||
return identity
|
||||
|
||||
def key_filter(mechanisms, keyname):
|
||||
return [ v[keyname] for k, v in mechanisms.items() ]
|
||||
|
||||
def fillna_with_id_func(identity, df, col):
|
||||
return df[[col]].fillna(value=identity(col))
|
||||
|
||||
def apply_identity_funcs(identity, df, cols):
|
||||
return list(map(lambda col: fillna_with_id_func(identity, df, col), cols))
|
||||
|
||||
def create_matrix_field(mechanisms, key):
|
||||
if key == 'states':
|
||||
identity = state_identity
|
||||
else:
|
||||
identity = behavior_identity
|
||||
df = pd.DataFrame(key_filter(mechanisms, key))
|
||||
col_list = apply_identity_funcs(identity, df, list(df.columns))
|
||||
return reduce((lambda x, y: pd.concat([x, y], axis=1)), col_list)
|
||||
|
||||
def generate_config(mechanisms, env_poc):
|
||||
bdf = create_matrix_field(mechanisms,'behaviors')
|
||||
sdf = create_matrix_field(mechanisms,'states')
|
||||
zipped_list = list(zip(sdf.values.tolist(), bdf.values.tolist()))
|
||||
return list(map(lambda x: (x[0] + env_poc, x[1]), zipped_list))
|
||||
|
|
@ -14,14 +14,24 @@ def apply_env_proc(env_processes, state_dict, step):
|
|||
if state in list(env_processes.keys()):
|
||||
state_dict[state] = env_processes[state](step)(state_dict[state])
|
||||
|
||||
def exception_handler(f, m_step, sL, last_mut_obj, _input):
|
||||
try:
|
||||
return f(m_step, sL, last_mut_obj, _input)
|
||||
except KeyError:
|
||||
print("Exception")
|
||||
return f(m_step, sL, sL[-2], _input)
|
||||
|
||||
|
||||
def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step):
|
||||
in_copy, mutatable_copy, out_copy = deepcopy(sL), deepcopy(sL), deepcopy(sL)
|
||||
last_in_obj, last_mut_obj = in_copy[-1], mutatable_copy[-1]
|
||||
|
||||
_input = getBehaviorInput(m_step, sL, last_in_obj, behavior_funcs)
|
||||
_input = exception_handler(getBehaviorInput, m_step, sL, last_in_obj, behavior_funcs)
|
||||
|
||||
last_mut_obj = dict([ f(m_step, sL, last_mut_obj, _input) for f in state_funcs ])
|
||||
last_mut_obj = dict([
|
||||
exception_handler(f, m_step, sL, last_mut_obj, _input) for f in state_funcs
|
||||
])
|
||||
print(str(m_step) + ': ' + str(last_mut_obj))
|
||||
|
||||
apply_env_proc(env_processes, last_mut_obj, last_mut_obj['timestamp'])
|
||||
|
||||
|
|
@ -44,6 +54,7 @@ def block_gen(states_list, configs, env_processes, t_step):
|
|||
for config in configs:
|
||||
s_conf, b_conf = config[0], config[1]
|
||||
states_list = mech_step(m_step, states_list, s_conf, b_conf, env_processes, t_step)
|
||||
print(b_conf)
|
||||
m_step += 1
|
||||
|
||||
t_step += 1
|
||||
|
|
@ -51,6 +62,7 @@ def block_gen(states_list, configs, env_processes, t_step):
|
|||
return states_list
|
||||
|
||||
|
||||
# rename pipe
|
||||
def pipeline(states_list, configs, env_processes, time_seq):
|
||||
time_seq = [x + 1 for x in time_seq]
|
||||
simulation_list = [states_list]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,11 @@ import pandas as pd
|
|||
|
||||
def main():
|
||||
states_list = [state_dict]
|
||||
configs = generate_config(mechanisms, exogenous_states)
|
||||
ep = list(exogenous_states.values())
|
||||
configs = generate_config(mechanisms, ep)
|
||||
# print(configs)
|
||||
# print(states_list)
|
||||
# print(configs)
|
||||
# p = pipeline(states_list, configs, env_processes, range(10))
|
||||
T = range(5)
|
||||
N = sim_config['N']
|
||||
|
|
|
|||
|
|
@ -55,4 +55,12 @@ def ep_time_step(s, dt_str, fromat_str='%Y-%m-%d %H:%M:%S', days=0, minutes=0, s
|
|||
if s['mech_step'] == 0:
|
||||
return time_step(dt_str, fromat_str, days, minutes, seconds)
|
||||
else:
|
||||
return dt_str
|
||||
return dt_str
|
||||
|
||||
# def create_tensor_field(mechanisms, env_poc, keys=['behaviors', 'states']):
|
||||
# dfs = [ create_matrix_field(mechanisms, k) for k in keys ]
|
||||
# df = pd.concat(dfs, axis=1)
|
||||
# for es, i in zip(env_poc, range(len(env_poc))):
|
||||
# df['es'+str(i)] = es
|
||||
# df['m'] = df.index + 1
|
||||
# return df
|
||||
|
|
@ -0,0 +1,644 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"from functools import partial, reduce"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 177,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Behaviors per Mechanism\n",
|
||||
"def b1m1(step, sL, s):\n",
|
||||
" return s['s1'] + 1\n",
|
||||
"def b2m1(step, sL, s):\n",
|
||||
" return s['s1'] + 1\n",
|
||||
"\n",
|
||||
"def b1m2(step, sL, s):\n",
|
||||
" return s['s1'] + 1\n",
|
||||
"def b2m2(step, sL, s):\n",
|
||||
" return s['s1'] + 1\n",
|
||||
"\n",
|
||||
"def b1m3(step, sL, s):\n",
|
||||
" return s['s1'] + 1\n",
|
||||
"def b2m3(step, sL, s):\n",
|
||||
" return s['s2'] + 1\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Internal States per Mechanism\n",
|
||||
"def s1m1(step, sL, s, _input):\n",
|
||||
" y = 's1'\n",
|
||||
" x = s['s1'] + _input\n",
|
||||
" return (y, x)\n",
|
||||
"def s2m1(step, sL, s, _input):\n",
|
||||
" y = 's2'\n",
|
||||
" x = s['s2'] + _input\n",
|
||||
" return (y, x)\n",
|
||||
"\n",
|
||||
"def s1m2(step, sL, s, _input):\n",
|
||||
" y = 's1'\n",
|
||||
" x = s['s1'] + _input\n",
|
||||
" return (y, x)\n",
|
||||
"def s2m2(step, sL, s, _input):\n",
|
||||
" y = 's2'\n",
|
||||
" x = s['s2'] + _input\n",
|
||||
" return (y, x)\n",
|
||||
"\n",
|
||||
"def s1m3(step, sL, s, _input):\n",
|
||||
" y = 's1'\n",
|
||||
" x = s['s1'] + _input\n",
|
||||
" return (y, x)\n",
|
||||
"def s2m3(step, sL, s, _input):\n",
|
||||
" y = 's2'\n",
|
||||
" x = s['s2'] + _input\n",
|
||||
" return (y, x)\n",
|
||||
"\n",
|
||||
"# Exogenous States\n",
|
||||
"proc_one_coef_A = 0.7\n",
|
||||
"proc_one_coef_B = 1.3\n",
|
||||
"def es3p1(step, sL, s, _input):\n",
|
||||
" y = 's3'\n",
|
||||
" x = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)\n",
|
||||
" return (y, x)\n",
|
||||
"def es4p2(step, sL, s, _input):\n",
|
||||
" y = 's4'\n",
|
||||
" x = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B)\n",
|
||||
" return (y, x)\n",
|
||||
"def es5p2(step, sL, s, _input): # accept timedelta instead of timedelta params\n",
|
||||
" y = 'timestamp'\n",
|
||||
" x = ep_time_step(s, s['timestamp'], seconds=1)\n",
|
||||
" return (y, x)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Environment States\n",
|
||||
"def env_a(x):\n",
|
||||
" return 10\n",
|
||||
"def env_b(x):\n",
|
||||
" return 10\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"exogenous_states = {\n",
|
||||
" \"s3\": es3p1,\n",
|
||||
" \"s4\": es4p2,\n",
|
||||
" \"timestamp\": es5p2\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"ep = list(exogenous_states.values())\n",
|
||||
"\n",
|
||||
"mechanisms = {\n",
|
||||
" \"m1\": {\n",
|
||||
" \"behaviors\": {\n",
|
||||
" \"b1\": b1m1, # lambda step, sL, s: s['s1'] + 1,\n",
|
||||
" \"b2\": b2m1\n",
|
||||
" },\n",
|
||||
" \"states\": {\n",
|
||||
" \"s1\": s1m1,\n",
|
||||
" \"s2\": s2m1,\n",
|
||||
" }\n",
|
||||
" },\n",
|
||||
" \"m2\": {\n",
|
||||
" \"behaviors\": {\n",
|
||||
" \"b1\": b1m2,\n",
|
||||
" \"b2\": b2m2\n",
|
||||
" },\n",
|
||||
" \"states\": {\n",
|
||||
" \"s1\": s1m2,\n",
|
||||
" # \"s2\": s2m2,\n",
|
||||
" }\n",
|
||||
" },\n",
|
||||
" \"m3\": {\n",
|
||||
" \"behaviors\": {\n",
|
||||
" # \"b1\": b1m3,\n",
|
||||
" # \"b2\": b2m3\n",
|
||||
" },\n",
|
||||
" \"states\": {\n",
|
||||
" \"s1\": s1m3,\n",
|
||||
" # \"s2\": s2m3,\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def state_identity(k):\n",
|
||||
" def identity(step, sL, s, _input):\n",
|
||||
" return (k, s[k])\n",
|
||||
" return identity\n",
|
||||
"\n",
|
||||
"def behavior_identity(k):\n",
|
||||
" def identity(step, sL, s):\n",
|
||||
" return s[k]\n",
|
||||
" return identity\n",
|
||||
"\n",
|
||||
"def key_filter(mechanisms, keyname): \n",
|
||||
" return [ v[keyname] for k, v in mechanisms.items() ]\n",
|
||||
"\n",
|
||||
"def fillna_with_id(identity, df, col):\n",
|
||||
" return df[[col]].fillna(value=identity(col))\n",
|
||||
"\n",
|
||||
"def apply_identity_funcs(identity, df, cols):\n",
|
||||
" return list(map(lambda col: fillna_with_id(identity, df, col), cols))\n",
|
||||
"\n",
|
||||
"def create_matrix_field(mechanisms, key):\n",
|
||||
" if key == 'states':\n",
|
||||
" identity = state_identity\n",
|
||||
" else:\n",
|
||||
" identity = behavior_identity\n",
|
||||
" df = pd.DataFrame(key_filter(mechanisms, key))\n",
|
||||
" col_list = apply_identity_funcs(identity, df, list(df.columns))\n",
|
||||
" return reduce((lambda x, y: pd.concat([x, y], axis=1)), col_list)\n",
|
||||
"\n",
|
||||
"def create_tensor_field(mechanisms, env_poc=ep, keys=['behaviors', 'states']):\n",
|
||||
" dfs = [ create_matrix_field(mechanisms, k) for k in keys ]\n",
|
||||
" df = pd.concat(dfs, axis=1)\n",
|
||||
" for es, i in zip(env_poc, range(len(env_poc))):\n",
|
||||
" df['es'+str(i)] = es\n",
|
||||
" df['m'] = df.index + 1\n",
|
||||
" return df\n",
|
||||
"\n",
|
||||
"def generate_config(mechanisms, env_poc=ep):\n",
|
||||
" bdf = create_matrix_field(mechanisms,'behaviors')\n",
|
||||
" sdf = create_matrix_field(mechanisms,'states')\n",
|
||||
" zipped_list = list(zip(sdf.values.tolist(), bdf.values.tolist()))\n",
|
||||
" return list(map(lambda x: (x[0] + env_poc, x[1]), zipped_list))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 183,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[[<function __main__.b1m1(step, sL, s)>,\n",
|
||||
" <function __main__.b2m1(step, sL, s)>],\n",
|
||||
" [<function __main__.b1m2(step, sL, s)>,\n",
|
||||
" <function __main__.b2m2(step, sL, s)>],\n",
|
||||
" [<function __main__.behavior_identity.<locals>.identity(step, sL, s)>,\n",
|
||||
" <function __main__.behavior_identity.<locals>.identity(step, sL, s)>]]"
|
||||
]
|
||||
},
|
||||
"execution_count": 183,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"create_matrix_field(mechanisms,'behaviors').values.tolist()\n",
|
||||
" \n",
|
||||
"# exdf[exdf.index == 0].values.tolist() #['b1','b2']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 181,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[([<function __main__.s1m1(step, sL, s, _input)>,\n",
|
||||
" <function __main__.s2m1(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es3p1(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es4p2(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es5p2(step, sL, s, _input)>],\n",
|
||||
" [<function __main__.b1m1(step, sL, s)>,\n",
|
||||
" <function __main__.b2m1(step, sL, s)>]),\n",
|
||||
" ([<function __main__.s1m2(step, sL, s, _input)>,\n",
|
||||
" <function __main__.state_identity.<locals>.identity(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es3p1(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es4p2(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es5p2(step, sL, s, _input)>],\n",
|
||||
" [<function __main__.b1m2(step, sL, s)>,\n",
|
||||
" <function __main__.b2m2(step, sL, s)>]),\n",
|
||||
" ([<function __main__.s1m3(step, sL, s, _input)>,\n",
|
||||
" <function __main__.state_identity.<locals>.identity(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es3p1(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es4p2(step, sL, s, _input)>,\n",
|
||||
" <function __main__.es5p2(step, sL, s, _input)>],\n",
|
||||
" [<function __main__.behavior_identity.<locals>.identity(step, sL, s)>,\n",
|
||||
" <function __main__.behavior_identity.<locals>.identity(step, sL, s)>])]"
|
||||
]
|
||||
},
|
||||
"execution_count": 181,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"generate_config(mechanisms, ep)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 180,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# def generate_config(mechanisms, exogenous_states):\n",
|
||||
"# es_funcs = list(exogenous_states.values())\n",
|
||||
"# # es_funcs = [ exogenous_states[state] for state in list(exogenous_states.keys()) ]\n",
|
||||
"# config = list(\n",
|
||||
"# map(\n",
|
||||
"# lambda m: (\n",
|
||||
"# list(mechanisms[m][\"states\"].values()) + es_funcs,\n",
|
||||
"# list(mechanisms[m][\"behaviors\"].values())\n",
|
||||
"# ),\n",
|
||||
"# list(mechanisms.keys())\n",
|
||||
"# )\n",
|
||||
"# )\n",
|
||||
"# return config\n",
|
||||
"# generate_config(mechanisms, exogenous_states)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 170,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>b1</th>\n",
|
||||
" <th>b2</th>\n",
|
||||
" <th>s1</th>\n",
|
||||
" <th>s2</th>\n",
|
||||
" <th>es0</th>\n",
|
||||
" <th>es1</th>\n",
|
||||
" <th>es2</th>\n",
|
||||
" <th>m</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td><function b1m1 at 0x118771e18></td>\n",
|
||||
" <td><function b2m1 at 0x1188d7d90></td>\n",
|
||||
" <td><function s1m1 at 0x1188d7730></td>\n",
|
||||
" <td><function s2m1 at 0x1188ed730></td>\n",
|
||||
" <td><function es3p1 at 0x1188ed400></td>\n",
|
||||
" <td><function es4p2 at 0x1188ed378></td>\n",
|
||||
" <td><function es5p2 at 0x1188ed158></td>\n",
|
||||
" <td>1</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td><function b1m2 at 0x1188d70d0></td>\n",
|
||||
" <td><function b2m2 at 0x1188d7840></td>\n",
|
||||
" <td><function s1m2 at 0x1188ed620></td>\n",
|
||||
" <td><function state_identity.<locals>.identity at ...</td>\n",
|
||||
" <td><function es3p1 at 0x1188ed400></td>\n",
|
||||
" <td><function es4p2 at 0x1188ed378></td>\n",
|
||||
" <td><function es5p2 at 0x1188ed158></td>\n",
|
||||
" <td>2</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td><function b1m3 at 0x1188d7ea0></td>\n",
|
||||
" <td><function behavior_identity.<locals>.identity ...</td>\n",
|
||||
" <td><function s1m3 at 0x1188d7a60></td>\n",
|
||||
" <td><function s2m3 at 0x1188ed268></td>\n",
|
||||
" <td><function es3p1 at 0x1188ed400></td>\n",
|
||||
" <td><function es4p2 at 0x1188ed378></td>\n",
|
||||
" <td><function es5p2 at 0x1188ed158></td>\n",
|
||||
" <td>3</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" b1 \\\n",
|
||||
"0 <function b1m1 at 0x118771e18> \n",
|
||||
"1 <function b1m2 at 0x1188d70d0> \n",
|
||||
"2 <function b1m3 at 0x1188d7ea0> \n",
|
||||
"\n",
|
||||
" b2 \\\n",
|
||||
"0 <function b2m1 at 0x1188d7d90> \n",
|
||||
"1 <function b2m2 at 0x1188d7840> \n",
|
||||
"2 <function behavior_identity.<locals>.identity ... \n",
|
||||
"\n",
|
||||
" s1 \\\n",
|
||||
"0 <function s1m1 at 0x1188d7730> \n",
|
||||
"1 <function s1m2 at 0x1188ed620> \n",
|
||||
"2 <function s1m3 at 0x1188d7a60> \n",
|
||||
"\n",
|
||||
" s2 \\\n",
|
||||
"0 <function s2m1 at 0x1188ed730> \n",
|
||||
"1 <function state_identity.<locals>.identity at ... \n",
|
||||
"2 <function s2m3 at 0x1188ed268> \n",
|
||||
"\n",
|
||||
" es0 es1 \\\n",
|
||||
"0 <function es3p1 at 0x1188ed400> <function es4p2 at 0x1188ed378> \n",
|
||||
"1 <function es3p1 at 0x1188ed400> <function es4p2 at 0x1188ed378> \n",
|
||||
"2 <function es3p1 at 0x1188ed400> <function es4p2 at 0x1188ed378> \n",
|
||||
"\n",
|
||||
" es2 m \n",
|
||||
"0 <function es5p2 at 0x1188ed158> 1 \n",
|
||||
"1 <function es5p2 at 0x1188ed158> 2 \n",
|
||||
"2 <function es5p2 at 0x1188ed158> 3 "
|
||||
]
|
||||
},
|
||||
"execution_count": 170,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"create_tensor_field(mechanisms)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 53,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>b1</th>\n",
|
||||
" <th>b2</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td><function b1m1 at 0x1108c88c8></td>\n",
|
||||
" <td><function b2m1 at 0x1108c89d8></td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td><function b1m2 at 0x1108c8d90></td>\n",
|
||||
" <td><function b2m2 at 0x1108c8a60></td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td><function b1m3 at 0x1108c8c80></td>\n",
|
||||
" <td><function behavior_identity.<locals>.identity ...</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" b1 \\\n",
|
||||
"0 <function b1m1 at 0x1108c88c8> \n",
|
||||
"1 <function b1m2 at 0x1108c8d90> \n",
|
||||
"2 <function b1m3 at 0x1108c8c80> \n",
|
||||
"\n",
|
||||
" b2 \n",
|
||||
"0 <function b2m1 at 0x1108c89d8> \n",
|
||||
"1 <function b2m2 at 0x1108c8a60> \n",
|
||||
"2 <function behavior_identity.<locals>.identity ... "
|
||||
]
|
||||
},
|
||||
"execution_count": 53,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"create_matrix_field(mechanisms,'behaviors')\n",
|
||||
"create_matrix_field(mechanisms,'states')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 60,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>b1</th>\n",
|
||||
" <th>b2</th>\n",
|
||||
" <th>s1</th>\n",
|
||||
" <th>s2</th>\n",
|
||||
" <th>es0</th>\n",
|
||||
" <th>es1</th>\n",
|
||||
" <th>es2</th>\n",
|
||||
" <th>m</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td><function b1m1 at 0x1105ed9d8></td>\n",
|
||||
" <td><function b2m1 at 0x1105edbf8></td>\n",
|
||||
" <td><function s1m1 at 0x1105c69d8></td>\n",
|
||||
" <td><function s2m1 at 0x1105ede18></td>\n",
|
||||
" <td><function es3p1 at 0x1187710d0></td>\n",
|
||||
" <td><function es4p2 at 0x118771158></td>\n",
|
||||
" <td><function es5p2 at 0x1187711e0></td>\n",
|
||||
" <td>1</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td><function b1m2 at 0x1105edc80></td>\n",
|
||||
" <td><function b2m2 at 0x1105edd08></td>\n",
|
||||
" <td><function s1m2 at 0x1105edea0></td>\n",
|
||||
" <td><function state_identity.<locals>.identity at ...</td>\n",
|
||||
" <td><function es3p1 at 0x1187710d0></td>\n",
|
||||
" <td><function es4p2 at 0x118771158></td>\n",
|
||||
" <td><function es5p2 at 0x1187711e0></td>\n",
|
||||
" <td>2</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td><function b1m3 at 0x1105edb70></td>\n",
|
||||
" <td><function behavior_identity.<locals>.identity ...</td>\n",
|
||||
" <td><function s1m3 at 0x1105ed0d0></td>\n",
|
||||
" <td><function s2m3 at 0x118771048></td>\n",
|
||||
" <td><function es3p1 at 0x1187710d0></td>\n",
|
||||
" <td><function es4p2 at 0x118771158></td>\n",
|
||||
" <td><function es5p2 at 0x1187711e0></td>\n",
|
||||
" <td>3</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" b1 \\\n",
|
||||
"0 <function b1m1 at 0x1105ed9d8> \n",
|
||||
"1 <function b1m2 at 0x1105edc80> \n",
|
||||
"2 <function b1m3 at 0x1105edb70> \n",
|
||||
"\n",
|
||||
" b2 \\\n",
|
||||
"0 <function b2m1 at 0x1105edbf8> \n",
|
||||
"1 <function b2m2 at 0x1105edd08> \n",
|
||||
"2 <function behavior_identity.<locals>.identity ... \n",
|
||||
"\n",
|
||||
" s1 \\\n",
|
||||
"0 <function s1m1 at 0x1105c69d8> \n",
|
||||
"1 <function s1m2 at 0x1105edea0> \n",
|
||||
"2 <function s1m3 at 0x1105ed0d0> \n",
|
||||
"\n",
|
||||
" s2 \\\n",
|
||||
"0 <function s2m1 at 0x1105ede18> \n",
|
||||
"1 <function state_identity.<locals>.identity at ... \n",
|
||||
"2 <function s2m3 at 0x118771048> \n",
|
||||
"\n",
|
||||
" es0 es1 \\\n",
|
||||
"0 <function es3p1 at 0x1187710d0> <function es4p2 at 0x118771158> \n",
|
||||
"1 <function es3p1 at 0x1187710d0> <function es4p2 at 0x118771158> \n",
|
||||
"2 <function es3p1 at 0x1187710d0> <function es4p2 at 0x118771158> \n",
|
||||
"\n",
|
||||
" es2 m \n",
|
||||
"0 <function es5p2 at 0x1187711e0> 1 \n",
|
||||
"1 <function es5p2 at 0x1187711e0> 2 \n",
|
||||
"2 <function es5p2 at 0x1187711e0> 3 "
|
||||
]
|
||||
},
|
||||
"execution_count": 60,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tensor_field_report(mechanisms)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"('a', 0)\n",
|
||||
"('b', 1)\n",
|
||||
"('c', 2)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"\n",
|
||||
"for x, i in zip(['a', 'b', 'c'], range(3)):\n",
|
||||
" print((x, i))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 41,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"3"
|
||||
]
|
||||
},
|
||||
"execution_count": 41,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"len(env_poc)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def create_tensor_field2(mechanisms, env_poc=ep):\n",
|
||||
" beh_df = create_matrix_field(mechanisms, 'behaviors')\n",
|
||||
" state_df = create_matrix_field(mechanisms, 'states')\n",
|
||||
" ep_df = pd.DataFrame({'m' : range(len(env_poc))})\n",
|
||||
" for es, i in zip(env_poc, range(len(env_poc))):\n",
|
||||
" ep_df['es'+str(i)] = es\n",
|
||||
" \n",
|
||||
" return beh_df"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
12
ui/config.py
12
ui/config.py
|
|
@ -109,7 +109,7 @@ mechanisms = {
|
|||
},
|
||||
"states": {
|
||||
"s1": s1m1,
|
||||
"s2": s2m1,
|
||||
# "s2": s2m1,
|
||||
}
|
||||
},
|
||||
"m2": {
|
||||
|
|
@ -118,18 +118,18 @@ mechanisms = {
|
|||
"b2": b2m2
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m2,
|
||||
"s2": s2m2,
|
||||
# "s1": s1m2,
|
||||
# "s2": s2m2,
|
||||
}
|
||||
},
|
||||
"m3": {
|
||||
"behaviors": {
|
||||
"b1": b1m3,
|
||||
"b2": b2m3
|
||||
"b2": b2m3 #toggle for error
|
||||
},
|
||||
"states": {
|
||||
"s1": s1m3,
|
||||
"s2": s2m3,
|
||||
# "s1": s1m3,
|
||||
# "s2": s2m3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue