From cfbbb73e31392b0424bb47a59adbb9da6d23f083 Mon Sep 17 00:00:00 2001 From: Markus Date: Mon, 26 Nov 2018 14:46:20 -0200 Subject: [PATCH] test notebook update and folder cleanup --- notebooks/CAD_Engine.ipynb | 1544 -------------------------------- notebooks/Sim_CAD_Engine.ipynb | 877 ------------------ notebooks/TestNotebook.ipynb | 35 - notebooks/config_padding.ipynb | 748 ---------------- notebooks/test.ipynb | 205 ++++- 5 files changed, 165 insertions(+), 3244 deletions(-) delete mode 100644 notebooks/CAD_Engine.ipynb delete mode 100644 notebooks/Sim_CAD_Engine.ipynb delete mode 100644 notebooks/TestNotebook.ipynb delete mode 100644 notebooks/config_padding.ipynb diff --git a/notebooks/CAD_Engine.ipynb b/notebooks/CAD_Engine.ipynb deleted file mode 100644 index fc51d07..0000000 --- a/notebooks/CAD_Engine.ipynb +++ /dev/null @@ -1,1544 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from fn import op, _, F\n", - "from operator import add, mul\n", - "from itertools import repeat, chain\n", - "from functools import reduce\n", - "# from objproxies import LazyProxy\n", - "import json\n", - "from copy import deepcopy, copy\n", - "from pipetools import pipe\n", - "from functools import partial\n", - "import numpy as np\n", - "from datetime import datetime, timedelta\n", - "from decimal import Decimal, getcontext, ROUND_DOWN\n", - "TWOPLACES = Decimal(10) ** -2 # same as Decimal('0.01')\n", - "import pandas as pd\n", - "import pprint\n", - "# getcontext().prec=None\n", - "# getcontext().rounding = ROUND_DOWN" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "flatten = lambda l: [item for sublist in l for item in sublist]\n", - "\n", - "def flatmap(f, items):\n", - " return list(map(f, items))\n", - " \n", - "def datetime_range(start, end, delta, dt_format='%Y-%m-%d %H:%M:%S'):\n", - " reverse_head = end\n", - " [start, end] = [datetime.strptime(x, dt_format) for x in [start, end]]\n", - " def _datetime_range(start, end, delta):\n", - " current = start\n", - " while current < end:\n", - " yield current\n", - " current += delta\n", - " \n", - " reverse_tail = [dt.strftime(dt_format) for dt in _datetime_range(start, end, delta)]\n", - " return reverse_tail + [reverse_head]\n", - " \n", - "def last_index(l):\n", - " return len(l)-1\n", - "\n", - "def retrieve_state(l, offset):\n", - " return l[last_index(l) + offset + 1]\n", - "\n", - "def bound_norm_random(rng, low, high):\n", - " # Add RNG Seed\n", - " res = rng.normal((high+low)/2,(high-low)/6)\n", - " if (reshigh):\n", - " res = bound_norm_random(rng, low, high)\n", - " return Decimal(res)\n", - "\n", - "def env_proc(trigger_step, update_f):\n", - " def env_step_trigger(trigger_step, update_f, step):\n", - " if step == trigger_step:\n", - " return update_f\n", - " else:\n", - " return lambda x: x\n", - " return partial(env_step_trigger, trigger_step, update_f)\n", - "\n", - "def time_step(dt_str, dt_format='%Y-%m-%d %H:%M:%S', days=0, minutes=0, seconds=30):\n", - " dt = datetime.strptime(dt_str, dt_format)\n", - " t = dt + timedelta(days=days, minutes=minutes, seconds=seconds)\n", - " return t.strftime(dt_format)\n", - "\n", - "def ep_time_step(s, dt_str, fromat_str='%Y-%m-%d %H:%M:%S', days=0, minutes=0, seconds=1):\n", - " if s['mech_step'] == 0:\n", - " return time_step(dt_str, fromat_str, days, minutes, seconds)\n", - " else: \n", - " return dt_str\n", - "\n", - "def round_down(x, fp=TWOPLACES):\n", - " return x.quantize(TWOPLACES, rounding=ROUND_DOWN)" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "# esceptions:\n", - "# point to line giving problems and pass a sentinel" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "seed = {\n", - " 'z': np.random.RandomState(1),\n", - " 'a': np.random.RandomState(2),\n", - " 'b': np.random.RandomState(3),\n", - " 'c': np.random.RandomState(3)\n", - "}\n", - "\n", - "# UI 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", - "# UI Internal States per Mechanism\n", - "def s1m1(step, sL, s, _input):\n", - " s['s1'] = s['s1'] + _input\n", - "def s2m1(step, sL, s, _input):\n", - " s['s2'] = s['s2'] + _input\n", - "\n", - "def s1m2(step, sL, s, _input):\n", - " s['s1'] = s['s1'] + _input\n", - "def s2m2(step, sL, s, _input):\n", - " s['s2'] = s['s2'] + _input\n", - " \n", - "def s1m3(step, sL, s, _input):\n", - " s['s1'] = s['s1'] + _input\n", - "def s2m3(step, sL, s, _input):\n", - " s['s2'] = s['s2'] + _input\n", - "\n", - "# UI Exogenous States #per Mechanism\n", - "proc_one_coef_A = 0.7\n", - "proc_one_coef_B = 1.3\n", - "def es3p1(step, sL, s, _input):\n", - " s['s3'] = s['s3'] * bound_norm_random(seed['a'], proc_one_coef_A, proc_one_coef_B)\n", - "def es4p2(step, sL, s, _input):\n", - " s['s4'] = s['s4'] * bound_norm_random(seed['b'], proc_one_coef_A, proc_one_coef_B) \n", - "def es5p2(step, sL, s, _input):\n", - " s['timestamp'] = ep_time_step(s, s['timestamp'], seconds=1)\n", - "\n", - "def env_a(x): \n", - " return 10\n", - "def env_b(x): \n", - " return 10\n", - "def what_ever(x): \n", - " return x + 1\n", - "\n", - "# Genesis States \n", - "state_dict = {\n", - " 's1': Decimal(0.0),\n", - " 's2': Decimal(0.0),\n", - " 's3': Decimal(1.0),\n", - " 's4': Decimal(1.0),\n", - " 'timestamp': '2018-10-01 15:16:24'\n", - "}\n", - "\n", - "sim_config = {\n", - " \"N\": 2\n", - "}\n", - "\n", - "exogenous_states = {\n", - " \"s3\": es3p1,\n", - " \"s4\": es4p2,\n", - " \"timestamp\": es5p2\n", - "}\n", - "\n", - "env_processes = {\n", - " \"s3\": env_proc('2018-10-01 15:16:25', env_a),\n", - " \"s4\": env_proc('2018-10-01 15:16:25', env_b)\n", - "}\n", - " \n", - "mechanisms = {\n", - " \"m1\": {\n", - " \"behaviors\": {\n", - " \"b1\": b1m1,\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", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "# if beh list empty, repeat 0 x n_states in list \n", - "def generate_config(mechanisms, exogenous_states):\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", - "\n", - "# partials = list(map(lambda f: partial(f, step, sL), funcs))\n", - "def getColResults(step, sL, s, funcs):\n", - " return list(map(lambda f: f(step, sL, s), funcs))\n", - "\n", - "def getBehaviorInput(step, sL, s, funcs): \n", - " return op.foldr(_ + _)(getColResults(step, sL, s, funcs))\n", - "\n", - "def apply_env_proc(env_processes, state_dict, step):\n", - " for state in state_dict.keys(): \n", - " if state in list(env_processes.keys()):\n", - " state_dict[state] = env_processes[state](step)(state_dict[state])\n", - "# return state_dict\n", - " \n", - "def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step):\n", - " in_copy, mutatable_copy, out_copy = deepcopy(sL), deepcopy(sL), deepcopy(sL)\n", - " last_in_obj, last_mut_obj = in_copy[-1], mutatable_copy[-1]\n", - " \n", - " _input = getBehaviorInput(m_step, sL, last_in_obj, behavior_funcs)\n", - "\n", - " for f in state_funcs:\n", - " f(m_step, sL, last_mut_obj, _input)\n", - " \n", - " apply_env_proc(env_processes, last_mut_obj, last_mut_obj['timestamp'])\n", - " \n", - " last_mut_obj[\"mech_step\"], last_mut_obj[\"time_step\"] = m_step, t_step\n", - " out_copy.append(last_mut_obj)\n", - " \n", - " del last_in_obj, last_mut_obj, in_copy, mutatable_copy,\n", - " return out_copy\n", - "\n", - "def block_gen(states_list, configs, env_processes, t_step):\n", - " m_step = 0\n", - " states_list_copy = deepcopy(states_list)\n", - " genesis_states = states_list_copy[-1]\n", - " genesis_states['mech_step'], genesis_states['time_step'] = m_step, t_step\n", - " states_list = [genesis_states]\n", - " \n", - " m_step += 1\n", - " for config in configs:\n", - " s_conf, b_conf = config[0], config[1]\n", - " states_list = mech_step(m_step, states_list, s_conf, b_conf, env_processes, t_step) \n", - " m_step += 1 \n", - " \n", - " t_step += 1\n", - " \n", - " return states_list\n", - "\n", - "def pipeline(states_list, configs, env_processes, time_seq):\n", - " time_seq = [x + 1 for x in time_seq]\n", - " simulation_list = [states_list]\n", - " for time_step in time_seq:\n", - " pipeline_run = block_gen(simulation_list[-1], configs, env_processes, time_step)\n", - " head, *pipeline_run = pipeline_run\n", - " simulation_list.append(pipeline_run)\n", - " \n", - " return simulation_list\n", - "\n", - "def simulation(states_list, configs, env_processes, time_seq, runs):\n", - " pipeline_run = []\n", - " for run in range(runs):\n", - " if run == 0:\n", - " head, *tail = pipeline(states_list, configs, env_processes, time_seq)\n", - " head[-1]['mech_step'], head[-1]['time_step'] = 0, 0\n", - " simulation_list = [head] + tail\n", - " pipeline_run += simulation_list\n", - " else:\n", - " transient_states_list = [pipeline_run[-1][-1]]\n", - " head, *tail = pipeline(transient_states_list, configs, env_processes, time_seq)\n", - " pipeline_run += tail\n", - " \n", - " return pipeline_run" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "states_list = [state_dict]\n", - "configs = generate_config(mechanisms, exogenous_states)\n", - "p = pipeline(states_list, configs, env_processes, range(10))\n", - "N = sim_config['N']\n", - "s = simulation(states_list, configs, env_processes, range(5), N)\n", - "# x = flatten(s)\n", - "# transient_state = p[-1][1]\n", - "# transient_state['mech_step'], transient_state['time_step'] = 0, 0\n", - "# head, *tail = pipeline([transient_state], configs, env_processes, range(1))\n", - "# head" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
mech_steps1s2s3s4time_steptimestamp
00001102018-10-01 15:16:24
1122101012018-10-01 15:16:25
2288101012018-10-01 15:16:25
332626101012018-10-01 15:16:25
41808010.112726504816649253370997039.37358308881163115877654945522018-10-01 15:16:26
5224224210.487346933264530942349835278.62016626166331414223691548622018-10-01 15:16:26
6372872811.913242135270736405637596086.53487634630409385728984067922018-10-01 15:16:26
712186218612.511116777442378299065991315.93118968315566923726363952432018-10-01 15:16:27
826560656011.454911154069123325574886575.32390954820124880401133424332018-10-01 15:16:27
93196821968211.454922335748109247037327945.92230524696739109178457843432018-10-01 15:16:27
101590485904812.076182995004145018523314635.84418161166074604232339800642018-10-01 15:16:28
11217714617714611.697584759271524237502733504.89550411635805911556400983142018-10-01 15:16:28
12353144053144012.599482274917543854537877695.21208435021169347331059511542018-10-01 15:16:28
1311594322159432210.245784765906019155373231625.02639302523665195708717849052018-10-01 15:16:29
1424782968478296812.019519313673296568461037904.15022183022198659782350351052018-10-01 15:16:29
153143489061434890613.783597733107369420213878283.90259899343079757840645896252018-10-01 15:16:29
161430467204304672013.320913592874087304819022983.67289421005976134574243413012018-10-01 15:16:30
17212914016212914016214.135275362924263979021941143.35192648688727431701794896012018-10-01 15:16:30
18338742048838742048814.203083115462195268554008013.36188633936078126094148887512018-10-01 15:16:30
1911162261466116226146613.025455373078228464709385942.60604763174302514928546198222018-10-01 15:16:31
2023486784400348678440013.139701926642296107045657042.53626761436770894889616035022018-10-01 15:16:31
213104603532021046035320214.454152883328036879921982482.79323804947474113589163469322018-10-01 15:16:31
221313810596083138105960813.903315932242113053109733563.03144478726104496774484686232018-10-01 15:16:32
232941431788269414317882613.381010864727075518935673553.36738570925962364852446784732018-10-01 15:16:32
24328242953648028242953648013.281361455988187967283749923.74432771883958405206048476132018-10-01 15:16:32
25184728860944284728860944213.857103600947317486522392684.30131261704849550334644855142018-10-01 15:16:33
2622541865828328254186582832815.628566944464974852221883993.82029653270196969121269357842018-10-01 15:16:33
2737625597484986762559748498614.636654143538757371444815344.14342997592437414219689284642018-10-01 15:16:33
281228767924549602287679245496015.380776140741954938013357143.37238343031412003190807879252018-10-01 15:16:34
292686303773648826863037736488215.713179332019243508422954943.16906745680040532299196548052018-10-01 15:16:34
30320589113209464820589113209464812.792708358832171308040157612.56235835182925122342346616352018-10-01 15:16:34
\n", - "
" - ], - "text/plain": [ - " mech_step s1 s2 \\\n", - "0 0 0 0 \n", - "1 1 2 2 \n", - "2 2 8 8 \n", - "3 3 26 26 \n", - "4 1 80 80 \n", - "5 2 242 242 \n", - "6 3 728 728 \n", - "7 1 2186 2186 \n", - "8 2 6560 6560 \n", - "9 3 19682 19682 \n", - "10 1 59048 59048 \n", - "11 2 177146 177146 \n", - "12 3 531440 531440 \n", - "13 1 1594322 1594322 \n", - "14 2 4782968 4782968 \n", - "15 3 14348906 14348906 \n", - "16 1 43046720 43046720 \n", - "17 2 129140162 129140162 \n", - "18 3 387420488 387420488 \n", - "19 1 1162261466 1162261466 \n", - "20 2 3486784400 3486784400 \n", - "21 3 10460353202 10460353202 \n", - "22 1 31381059608 31381059608 \n", - "23 2 94143178826 94143178826 \n", - "24 3 282429536480 282429536480 \n", - "25 1 847288609442 847288609442 \n", - "26 2 2541865828328 2541865828328 \n", - "27 3 7625597484986 7625597484986 \n", - "28 1 22876792454960 22876792454960 \n", - "29 2 68630377364882 68630377364882 \n", - "30 3 205891132094648 205891132094648 \n", - "\n", - " s3 s4 time_step \\\n", - "0 1 1 0 \n", - "1 10 10 1 \n", - "2 10 10 1 \n", - "3 10 10 1 \n", - "4 10.11272650481664925337099703 9.373583088811631158776549455 2 \n", - "5 10.48734693326453094234983527 8.620166261663314142236915486 2 \n", - "6 11.91324213527073640563759608 6.534876346304093857289840679 2 \n", - "7 12.51111677744237829906599131 5.931189683155669237263639524 3 \n", - "8 11.45491115406912332557488657 5.323909548201248804011334243 3 \n", - "9 11.45492233574810924703732794 5.922305246967391091784578434 3 \n", - "10 12.07618299500414501852331463 5.844181611660746042323398006 4 \n", - "11 11.69758475927152423750273350 4.895504116358059115564009831 4 \n", - "12 12.59948227491754385453787769 5.212084350211693473310595115 4 \n", - "13 10.24578476590601915537323162 5.026393025236651957087178490 5 \n", - "14 12.01951931367329656846103790 4.150221830221986597823503510 5 \n", - "15 13.78359773310736942021387828 3.902598993430797578406458962 5 \n", - "16 13.32091359287408730481902298 3.672894210059761345742434130 1 \n", - "17 14.13527536292426397902194114 3.351926486887274317017948960 1 \n", - "18 14.20308311546219526855400801 3.361886339360781260941488875 1 \n", - "19 13.02545537307822846470938594 2.606047631743025149285461982 2 \n", - "20 13.13970192664229610704565704 2.536267614367708948896160350 2 \n", - "21 14.45415288332803687992198248 2.793238049474741135891634693 2 \n", - "22 13.90331593224211305310973356 3.031444787261044967744846862 3 \n", - "23 13.38101086472707551893567355 3.367385709259623648524467847 3 \n", - "24 13.28136145598818796728374992 3.744327718839584052060484761 3 \n", - "25 13.85710360094731748652239268 4.301312617048495503346448551 4 \n", - "26 15.62856694446497485222188399 3.820296532701969691212693578 4 \n", - "27 14.63665414353875737144481534 4.143429975924374142196892846 4 \n", - "28 15.38077614074195493801335714 3.372383430314120031908078792 5 \n", - "29 15.71317933201924350842295494 3.169067456800405322991965480 5 \n", - "30 12.79270835883217130804015761 2.562358351829251223423466163 5 \n", - "\n", - " timestamp \n", - "0 2018-10-01 15:16:24 \n", - "1 2018-10-01 15:16:25 \n", - "2 2018-10-01 15:16:25 \n", - "3 2018-10-01 15:16:25 \n", - "4 2018-10-01 15:16:26 \n", - "5 2018-10-01 15:16:26 \n", - "6 2018-10-01 15:16:26 \n", - "7 2018-10-01 15:16:27 \n", - "8 2018-10-01 15:16:27 \n", - "9 2018-10-01 15:16:27 \n", - "10 2018-10-01 15:16:28 \n", - "11 2018-10-01 15:16:28 \n", - "12 2018-10-01 15:16:28 \n", - "13 2018-10-01 15:16:29 \n", - "14 2018-10-01 15:16:29 \n", - "15 2018-10-01 15:16:29 \n", - "16 2018-10-01 15:16:30 \n", - "17 2018-10-01 15:16:30 \n", - "18 2018-10-01 15:16:30 \n", - "19 2018-10-01 15:16:31 \n", - "20 2018-10-01 15:16:31 \n", - "21 2018-10-01 15:16:31 \n", - "22 2018-10-01 15:16:32 \n", - "23 2018-10-01 15:16:32 \n", - "24 2018-10-01 15:16:32 \n", - "25 2018-10-01 15:16:33 \n", - "26 2018-10-01 15:16:33 \n", - "27 2018-10-01 15:16:33 \n", - "28 2018-10-01 15:16:34 \n", - "29 2018-10-01 15:16:34 \n", - "30 2018-10-01 15:16:34 " - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pd.DataFrame(flatten(s))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "# pd.DataFrame(flatten(p))" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "# flatten(pipeline(states_list, configs, env_processes, range(10)))" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
mech_steps1s2s3s4time_steptimestamp
00001102018-10-01 15:16:24
1122101012018-10-01 15:16:25
2288101012018-10-01 15:16:25
332626101012018-10-01 15:16:25
41808010.3260034333869810119210797011.7746450314059347697082103022018-10-01 15:16:26
522422428.21916515274784955205371299110.9801773387214634804305097322018-10-01 15:16:26
637287288.25718333114068459995979706311.1455573279124922629545779522018-10-01 15:16:26
71218621867.69761418303725988415748507911.3160238377322023420946343232018-10-01 15:16:27
82656065606.58958955625320624245355845710.1117779289454360207806075732018-10-01 15:16:27
9319682196826.93507938421090996234107250610.5546198167452742497326965132018-10-01 15:16:27
10159048590487.44500160717102196461960229712.6011378649838055327415438142018-10-01 15:16:28
1121771461771466.95865667781136112301155569011.3096083396823127488043278442018-10-01 15:16:28
1235314405314407.54489308076341439053948261912.3267248984101325124126510442018-10-01 15:16:28
131159432215943227.25704297441675434129273706612.1362685525819409923474763752018-10-01 15:16:29
142478296847829687.30529433408675028875311565914.2839357716573656718733737352018-10-01 15:16:29
15314348906143489066.50263319367367710575799849814.9749759400775891229965018052018-10-01 15:16:29
16143046720430467207.53296700646015886683024862215.9876083719011149813759189962018-10-01 15:16:30
1721291401621291401625.52961250543163593871152160917.0158726368362632068794171462018-10-01 15:16:30
1833874204883874204885.47904274871256495704604649817.4397154045538409948107159962018-10-01 15:16:30
191116226146611622614665.85990175186463137404836714815.0055435787421793737865330072018-10-01 15:16:31
202348678440034867844004.66831033426642853326666637117.0938094196505573185825817172018-10-01 15:16:31
21310460353202104603532024.57986020161816165272325721714.7508139318520774978598645372018-10-01 15:16:31
22131381059608313810596084.54449513239095366886914084415.1027140580688841666002539582018-10-01 15:16:32
23294143178826941431788264.91928101177860913117888377016.0301371246650606644045462482018-10-01 15:16:32
2432824295364802824295364805.53331202367358005176345704114.6869522616793077505417237282018-10-01 15:16:32
2518472886094428472886094425.30982582865393698162295633314.9000059117257340823484719292018-10-01 15:16:33
262254186582832825418658283284.57467053107137237917651360616.6401512087351580090579643392018-10-01 15:16:33
273762559748498676255974849865.20013569135900153491197292216.6000410060559880661690522992018-10-01 15:16:33
28122876792454960228767924549605.83345274620393831999132966515.12486604838650902185343711102018-10-01 15:16:34
29268630377364882686303773648825.56394410950931399948902225610.71485175557766753591769425102018-10-01 15:16:34
3032058911320946482058911320946485.7591765064867251346787523629.673539064064506702922033631102018-10-01 15:16:34
\n", - "
" - ], - "text/plain": [ - " mech_step s1 s2 \\\n", - "0 0 0 0 \n", - "1 1 2 2 \n", - "2 2 8 8 \n", - "3 3 26 26 \n", - "4 1 80 80 \n", - "5 2 242 242 \n", - "6 3 728 728 \n", - "7 1 2186 2186 \n", - "8 2 6560 6560 \n", - "9 3 19682 19682 \n", - "10 1 59048 59048 \n", - "11 2 177146 177146 \n", - "12 3 531440 531440 \n", - "13 1 1594322 1594322 \n", - "14 2 4782968 4782968 \n", - "15 3 14348906 14348906 \n", - "16 1 43046720 43046720 \n", - "17 2 129140162 129140162 \n", - "18 3 387420488 387420488 \n", - "19 1 1162261466 1162261466 \n", - "20 2 3486784400 3486784400 \n", - "21 3 10460353202 10460353202 \n", - "22 1 31381059608 31381059608 \n", - "23 2 94143178826 94143178826 \n", - "24 3 282429536480 282429536480 \n", - "25 1 847288609442 847288609442 \n", - "26 2 2541865828328 2541865828328 \n", - "27 3 7625597484986 7625597484986 \n", - "28 1 22876792454960 22876792454960 \n", - "29 2 68630377364882 68630377364882 \n", - "30 3 205891132094648 205891132094648 \n", - "\n", - " s3 s4 time_step \\\n", - "0 1 1 0 \n", - "1 10 10 1 \n", - "2 10 10 1 \n", - "3 10 10 1 \n", - "4 10.32600343338698101192107970 11.77464503140593476970821030 2 \n", - "5 8.219165152747849552053712991 10.98017733872146348043050973 2 \n", - "6 8.257183331140684599959797063 11.14555732791249226295457795 2 \n", - "7 7.697614183037259884157485079 11.31602383773220234209463432 3 \n", - "8 6.589589556253206242453558457 10.11177792894543602078060757 3 \n", - "9 6.935079384210909962341072506 10.55461981674527424973269651 3 \n", - "10 7.445001607171021964619602297 12.60113786498380553274154381 4 \n", - "11 6.958656677811361123011555690 11.30960833968231274880432784 4 \n", - "12 7.544893080763414390539482619 12.32672489841013251241265104 4 \n", - "13 7.257042974416754341292737066 12.13626855258194099234747637 5 \n", - "14 7.305294334086750288753115659 14.28393577165736567187337373 5 \n", - "15 6.502633193673677105757998498 14.97497594007758912299650180 5 \n", - "16 7.532967006460158866830248622 15.98760837190111498137591899 6 \n", - "17 5.529612505431635938711521609 17.01587263683626320687941714 6 \n", - "18 5.479042748712564957046046498 17.43971540455384099481071599 6 \n", - "19 5.859901751864631374048367148 15.00554357874217937378653300 7 \n", - "20 4.668310334266428533266666371 17.09380941965055731858258171 7 \n", - "21 4.579860201618161652723257217 14.75081393185207749785986453 7 \n", - "22 4.544495132390953668869140844 15.10271405806888416660025395 8 \n", - "23 4.919281011778609131178883770 16.03013712466506066440454624 8 \n", - "24 5.533312023673580051763457041 14.68695226167930775054172372 8 \n", - "25 5.309825828653936981622956333 14.90000591172573408234847192 9 \n", - "26 4.574670531071372379176513606 16.64015120873515800905796433 9 \n", - "27 5.200135691359001534911972922 16.60004100605598806616905229 9 \n", - "28 5.833452746203938319991329665 15.12486604838650902185343711 10 \n", - "29 5.563944109509313999489022256 10.71485175557766753591769425 10 \n", - "30 5.759176506486725134678752362 9.673539064064506702922033631 10 \n", - "\n", - " timestamp \n", - "0 2018-10-01 15:16:24 \n", - "1 2018-10-01 15:16:25 \n", - "2 2018-10-01 15:16:25 \n", - "3 2018-10-01 15:16:25 \n", - "4 2018-10-01 15:16:26 \n", - "5 2018-10-01 15:16:26 \n", - "6 2018-10-01 15:16:26 \n", - "7 2018-10-01 15:16:27 \n", - "8 2018-10-01 15:16:27 \n", - "9 2018-10-01 15:16:27 \n", - "10 2018-10-01 15:16:28 \n", - "11 2018-10-01 15:16:28 \n", - "12 2018-10-01 15:16:28 \n", - "13 2018-10-01 15:16:29 \n", - "14 2018-10-01 15:16:29 \n", - "15 2018-10-01 15:16:29 \n", - "16 2018-10-01 15:16:30 \n", - "17 2018-10-01 15:16:30 \n", - "18 2018-10-01 15:16:30 \n", - "19 2018-10-01 15:16:31 \n", - "20 2018-10-01 15:16:31 \n", - "21 2018-10-01 15:16:31 \n", - "22 2018-10-01 15:16:32 \n", - "23 2018-10-01 15:16:32 \n", - "24 2018-10-01 15:16:32 \n", - "25 2018-10-01 15:16:33 \n", - "26 2018-10-01 15:16:33 \n", - "27 2018-10-01 15:16:33 \n", - "28 2018-10-01 15:16:34 \n", - "29 2018-10-01 15:16:34 \n", - "30 2018-10-01 15:16:34 " - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "states_list = [state_dict]\n", - "configs = generate_config(mechanisms, exogenous_states)\n", - "# type(pipeline(states_list, configs, env_processes, range(10)))\n", - "pd.DataFrame(flatten(pipeline(states_list, configs, env_processes, range(10))))" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[0, 1]" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list(range(2))" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'non_numeric' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mstate_dict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;34m's1'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'3323'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m's2'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'2572'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m's3'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'2.657'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m's4'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'7.914'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'timestamp'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'2018-10-01 15:16:26'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'mech_step'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'time_step'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mstate_dict\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mv\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mquantize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mTWOPLACES\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mROUND_DOWN\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mk\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mv\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mstate_dict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mstate_dict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnon_numeric\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[0mstate_dict\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mNameError\u001b[0m: name 'non_numeric' is not defined" - ] - } - ], - "source": [ - "# Decimal('240.0').quantize(Decimal('0.01'), ROUND_DOWN)\n", - "# round(Decimal('240.01'), 2)\n", - "state_dict = {'s1': Decimal('3323'), 's2': Decimal('2572'), 's3': Decimal('2.657'), 's4': Decimal('7.914'), 'timestamp': '2018-10-01 15:16:26', 'mech_step': 1, 'time_step': 2}\n", - "state_dict = {k: v.quantize(TWOPLACES, ROUND_DOWN) for k, v in state_dict.items() if type(v) == Decimal}\n", - "state_dict.update(non_numeric)\n", - "state_dict" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "states_list = [state_dict]\n", - "states_list\n", - "# {'s1': 8.742503764992283e+170,\n", - "# 's2': 1.119720780594405e+171,\n", - "# 's3': 4.251811100418906,\n", - "# 's4': 6.92728042985628,\n", - "# 'timestamp': '2018-10-01 15:16:31',\n", - "# 'mech_step': 3,\n", - "# 'time_step': 7}\n", - "# {'s1': Decimal('2.221384236472411425810660220E+330'),\n", - "# 's2': Decimal('2.845096899831187764579913612E+330'),\n", - "# 's3': Decimal('3.622519693611211445932083740'),\n", - "# 's4': Decimal('5.161487081026327858663750787'),\n", - "# 'timestamp': '2018-10-01 15:16:32',\n", - "# 'mech_step': 3,\n", - "# 'time_step': 8}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from decimal import Decimal, MAX_EMAX\n", - "# Decimal(2.5347751615574597e+167)**2\n", - "MAX_EMAX**5" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "1000 * 1000" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "from datetime import datetime, timedelta\n", - "# from datetime import timedelta \n", - "# st = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')\n", - "st = datetime.now()\n", - "print(st)\n", - "x = st + timedelta(seconds=60)\n", - "print(x)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "s = datetime.now().strftime('%Y-%m-%d %H:%M:%S')\n", - "datetime_object = datetime.strptime(s, '%Y-%m-%d %H:%M:%S')\n", - "datetime_object" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "datetime.fromtimestamp()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from datetime import datetime, timedelta\n", - "\n", - "# def time_step_func(year, month, day, hour, minute, second):\n", - "a = datetime(2016, 11, 15, 9, 59, 25)#.strftime(\"%Y-%m-%d %H:%M:%S\")\n", - "b = a + timedelta(seconds=60) # days, seconds, then other fields.\n", - "print(a)\n", - "print(b)\n", - "st = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')\n", - "def time_step_func(dt_str, fromat_str='%Y-%m-%d %H:%M:%S', days=0, minutes=0, seconds=1):\n", - " dt = datetime.strptime(dt_str, fromat_str)\n", - " t = dt + timedelta(days=days, minutes=minutes, seconds=seconds)\n", - " return t.strftime(fromat_str)\n", - "\n", - "time_step_func('2018-10-01 15:16:24')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def time_step_func(x, y):\n", - " return x + y" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for m in M: #M is the parameter sweep array\n", - " # for Pairwise, run below separately\n", - " for n in N: #N is the total number of Montecarlo runs\n", - " for t in T: #T[len(T)]-T[0] is the duration of each simulation\n", - " # Pipeline\n", - " for b in Behaviors:\n", - " for M in Mechanisms:\n", - " for s in States:\n", - " update(s)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "[{'s1': 2}] + [{'s1': 3}]\n", - "list(zip([block_gen] * 2, range(2)))\n", - "len([0,1])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "states_list = [state_dict]\n", - "configs = generate_config(mechanisms, exogenous_states)\n", - "def step_func(x, y):\n", - " return x + y\n", - "pipeline(states_list, configs, env_processes, step_func)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# def s3step1(step, sL, s, _input):\n", - "# s['s3'] = s['s3'] \n", - "# # def s3step2(step, sL, s, _input):\n", - "# s['s3'] = s['s3'] + 1\n", - "# def s3step3(step, sL, s, _input):\n", - "# s['s3'] = s['s3'] * bound_norm_random(proc_one_coef_A, proc_one_coef_B)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# 15 + 28.933333333333334 + 4" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# def multiply(x,y,z):\n", - "# return x * y * z\n", - "\n", - "# # create a new function that multiplies by 2\n", - "# dbl = partial(partial(multiply,2), multiply, 2)\n", - "# print(dbl(2))" - ] - } - ], - "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 -} diff --git a/notebooks/Sim_CAD_Engine.ipynb b/notebooks/Sim_CAD_Engine.ipynb deleted file mode 100644 index 08a6f8e..0000000 --- a/notebooks/Sim_CAD_Engine.ipynb +++ /dev/null @@ -1,877 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 491, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "from scipy.stats import poisson\n", - "import numpy as np\n", - "import math\n", - "import seaborn as sns\n", - "import matplotlib as mpl\n", - "import matplotlib.pyplot as plt" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# UTILS" - ] - }, - { - "cell_type": "code", - "execution_count": 492, - "metadata": {}, - "outputs": [], - "source": [ - "def bound_norm_random(low, high):\n", - " res = np.random.normal((high+low)/2,(high-low)/6)\n", - " if (reshigh):\n", - " res = bound_norm_random(low, high)\n", - " return res" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# TYPE/PHASE" - ] - }, - { - "cell_type": "code", - "execution_count": 493, - "metadata": {}, - "outputs": [], - "source": [ - "EXPERIMENT_TYPES = ['1 off run', 'Monte Carlo', 'Monte Carlo Parameter Sweep', 'Monte Carlo Pairwise']\n", - "\n", - "experiment_type = EXPERIMENT_TYPES[1]\n", - "monte_carlo_runs = 100\n", - "\n", - "#correct number of runs if inconsistent with experiment type\n", - "if (experiment_type == EXPERIMENT_TYPES[0]):\n", - " monte_carlo_runs = 1" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# TIMESCALE" - ] - }, - { - "cell_type": "code", - "execution_count": 494, - "metadata": {}, - "outputs": [], - "source": [ - "SECOND = 1\n", - "MINUTE = 60*SECOND\n", - "HOUR = 60*MINUTE\n", - "DAY = 24*HOUR\n", - "DURATION_OF_A_STEP = 1*DAY\n", - "\n", - "experiment_steps = 1000\n", - "experiment_duration = experiment_steps * DURATION_OF_A_STEP\n", - "time_array = np.arange(0,experiment_steps*DURATION_OF_A_STEP,DURATION_OF_A_STEP)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# MECHANISMS (dimension)" - ] - }, - { - "cell_type": "code", - "execution_count": 495, - "metadata": {}, - "outputs": [], - "source": [ - "mechanisms_names = ['mech_one', 'mech_two', 'mech_three']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# STATES (dimension)" - ] - }, - { - "cell_type": "code", - "execution_count": 496, - "metadata": {}, - "outputs": [], - "source": [ - "states_names = ['a', 'b', 'c']\n", - "states_data = [[np.zeros(experiment_steps)]*len(states_names)]*monte_carlo_runs\n", - "states_data = np.zeros((monte_carlo_runs, experiment_steps, len(states_names)), dtype=int)\n", - "# states_data is a 3-dimensional array - montecarlo, time, states\n", - "# montecarlo[time[states]]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Initial Conditions" - ] - }, - { - "cell_type": "code", - "execution_count": 497, - "metadata": {}, - "outputs": [], - "source": [ - "states_0 = {\n", - " 'a': 0,\n", - " 'b': 0,\n", - " 'c': 300\n", - "}\n", - "# an initial condition must be set for every state\n", - "assert np.array([k in states_0 for k in states_names]).all(), 'Error: The initial condition of one or more states is unkonwn'\n", - "\n", - "# copy initial condition to the states dataset\n", - "for i in range(len(states_names)):\n", - " states_data[:,0,i] = states_0[states_names[i]]" - ] - }, - { - "cell_type": "code", - "execution_count": 498, - "metadata": {}, - "outputs": [], - "source": [ - "T_0 = 0\n", - "time_array = T_0 + time_array" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Mechanisms Coef (params)" - ] - }, - { - "cell_type": "code", - "execution_count": 499, - "metadata": {}, - "outputs": [], - "source": [ - "mech_one_coef_A = 0.05" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# MECHANISMS EQUATIONS (func)" - ] - }, - { - "cell_type": "code", - "execution_count": 500, - "metadata": {}, - "outputs": [], - "source": [ - "# state/mechanism matrix\n", - "def mech_one(_states_data, _time_array, _run, _step, args):\n", - "# print('mech 1')\n", - " _states_data[_run, _step, states_names.index('a')] += (1-mech_one_coef_A)*args[0]\n", - " _states_data[_run, _step, states_names.index('b')] += mech_one_coef_A*args[0]\n", - " return _states_data\n", - "\n", - "def mech_two(_states_data, _time_array, _run, _step, args):\n", - "# print('mech 2')\n", - " _states_data[_run, _step, states_names.index('a')] -= args[0]\n", - " return _states_data\n", - "\n", - "def mech_three(_states_data, _time_array, _run, _step, args):\n", - "# print('mech 3')\n", - " _states_data[_run, _step, states_names.index('b')] -= args[0]\n", - " return _states_data\n", - "\n", - "def mech_four(_states_data, _time_array, _run, _step):\n", - "# print('mech 4')\n", - " _states_data[_run, _step, states_names.index('a')] = _states_data[_run, _step-1, states_names.index('a')]\n", - " _states_data[_run, _step, states_names.index('b')] = _states_data[_run, _step-1, states_names.index('b')] \n", - " return _states_data\n", - "\n", - "mechanisms = [eval(m) for m in mechanisms_names]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Behavioral Model Coef (params) " - ] - }, - { - "cell_type": "code", - "execution_count": 501, - "metadata": {}, - "outputs": [], - "source": [ - "behavior_one_coef_A = 0.01\n", - "behavior_one_coef_B = -0.01\n", - "\n", - "behavior_two_coef_A = 1" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# BEHAVIORAL MODEL (func)" - ] - }, - { - "cell_type": "code", - "execution_count": 502, - "metadata": {}, - "outputs": [], - "source": [ - "behaviors_names = ['behavior_one', 'behavior_two']\n", - "def behavior_one(_states_data, _time_array, _run, _step): \n", - " c_var = ( _states_data[_run, _step, states_names.index('c')]\n", - " - _states_data[_run, _step-1, states_names.index('c')] )\n", - " c_var_perc = c_var / _states_data[_run, _step-1, states_names.index('c')]\n", - " \n", - " if (c_var_perc > behavior_one_coef_A):\n", - " return mech_one(_states_data, _time_array, _run, _step, [c_var])\n", - " elif (c_var_perc < behavior_one_coef_B):\n", - " return mech_two(_states_data, _time_array, _run, _step, [-c_var])\n", - " return _states_data\n", - "\n", - "def behavior_two(_states_data, _time_array, _run, _step):\n", - " b_balance = _states_data[_run, _step-1, states_names.index('b')]\n", - " if (b_balance > behavior_two_coef_A):\n", - " return mech_three(_states_data, _time_array, _run, _step, [b_balance])\n", - " return _states_data\n", - "\n", - "behaviors = [eval(b) for b in behaviors_names] " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# ENVIRONMENTAL PROCESS (dimension)" - ] - }, - { - "cell_type": "code", - "execution_count": 503, - "metadata": {}, - "outputs": [], - "source": [ - "env_proc_names = ['proc_one']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Stochastic Process Coef (params)" - ] - }, - { - "cell_type": "code", - "execution_count": 504, - "metadata": {}, - "outputs": [], - "source": [ - "proc_one_coef_A = 0.7\n", - "proc_one_coef_B = 1.3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# ENVIRONMENTAL PROCESS (func)" - ] - }, - { - "cell_type": "code", - "execution_count": 505, - "metadata": {}, - "outputs": [], - "source": [ - "def proc_one(_states_data, _time_array, _run, _step):\n", - " _states_data[_run, _step, states_names.index('a')] = _states_data[_run, _step-1, states_names.index('a')]\n", - " _states_data[_run, _step, states_names.index('b')] = _states_data[_run, _step-1, states_names.index('b')] \n", - " _states_data[_run, _step, states_names.index('c')] = ( _states_data[_run, _step-1, states_names.index('c')]\n", - " * bound_norm_random(proc_one_coef_A, proc_one_coef_B) )\n", - " return _states_data\n", - "\n", - "env_proc = [eval(p) for p in env_proc_names]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# ENGINE" - ] - }, - { - "cell_type": "code", - "execution_count": 506, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/markusbkoch/.local/share/virtualenvs/DiffyQ-SimCAD-4_qpgnP9/lib/python3.6/site-packages/ipykernel_launcher.py:5: RuntimeWarning: invalid value encountered in long_scalars\n", - " \"\"\"\n" - ] - } - ], - "source": [ - "for i in range(monte_carlo_runs):\n", - " for t in range(1,experiment_steps):\n", - " for p in env_proc:\n", - " states_data = p(_states_data=states_data,\n", - " _time_array=time_array, \n", - " _run=i, \n", - " _step=t)\n", - " for b in behaviors:\n", - " states_data = b(_states_data=states_data,\n", - " _time_array=time_array, \n", - " _run=i, \n", - " _step=t) #behaviors have access to exogenous data @ step-1, not @ step" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# DATA COLLECTION" - ] - }, - { - "cell_type": "code", - "execution_count": 507, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
abc
0000300
86400-70293
172800-200280
259200-860214
345600-671234
432000-671233
518400-911209
604800-991201
691200-931207
777600-1041196
864000-1011199
950400-861214
1036800-921208
1123200-921210
1209600-991203
1296000-1221180
1382400-1351167
1468800-1611141
1555200-1611141
1641600-1871115
1728000-1951107
1814400-2011101
1900800-1891113
1987200-1891112
2073600-1891111
2160000-1911109
2246400-2001100
2332800-206194
2419200-206194
2505600-218182
...............
9983808000-38600
83894400-38600
83980800-38600
84067200-38600
84153600-38600
84240000-38600
84326400-38600
84412800-38600
84499200-38600
84585600-38600
84672000-38600
84758400-38600
84844800-38600
84931200-38600
85017600-38600
85104000-38600
85190400-38600
85276800-38600
85363200-38600
85449600-38600
85536000-38600
85622400-38600
85708800-38600
85795200-38600
85881600-38600
85968000-38600
86054400-38600
86140800-38600
86227200-38600
86313600-38600
\n", - "

