cadCAD/notebooks/config_padding.ipynb

749 lines
25 KiB
Plaintext

{
"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": 2,
"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": 3,
"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": 3,
"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": 4,
"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>&lt;function b1m1 at 0x10af42158&gt;</td>\n",
" <td>&lt;function b2m1 at 0x10af42268&gt;</td>\n",
" <td>&lt;function s1m1 at 0x10af42510&gt;</td>\n",
" <td>&lt;function s2m1 at 0x10af42598&gt;</td>\n",
" <td>&lt;function es3p1 at 0x10af42840&gt;</td>\n",
" <td>&lt;function es4p2 at 0x10af428c8&gt;</td>\n",
" <td>&lt;function es5p2 at 0x10af42950&gt;</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>&lt;function b1m2 at 0x10af422f0&gt;</td>\n",
" <td>&lt;function b2m2 at 0x10af42400&gt;</td>\n",
" <td>&lt;function s1m2 at 0x10af42620&gt;</td>\n",
" <td>&lt;function state_identity.&lt;locals&gt;.identity at ...</td>\n",
" <td>&lt;function es3p1 at 0x10af42840&gt;</td>\n",
" <td>&lt;function es4p2 at 0x10af428c8&gt;</td>\n",
" <td>&lt;function es5p2 at 0x10af42950&gt;</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>&lt;function behavior_identity.&lt;locals&gt;.identity ...</td>\n",
" <td>&lt;function behavior_identity.&lt;locals&gt;.identity ...</td>\n",
" <td>&lt;function s1m3 at 0x10af42730&gt;</td>\n",
" <td>&lt;function state_identity.&lt;locals&gt;.identity at ...</td>\n",
" <td>&lt;function es3p1 at 0x10af42840&gt;</td>\n",
" <td>&lt;function es4p2 at 0x10af428c8&gt;</td>\n",
" <td>&lt;function es5p2 at 0x10af42950&gt;</td>\n",
" <td>3</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" b1 \\\n",
"0 <function b1m1 at 0x10af42158> \n",
"1 <function b1m2 at 0x10af422f0> \n",
"2 <function behavior_identity.<locals>.identity ... \n",
"\n",
" b2 \\\n",
"0 <function b2m1 at 0x10af42268> \n",
"1 <function b2m2 at 0x10af42400> \n",
"2 <function behavior_identity.<locals>.identity ... \n",
"\n",
" s1 \\\n",
"0 <function s1m1 at 0x10af42510> \n",
"1 <function s1m2 at 0x10af42620> \n",
"2 <function s1m3 at 0x10af42730> \n",
"\n",
" s2 \\\n",
"0 <function s2m1 at 0x10af42598> \n",
"1 <function state_identity.<locals>.identity at ... \n",
"2 <function state_identity.<locals>.identity at ... \n",
"\n",
" es0 es1 \\\n",
"0 <function es3p1 at 0x10af42840> <function es4p2 at 0x10af428c8> \n",
"1 <function es3p1 at 0x10af42840> <function es4p2 at 0x10af428c8> \n",
"2 <function es3p1 at 0x10af42840> <function es4p2 at 0x10af428c8> \n",
"\n",
" es2 m \n",
"0 <function es5p2 at 0x10af42950> 1 \n",
"1 <function es5p2 at 0x10af42950> 2 \n",
"2 <function es5p2 at 0x10af42950> 3 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# generate_config(mechanisms, ep)\n",
"create_tensor_field(mechanisms)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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__.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__.es3p1(step, sL, s, _input)>,\n",
" <function __main__.es4p2(step, sL, s, _input)>,\n",
" <function __main__.es5p2(step, sL, s, _input)>],\n",
" [])]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"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>&lt;function b1m1 at 0x118771e18&gt;</td>\n",
" <td>&lt;function b2m1 at 0x1188d7d90&gt;</td>\n",
" <td>&lt;function s1m1 at 0x1188d7730&gt;</td>\n",
" <td>&lt;function s2m1 at 0x1188ed730&gt;</td>\n",
" <td>&lt;function es3p1 at 0x1188ed400&gt;</td>\n",
" <td>&lt;function es4p2 at 0x1188ed378&gt;</td>\n",
" <td>&lt;function es5p2 at 0x1188ed158&gt;</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>&lt;function b1m2 at 0x1188d70d0&gt;</td>\n",
" <td>&lt;function b2m2 at 0x1188d7840&gt;</td>\n",
" <td>&lt;function s1m2 at 0x1188ed620&gt;</td>\n",
" <td>&lt;function state_identity.&lt;locals&gt;.identity at ...</td>\n",
" <td>&lt;function es3p1 at 0x1188ed400&gt;</td>\n",
" <td>&lt;function es4p2 at 0x1188ed378&gt;</td>\n",
" <td>&lt;function es5p2 at 0x1188ed158&gt;</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>&lt;function b1m3 at 0x1188d7ea0&gt;</td>\n",
" <td>&lt;function behavior_identity.&lt;locals&gt;.identity ...</td>\n",
" <td>&lt;function s1m3 at 0x1188d7a60&gt;</td>\n",
" <td>&lt;function s2m3 at 0x1188ed268&gt;</td>\n",
" <td>&lt;function es3p1 at 0x1188ed400&gt;</td>\n",
" <td>&lt;function es4p2 at 0x1188ed378&gt;</td>\n",
" <td>&lt;function es5p2 at 0x1188ed158&gt;</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>&lt;function b1m1 at 0x1108c88c8&gt;</td>\n",
" <td>&lt;function b2m1 at 0x1108c89d8&gt;</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>&lt;function b1m2 at 0x1108c8d90&gt;</td>\n",
" <td>&lt;function b2m2 at 0x1108c8a60&gt;</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>&lt;function b1m3 at 0x1108c8c80&gt;</td>\n",
" <td>&lt;function behavior_identity.&lt;locals&gt;.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>&lt;function b1m1 at 0x1105ed9d8&gt;</td>\n",
" <td>&lt;function b2m1 at 0x1105edbf8&gt;</td>\n",
" <td>&lt;function s1m1 at 0x1105c69d8&gt;</td>\n",
" <td>&lt;function s2m1 at 0x1105ede18&gt;</td>\n",
" <td>&lt;function es3p1 at 0x1187710d0&gt;</td>\n",
" <td>&lt;function es4p2 at 0x118771158&gt;</td>\n",
" <td>&lt;function es5p2 at 0x1187711e0&gt;</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>&lt;function b1m2 at 0x1105edc80&gt;</td>\n",
" <td>&lt;function b2m2 at 0x1105edd08&gt;</td>\n",
" <td>&lt;function s1m2 at 0x1105edea0&gt;</td>\n",
" <td>&lt;function state_identity.&lt;locals&gt;.identity at ...</td>\n",
" <td>&lt;function es3p1 at 0x1187710d0&gt;</td>\n",
" <td>&lt;function es4p2 at 0x118771158&gt;</td>\n",
" <td>&lt;function es5p2 at 0x1187711e0&gt;</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>&lt;function b1m3 at 0x1105edb70&gt;</td>\n",
" <td>&lt;function behavior_identity.&lt;locals&gt;.identity ...</td>\n",
" <td>&lt;function s1m3 at 0x1105ed0d0&gt;</td>\n",
" <td>&lt;function s2m3 at 0x118771048&gt;</td>\n",
" <td>&lt;function es3p1 at 0x1187710d0&gt;</td>\n",
" <td>&lt;function es4p2 at 0x118771158&gt;</td>\n",
" <td>&lt;function es5p2 at 0x1187711e0&gt;</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
}