100000 rows × 3 columns

\n", - "
" - ], - "text/plain": [ - " a b c\n", - "0 0 0 0 300\n", - " 86400 -7 0 293\n", - " 172800 -20 0 280\n", - " 259200 -86 0 214\n", - " 345600 -67 1 234\n", - " 432000 -67 1 233\n", - " 518400 -91 1 209\n", - " 604800 -99 1 201\n", - " 691200 -93 1 207\n", - " 777600 -104 1 196\n", - " 864000 -101 1 199\n", - " 950400 -86 1 214\n", - " 1036800 -92 1 208\n", - " 1123200 -92 1 210\n", - " 1209600 -99 1 203\n", - " 1296000 -122 1 180\n", - " 1382400 -135 1 167\n", - " 1468800 -161 1 141\n", - " 1555200 -161 1 141\n", - " 1641600 -187 1 115\n", - " 1728000 -195 1 107\n", - " 1814400 -201 1 101\n", - " 1900800 -189 1 113\n", - " 1987200 -189 1 112\n", - " 2073600 -189 1 111\n", - " 2160000 -191 1 109\n", - " 2246400 -200 1 100\n", - " 2332800 -206 1 94\n", - " 2419200 -206 1 94\n", - " 2505600 -218 1 82\n", - "... ... .. ...\n", - "99 83808000 -386 0 0\n", - " 83894400 -386 0 0\n", - " 83980800 -386 0 0\n", - " 84067200 -386 0 0\n", - " 84153600 -386 0 0\n", - " 84240000 -386 0 0\n", - " 84326400 -386 0 0\n", - " 84412800 -386 0 0\n", - " 84499200 -386 0 0\n", - " 84585600 -386 0 0\n", - " 84672000 -386 0 0\n", - " 84758400 -386 0 0\n", - " 84844800 -386 0 0\n", - " 84931200 -386 0 0\n", - " 85017600 -386 0 0\n", - " 85104000 -386 0 0\n", - " 85190400 -386 0 0\n", - " 85276800 -386 0 0\n", - " 85363200 -386 0 0\n", - " 85449600 -386 0 0\n", - " 85536000 -386 0 0\n", - " 85622400 -386 0 0\n", - " 85708800 -386 0 0\n", - " 85795200 -386 0 0\n", - " 85881600 -386 0 0\n", - " 85968000 -386 0 0\n", - " 86054400 -386 0 0\n", - " 86140800 -386 0 0\n", - " 86227200 -386 0 0\n", - " 86313600 -386 0 0\n", - "\n", - "[100000 rows x 3 columns]" - ] - }, - "execution_count": 507, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data = pd.DataFrame(states_data[0], \n", - " index=[[0]*experiment_steps, time_array], \n", - " columns=states_names)\n", - "for i in range(1,monte_carlo_runs):\n", - " b = pd.DataFrame(states_data[i],\n", - " index=[[i]*experiment_steps, time_array], \n", - " columns=states_names)\n", - " data = data.append(b)\n", - "data" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "DiffyQ-SimCAD Env", - "language": "python", - "name": "diffyq-simcad" - }, - "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 -} diff --git a/notebooks/TestNotebook.ipynb b/notebooks/TestNotebook.ipynb deleted file mode 100644 index 51d7dc7..0000000 --- a/notebooks/TestNotebook.ipynb +++ /dev/null @@ -1,35 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "assert pd.__version__ == '0.23.4'" - ] - } - ], - "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 -} diff --git a/notebooks/config_padding.ipynb b/notebooks/config_padding.ipynb deleted file mode 100644 index e70f546..0000000 --- a/notebooks/config_padding.ipynb +++ /dev/null @@ -1,748 +0,0 @@ -{ - "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": [ - "[[,\n", - " ],\n", - " [,\n", - " ],\n", - " [.identity(step, sL, s)>,\n", - " .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": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
b1b2s1s2es0es1es2m
0<function b1m1 at 0x10af42158><function b2m1 at 0x10af42268><function s1m1 at 0x10af42510><function s2m1 at 0x10af42598><function es3p1 at 0x10af42840><function es4p2 at 0x10af428c8><function es5p2 at 0x10af42950>1
1<function b1m2 at 0x10af422f0><function b2m2 at 0x10af42400><function s1m2 at 0x10af42620><function state_identity.<locals>.identity at ...<function es3p1 at 0x10af42840><function es4p2 at 0x10af428c8><function es5p2 at 0x10af42950>2
2<function behavior_identity.<locals>.identity ...<function behavior_identity.<locals>.identity ...<function s1m3 at 0x10af42730><function state_identity.<locals>.identity at ...<function es3p1 at 0x10af42840><function es4p2 at 0x10af428c8><function es5p2 at 0x10af42950>3
\n", - "
" - ], - "text/plain": [ - " b1 \\\n", - "0 \n", - "1 \n", - "2 .identity ... \n", - "\n", - " b2 \\\n", - "0 \n", - "1 \n", - "2 .identity ... \n", - "\n", - " s1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " s2 \\\n", - "0 \n", - "1 .identity at ... \n", - "2 .identity at ... \n", - "\n", - " es0 es1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " es2 m \n", - "0 1 \n", - "1 2 \n", - "2 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": [ - "[([,\n", - " ,\n", - " ,\n", - " ,\n", - " ],\n", - " [,\n", - " ]),\n", - " ([,\n", - " ,\n", - " ,\n", - " ],\n", - " [,\n", - " ]),\n", - " ([,\n", - " ,\n", - " ,\n", - " ],\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": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
b1b2s1s2es0es1es2m
0<function b1m1 at 0x118771e18><function b2m1 at 0x1188d7d90><function s1m1 at 0x1188d7730><function s2m1 at 0x1188ed730><function es3p1 at 0x1188ed400><function es4p2 at 0x1188ed378><function es5p2 at 0x1188ed158>1
1<function b1m2 at 0x1188d70d0><function b2m2 at 0x1188d7840><function s1m2 at 0x1188ed620><function state_identity.<locals>.identity at ...<function es3p1 at 0x1188ed400><function es4p2 at 0x1188ed378><function es5p2 at 0x1188ed158>2
2<function b1m3 at 0x1188d7ea0><function behavior_identity.<locals>.identity ...<function s1m3 at 0x1188d7a60><function s2m3 at 0x1188ed268><function es3p1 at 0x1188ed400><function es4p2 at 0x1188ed378><function es5p2 at 0x1188ed158>3
\n", - "
" - ], - "text/plain": [ - " b1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " b2 \\\n", - "0 \n", - "1 \n", - "2 .identity ... \n", - "\n", - " s1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " s2 \\\n", - "0 \n", - "1 .identity at ... \n", - "2 \n", - "\n", - " es0 es1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " es2 m \n", - "0 1 \n", - "1 2 \n", - "2 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": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
b1b2
0<function b1m1 at 0x1108c88c8><function b2m1 at 0x1108c89d8>
1<function b1m2 at 0x1108c8d90><function b2m2 at 0x1108c8a60>
2<function b1m3 at 0x1108c8c80><function behavior_identity.<locals>.identity ...
\n", - "
" - ], - "text/plain": [ - " b1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " b2 \n", - "0 \n", - "1 \n", - "2 .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": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
b1b2s1s2es0es1es2m
0<function b1m1 at 0x1105ed9d8><function b2m1 at 0x1105edbf8><function s1m1 at 0x1105c69d8><function s2m1 at 0x1105ede18><function es3p1 at 0x1187710d0><function es4p2 at 0x118771158><function es5p2 at 0x1187711e0>1
1<function b1m2 at 0x1105edc80><function b2m2 at 0x1105edd08><function s1m2 at 0x1105edea0><function state_identity.<locals>.identity at ...<function es3p1 at 0x1187710d0><function es4p2 at 0x118771158><function es5p2 at 0x1187711e0>2
2<function b1m3 at 0x1105edb70><function behavior_identity.<locals>.identity ...<function s1m3 at 0x1105ed0d0><function s2m3 at 0x118771048><function es3p1 at 0x1187710d0><function es4p2 at 0x118771158><function es5p2 at 0x1187711e0>3
\n", - "
" - ], - "text/plain": [ - " b1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " b2 \\\n", - "0 \n", - "1 \n", - "2 .identity ... \n", - "\n", - " s1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " s2 \\\n", - "0 \n", - "1 .identity at ... \n", - "2 \n", - "\n", - " es0 es1 \\\n", - "0 \n", - "1 \n", - "2 \n", - "\n", - " es2 m \n", - "0 1 \n", - "1 2 \n", - "2 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 -} diff --git a/notebooks/test.ipynb b/notebooks/test.ipynb index 67ede2d..a8ae62a 100644 --- a/notebooks/test.ipynb +++ b/notebooks/test.ipynb @@ -2,55 +2,180 @@ "cells": [ { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "metadata": { "scrolled": false }, "outputs": [ { - "ename": "ImportError", - "evalue": "cannot import name 'run'", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mengine\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmain\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mImportError\u001b[0m: cannot import name 'run'" - ], - "output_type": "error" + "name": "stdout", + "output_type": "stream", + "text": [ + "Simulation Run 1\n", + "\n", + "single_proc: []\n", + "+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n", + "| | mech_step | run | s1 | s2 | s3 | s4 | time_step | timestamp |\n", + "|----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------|\n", + "| 0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n", + "| 1 | 1 | 1 | 1 | 4 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 2 | 2 | 1 | ab | 6 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 3 | 3 | 1 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 4 | 1 | 1 | 1 | 4 | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n", + "| 5 | 2 | 1 | ab | 6 | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n", + "| 6 | 3 | 1 | ['c', 'd'] | [ 30 300] | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n", + "| 7 | 1 | 1 | 1 | 4 | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n", + "| 8 | 2 | 1 | ab | 6 | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n", + "| 9 | 3 | 1 | ['c', 'd'] | [ 30 300] | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n", + "| 10 | 1 | 1 | 1 | 4 | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n", + "| 11 | 2 | 1 | ab | 6 | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n", + "| 12 | 3 | 1 | ['c', 'd'] | [ 30 300] | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n", + "| 13 | 1 | 1 | 1 | 4 | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n", + "| 14 | 2 | 1 | ab | 6 | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n", + "| 15 | 3 | 1 | ['c', 'd'] | [ 30 300] | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n", + "| 16 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n", + "| 17 | 1 | 2 | 1 | 4 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 18 | 2 | 2 | ab | 6 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 19 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 20 | 1 | 2 | 1 | 4 | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n", + "| 21 | 2 | 2 | ab | 6 | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n", + "| 22 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n", + "| 23 | 1 | 2 | 1 | 4 | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n", + "| 24 | 2 | 2 | ab | 6 | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n", + "| 25 | 3 | 2 | ['c', 'd'] | [ 30 300] | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n", + "| 26 | 1 | 2 | 1 | 4 | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n", + "| 27 | 2 | 2 | ab | 6 | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n", + "| 28 | 3 | 2 | ['c', 'd'] | [ 30 300] | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n", + "| 29 | 1 | 2 | 1 | 4 | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n", + "| 30 | 2 | 2 | ab | 6 | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n", + "| 31 | 3 | 2 | ['c', 'd'] | [ 30 300] | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n", + "+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n", + "\n", + "Simulation Run 2: Pairwise Execution\n", + "\n", + "multi_proc: [, ]\n", + "+----+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----+\n", + "| | b1 | b2 | s1 | s2 | es1 | es2 | es3 | m |\n", + "|----+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----|\n", + "| 0 | | | | | ._curried at 0x10fc23ae8> | ._curried at 0x10fc23b70> | ._curried at 0x10fc23bf8> | 1 |\n", + "| 1 | | | | | ._curried at 0x10fc23ae8> | ._curried at 0x10fc23b70> | ._curried at 0x10fc23bf8> | 2 |\n", + "| 2 | | | | | ._curried at 0x10fc23ae8> | ._curried at 0x10fc23b70> | ._curried at 0x10fc23bf8> | 3 |\n", + "+----+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----+\n", + "+----+--------------------------------+--------------------------------+--------------------------------+------------------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----+\n", + "| | b1 | b2 | s1 | s2 | es1 | es2 | es3 | m |\n", + "|----+--------------------------------+--------------------------------+--------------------------------+------------------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----|\n", + "| 0 | | | | . at 0x10d4f6598> | ._curried at 0x10fc29840> | ._curried at 0x10fc298c8> | ._curried at 0x10fc29950> | 1 |\n", + "| 1 | | | | . at 0x10d4f6598> | ._curried at 0x10fc29840> | ._curried at 0x10fc298c8> | ._curried at 0x10fc29950> | 2 |\n", + "| 2 | | | | | ._curried at 0x10fc29840> | ._curried at 0x10fc298c8> | ._curried at 0x10fc29950> | 3 |\n", + "+----+--------------------------------+--------------------------------+--------------------------------+------------------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----------------------------------------------------+-----+\n", + "+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n", + "| | mech_step | run | s1 | s2 | s3 | s4 | time_step | timestamp |\n", + "|----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------|\n", + "| 0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n", + "| 1 | 1 | 1 | 1 | 4 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 2 | 2 | 1 | ab | 6 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 3 | 3 | 1 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 4 | 1 | 1 | 1 | 4 | 12.2922 | 10.8846 | 2 | 2018-10-01 15:16:26 |\n", + "| 5 | 2 | 1 | ab | 6 | 12.2922 | 10.8846 | 2 | 2018-10-01 15:16:26 |\n", + "| 6 | 3 | 1 | ['c', 'd'] | [ 30 300] | 12.2922 | 10.8846 | 2 | 2018-10-01 15:16:26 |\n", + "| 7 | 1 | 1 | 1 | 4 | 12.3433 | 11.8439 | 3 | 2018-10-01 15:16:27 |\n", + "| 8 | 2 | 1 | ab | 6 | 12.3433 | 11.8439 | 3 | 2018-10-01 15:16:27 |\n", + "| 9 | 3 | 1 | ['c', 'd'] | [ 30 300] | 12.3433 | 11.8439 | 3 | 2018-10-01 15:16:27 |\n", + "| 10 | 1 | 1 | 1 | 4 | 10.9634 | 13.8687 | 4 | 2018-10-01 15:16:28 |\n", + "| 11 | 2 | 1 | ab | 6 | 10.9634 | 13.8687 | 4 | 2018-10-01 15:16:28 |\n", + "| 12 | 3 | 1 | ['c', 'd'] | [ 30 300] | 10.9634 | 13.8687 | 4 | 2018-10-01 15:16:28 |\n", + "| 13 | 1 | 1 | 1 | 4 | 11.5544 | 13.9381 | 5 | 2018-10-01 15:16:29 |\n", + "| 14 | 2 | 1 | ab | 6 | 11.5544 | 13.9381 | 5 | 2018-10-01 15:16:29 |\n", + "| 15 | 3 | 1 | ['c', 'd'] | [ 30 300] | 11.5544 | 13.9381 | 5 | 2018-10-01 15:16:29 |\n", + "| 16 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n", + "| 17 | 1 | 2 | 1 | 4 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 18 | 2 | 2 | ab | 6 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 19 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 20 | 1 | 2 | 1 | 4 | 9.98087 | 9.45464 | 2 | 2018-10-01 15:16:26 |\n", + "| 21 | 2 | 2 | ab | 6 | 9.98087 | 9.45464 | 2 | 2018-10-01 15:16:26 |\n", + "| 22 | 3 | 2 | ['c', 'd'] | [ 30 300] | 9.98087 | 9.45464 | 2 | 2018-10-01 15:16:26 |\n", + "| 23 | 1 | 2 | 1 | 4 | 11.1536 | 7.9925 | 3 | 2018-10-01 15:16:27 |\n", + "| 24 | 2 | 2 | ab | 6 | 11.1536 | 7.9925 | 3 | 2018-10-01 15:16:27 |\n", + "| 25 | 3 | 2 | ['c', 'd'] | [ 30 300] | 11.1536 | 7.9925 | 3 | 2018-10-01 15:16:27 |\n", + "| 26 | 1 | 2 | 1 | 4 | 10.3195 | 8.77766 | 4 | 2018-10-01 15:16:28 |\n", + "| 27 | 2 | 2 | ab | 6 | 10.3195 | 8.77766 | 4 | 2018-10-01 15:16:28 |\n", + "| 28 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10.3195 | 8.77766 | 4 | 2018-10-01 15:16:28 |\n", + "| 29 | 1 | 2 | 1 | 4 | 10.3288 | 7.81118 | 5 | 2018-10-01 15:16:29 |\n", + "| 30 | 2 | 2 | ab | 6 | 10.3288 | 7.81118 | 5 | 2018-10-01 15:16:29 |\n", + "| 31 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10.3288 | 7.81118 | 5 | 2018-10-01 15:16:29 |\n", + "+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n", + "+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n", + "| | mech_step | run | s1 | s2 | s3 | s4 | time_step | timestamp |\n", + "|----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------|\n", + "| 0 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n", + "| 1 | 1 | 1 | 1 | 0 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 2 | 2 | 1 | ab | 0 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 3 | 3 | 1 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 4 | 1 | 1 | 1 | [ 30 300] | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n", + "| 5 | 2 | 1 | ab | [ 30 300] | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n", + "| 6 | 3 | 1 | ['c', 'd'] | [ 30 300] | 9.94373 | 10.4365 | 2 | 2018-10-01 15:16:26 |\n", + "| 7 | 1 | 1 | 1 | [ 30 300] | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n", + "| 8 | 2 | 1 | ab | [ 30 300] | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n", + "| 9 | 3 | 1 | ['c', 'd'] | [ 30 300] | 7.81956 | 10.5372 | 3 | 2018-10-01 15:16:27 |\n", + "| 10 | 1 | 1 | 1 | [ 30 300] | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n", + "| 11 | 2 | 1 | ab | [ 30 300] | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n", + "| 12 | 3 | 1 | ['c', 'd'] | [ 30 300] | 9.10218 | 8.57362 | 4 | 2018-10-01 15:16:28 |\n", + "| 13 | 1 | 1 | 1 | [ 30 300] | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n", + "| 14 | 2 | 1 | ab | [ 30 300] | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n", + "| 15 | 3 | 1 | ['c', 'd'] | [ 30 300] | 7.46976 | 8.33579 | 5 | 2018-10-01 15:16:29 |\n", + "| 16 | 0 | 2 | 0 | 0 | 1 | 1 | 0 | 2018-10-01 15:16:24 |\n", + "| 17 | 1 | 2 | 1 | 0 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 18 | 2 | 2 | ab | 0 | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 19 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10 | 10 | 1 | 2018-10-01 15:16:25 |\n", + "| 20 | 1 | 2 | 1 | [ 30 300] | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n", + "| 21 | 2 | 2 | ab | [ 30 300] | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n", + "| 22 | 3 | 2 | ['c', 'd'] | [ 30 300] | 10.5029 | 9.91726 | 2 | 2018-10-01 15:16:26 |\n", + "| 23 | 1 | 2 | 1 | [ 30 300] | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n", + "| 24 | 2 | 2 | ab | [ 30 300] | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n", + "| 25 | 3 | 2 | ['c', 'd'] | [ 30 300] | 9.19497 | 9.29545 | 3 | 2018-10-01 15:16:27 |\n", + "| 26 | 1 | 2 | 1 | [ 30 300] | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n", + "| 27 | 2 | 2 | ab | [ 30 300] | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n", + "| 28 | 3 | 2 | ['c', 'd'] | [ 30 300] | 8.22219 | 9.25471 | 4 | 2018-10-01 15:16:28 |\n", + "| 29 | 1 | 2 | 1 | [ 30 300] | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n", + "| 30 | 2 | 2 | ab | [ 30 300] | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n", + "| 31 | 3 | 2 | ['c', 'd'] | [ 30 300] | 7.47478 | 8.81306 | 5 | 2018-10-01 15:16:29 |\n", + "+----+-------------+-------+------------+-----------+----------+----------+-------------+---------------------+\n", + "\n" + ] } ], "source": [ - "from engine import run\n", - "run.main()" + "import pandas as pd\n", + "from tabulate import tabulate\n", + "\n", + "from SimCAD.engine import ExecutionMode, ExecutionContext, Executor\n", + "from sandboxUX import config1, config2\n", + "from SimCAD import configs\n", + "\n", + "# ToDo: pass ExecutionContext with execution method as ExecutionContext input\n", + "\n", + "exec_mode = ExecutionMode()\n", + "\n", + "print(\"Simulation Run 1\")\n", + "print()\n", + "single_config = [configs[0]]\n", + "single_proc_ctx = ExecutionContext(exec_mode.single_proc)\n", + "run1 = Executor(single_proc_ctx, single_config)\n", + "run1_raw_result = run1.main()\n", + "result = pd.DataFrame(run1_raw_result)\n", + "print(tabulate(result, headers='keys', tablefmt='psql'))\n", + "print()\n", + "\n", + "print(\"Simulation Run 2: Pairwise Execution\")\n", + "print()\n", + "multi_proc_ctx = ExecutionContext(exec_mode.multi_proc)\n", + "run2 = Executor(multi_proc_ctx, configs)\n", + "run2_raw_results = run2.main()\n", + "for raw_result in run2_raw_results:\n", + " result = pd.DataFrame(raw_result)\n", + " print(tabulate(result, headers='keys', tablefmt='psql'))\n", + "print()" ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {