{ "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": 85, "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 last_index(l):\n", " return len(l)-1\n", "\n", "def retrieve_state(l, offset):\n", " return l[last_index(l) + offset + 1]\n", "# Stochastic Process\n", "# Input RNG Seed\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", " print('trigered: '+step)\n", " return update_f\n", " else:\n", " print('NOT trigered: '+step)\n", " return lambda x: x\n", " return partial(env_step_trigger, trigger_step, update_f)\n", "\n", "def 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", " dt = datetime.strptime(dt_str, fromat_str)\n", " t = dt + timedelta(days=days, minutes=minutes, seconds=seconds)\n", " return t.strftime(fromat_str)\n", " else: \n", " return dt_str\n", "\n", "def round_down(x, fp=TWOPLACES):\n", " return x.quantize(TWOPLACES, rounding=ROUND_DOWN)\n", " \n", "# def round_down(f, fp=TWOPLACES):\n", "# return (f).quantize(fp, ROUND_DOWN)" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [], "source": [ "\n", "# esceptions:\n", "# point to line giving problems and pass a sentinel" ] }, { "cell_type": "code", "execution_count": 99, "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'] = time_step(s, s['timestamp'], seconds=1)\n", "\n", "\n", "# add env process f(s) read from time es\n", "# funcs execute in order\n", "def env_a(x): \n", " return -1\n", "def env_b(x): \n", " return -1\n", " \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", "# simulation = {\n", "# \"s3\": es3p1\n", "# }\n", "\n", "exogenous_states = {\n", " \"s3\": es3p1,\n", " \"s4\": es4p2,\n", " \"timestamp\": es5p2\n", "}\n", "\n", "# Update time at the end of each pipeline (once per 'block')\n", "# Enable the acceptance of user defined time\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": 100, "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", " # Truncate reffs\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", " # * force eval of _input withing state functions\n", " _input = getBehaviorInput(m_step, sL, last_in_obj, behavior_funcs)\n", "\n", " apply_env_proc(env_processes, last_mut_obj, last_mut_obj['timestamp'])\n", "# apply_env_proc(env_processes, last_mut_obj, t_step)\n", "\n", " for f in state_funcs:\n", " f(m_step, sL, last_mut_obj, _input)\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": 101, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NOT trigered: 2018-10-01 15:16:24\n", "NOT trigered: 2018-10-01 15:16:24\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:29\n", "NOT trigered: 2018-10-01 15:16:29\n", "NOT trigered: 2018-10-01 15:16:29\n", "NOT trigered: 2018-10-01 15:16:29\n", "NOT trigered: 2018-10-01 15:16:29\n", "NOT trigered: 2018-10-01 15:16:29\n", "NOT trigered: 2018-10-01 15:16:30\n", "NOT trigered: 2018-10-01 15:16:30\n", "NOT trigered: 2018-10-01 15:16:30\n", "NOT trigered: 2018-10-01 15:16:30\n", "NOT trigered: 2018-10-01 15:16:30\n", "NOT trigered: 2018-10-01 15:16:30\n", "NOT trigered: 2018-10-01 15:16:31\n", "NOT trigered: 2018-10-01 15:16:31\n", "NOT trigered: 2018-10-01 15:16:31\n", "NOT trigered: 2018-10-01 15:16:31\n", "NOT trigered: 2018-10-01 15:16:31\n", "NOT trigered: 2018-10-01 15:16:31\n", "NOT trigered: 2018-10-01 15:16:32\n", "NOT trigered: 2018-10-01 15:16:32\n", "NOT trigered: 2018-10-01 15:16:32\n", "NOT trigered: 2018-10-01 15:16:32\n", "NOT trigered: 2018-10-01 15:16:32\n", "NOT trigered: 2018-10-01 15:16:32\n", "NOT trigered: 2018-10-01 15:16:33\n", "NOT trigered: 2018-10-01 15:16:33\n", "NOT trigered: 2018-10-01 15:16:33\n", "NOT trigered: 2018-10-01 15:16:33\n", "NOT trigered: 2018-10-01 15:16:33\n", "NOT trigered: 2018-10-01 15:16:33\n", "NOT trigered: 2018-10-01 15:16:34\n", "NOT trigered: 2018-10-01 15:16:34\n", "NOT trigered: 2018-10-01 15:16:34\n", "NOT trigered: 2018-10-01 15:16:34\n", "NOT trigered: 2018-10-01 15:16:24\n", "NOT trigered: 2018-10-01 15:16:24\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "trigered: 2018-10-01 15:16:25\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:26\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:27\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:28\n", "NOT trigered: 2018-10-01 15:16:28\n" ] } ], "source": [ "states_list = [state_dict]\n", "configs = generate_config(mechanisms, exogenous_states)\n", "p = pipeline(states_list, configs, env_processes, range(10))\n", "s = simulation(states_list, configs, env_processes, range(2), 2)\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": 102, "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
11220.95832421525945288287573475831.17886284734303181664927251412018-10-01 15:16:25
2288-0.9943733172773669970467835810-1.04365098505119902050353175612018-10-01 15:16:25
332626-0.7863803904331545524541979830-1.00964974680720076527506989812018-10-01 15:16:25
418080-1.164027080840498884484190967-0.813650729663550897896584501722018-10-01 15:16:26
52242242-0.9552663219495139965448022608-0.791081018325960723136130761222018-10-01 15:16:26
63728728-0.8748570309494044673003324683-0.763016708867921902221703917922018-10-01 15:16:26
7121862186-0.9188519653028559191494015290-0.756703395579161623013977053832018-10-01 15:16:27
8265606560-0.8044284247281271626156064005-0.709258041460857800953423230132018-10-01 15:16:27
931968219682-0.7193237410424213328031717259-0.706150202590030988627848986332018-10-01 15:16:27
1015904859048-0.6539366652218983625162031954-0.672451441708233124603276746342018-10-01 15:16:28
112177146177146-0.6899982671132800609186798069-0.584100416947396334409009799542018-10-01 15:16:28
123531440531440-0.8481602227838296888984432921-0.635771247076476895437842506142018-10-01 15:16:28
13115943221594322-0.8516834288658128498292162290-0.691802914153004980198101033552018-10-01 15:16:29
14247829684782968-0.7564715712347508471660595074-0.810071676892264085021759675452018-10-01 15:16:29
1531434890614348906-0.7972498007104424508069565774-0.814124760534187816310906001952018-10-01 15:16:29
1614304672043046720-0.7497209805242121767590917327-0.781178970208633325279206085362018-10-01 15:16:30
172129140162129140162-0.7482867270632369112542703363-0.738576597981187434032544671362018-10-01 15:16:30
183387420488387420488-0.8362105087467554066801144981-0.624357402521352659428649852262018-10-01 15:16:30
19111622614661162261466-0.7736727540481614067105454386-0.685692240478851709866298271572018-10-01 15:16:31
20234867844003486784400-0.7743710131258121981198043907-0.610192887457863931483662909072018-10-01 15:16:31
2131046035320210460353202-0.7063728832335825898433752401-0.537882191248428659184776764772018-10-01 15:16:31
2213138105960831381059608-0.6953227976364985577364199016-0.526820649395287135022522771082018-10-01 15:16:32
2329414317882694143178826-0.7131627260841388238904800896-0.605114013547100472795963119882018-10-01 15:16:32
243282429536480282429536480-0.6426466898925962665114815185-0.619438046600456999772391538582018-10-01 15:16:32
251847288609442847288609442-0.6208724083994397579976835846-0.556020899878994276380031091392018-10-01 15:16:33
26225418658283282541865828328-0.6062083935933455693844456101-0.516376987805603698709650797592018-10-01 15:16:33
27376255974849867625597484986-0.5675532115148602461045555170-0.548663199032381580073423225792018-10-01 15:16:33
2812287679245496022876792454960-0.5001498947976128312700433357-0.5398564214990231691461820341102018-10-01 15:16:34
2926863037736488268630377364882-0.4290677301255414288053960084-0.4983502974188522986087216116102018-10-01 15:16:34
303205891132094648205891132094648-0.4224817466061129854881621614-0.4868867095325838908165051117102018-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 \\\n", "0 1 1 \n", "1 0.9583242152594528828757347583 1.178862847343031816649272514 \n", "2 -0.9943733172773669970467835810 -1.043650985051199020503531756 \n", "3 -0.7863803904331545524541979830 -1.009649746807200765275069898 \n", "4 -1.164027080840498884484190967 -0.8136507296635508978965845017 \n", "5 -0.9552663219495139965448022608 -0.7910810183259607231361307612 \n", "6 -0.8748570309494044673003324683 -0.7630167088679219022217039179 \n", "7 -0.9188519653028559191494015290 -0.7567033955791616230139770538 \n", "8 -0.8044284247281271626156064005 -0.7092580414608578009534232301 \n", "9 -0.7193237410424213328031717259 -0.7061502025900309886278489863 \n", "10 -0.6539366652218983625162031954 -0.6724514417082331246032767463 \n", "11 -0.6899982671132800609186798069 -0.5841004169473963344090097995 \n", "12 -0.8481602227838296888984432921 -0.6357712470764768954378425061 \n", "13 -0.8516834288658128498292162290 -0.6918029141530049801981010335 \n", "14 -0.7564715712347508471660595074 -0.8100716768922640850217596754 \n", "15 -0.7972498007104424508069565774 -0.8141247605341878163109060019 \n", "16 -0.7497209805242121767590917327 -0.7811789702086333252792060853 \n", "17 -0.7482867270632369112542703363 -0.7385765979811874340325446713 \n", "18 -0.8362105087467554066801144981 -0.6243574025213526594286498522 \n", "19 -0.7736727540481614067105454386 -0.6856922404788517098662982715 \n", "20 -0.7743710131258121981198043907 -0.6101928874578639314836629090 \n", "21 -0.7063728832335825898433752401 -0.5378821912484286591847767647 \n", "22 -0.6953227976364985577364199016 -0.5268206493952871350225227710 \n", "23 -0.7131627260841388238904800896 -0.6051140135471004727959631198 \n", "24 -0.6426466898925962665114815185 -0.6194380466004569997723915385 \n", "25 -0.6208724083994397579976835846 -0.5560208998789942763800310913 \n", "26 -0.6062083935933455693844456101 -0.5163769878056036987096507975 \n", "27 -0.5675532115148602461045555170 -0.5486631990323815800734232257 \n", "28 -0.5001498947976128312700433357 -0.5398564214990231691461820341 \n", "29 -0.4290677301255414288053960084 -0.4983502974188522986087216116 \n", "30 -0.4224817466061129854881621614 -0.4868867095325838908165051117 \n", "\n", " time_step timestamp \n", "0 0 2018-10-01 15:16:24 \n", "1 1 2018-10-01 15:16:25 \n", "2 1 2018-10-01 15:16:25 \n", "3 1 2018-10-01 15:16:25 \n", "4 2 2018-10-01 15:16:26 \n", "5 2 2018-10-01 15:16:26 \n", "6 2 2018-10-01 15:16:26 \n", "7 3 2018-10-01 15:16:27 \n", "8 3 2018-10-01 15:16:27 \n", "9 3 2018-10-01 15:16:27 \n", "10 4 2018-10-01 15:16:28 \n", "11 4 2018-10-01 15:16:28 \n", "12 4 2018-10-01 15:16:28 \n", "13 5 2018-10-01 15:16:29 \n", "14 5 2018-10-01 15:16:29 \n", "15 5 2018-10-01 15:16:29 \n", "16 6 2018-10-01 15:16:30 \n", "17 6 2018-10-01 15:16:30 \n", "18 6 2018-10-01 15:16:30 \n", "19 7 2018-10-01 15:16:31 \n", "20 7 2018-10-01 15:16:31 \n", "21 7 2018-10-01 15:16:31 \n", "22 8 2018-10-01 15:16:32 \n", "23 8 2018-10-01 15:16:32 \n", "24 8 2018-10-01 15:16:32 \n", "25 9 2018-10-01 15:16:33 \n", "26 9 2018-10-01 15:16:33 \n", "27 9 2018-10-01 15:16:33 \n", "28 10 2018-10-01 15:16:34 \n", "29 10 2018-10-01 15:16:34 \n", "30 10 2018-10-01 15:16:34 " ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.DataFrame(flatten(p))" ] }, { "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
0NaN0011NaN2018-10-01 15:16:24
11.0220.81319093454362367801024902290.96437292405532548666968750691.02018-10-01 15:16:25
22.0880.95396930218324841446774916320.79626912217056149938579538681.02018-10-01 15:16:25
33.026261.0939812789408900453953824790.74875975352783575452054345331.02018-10-01 15:16:25
41.080801.0572588065299107530798413800.70468817526151192436485017402.02018-10-01 15:16:26
52.02422421.1218933488294280710979458070.64310672308116671617171769472.02018-10-01 15:16:26
63.07287281.1272751376250613465209112340.64501763852387293707089991562.02018-10-01 15:16:26
71.0218621861.0338087779216684005916198590.50000104692035120095551772833.02018-10-01 15:16:27
82.0656065601.0428763372920644606416906790.48661292564551380840727014823.02018-10-01 15:16:27
93.019682196821.1472021284638563250410266990.53591574153271162450867699663.02018-10-01 15:16:27
101.059048590481.1034831137403304150647175620.58161852026395546016986493724.02018-10-01 15:16:28
112.01771461771461.0620286272687062695923892690.64607275765267579801267386144.02018-10-01 15:16:28
123.05314405314401.0541196190599114603641466640.71839353840992708199563172324.02018-10-01 15:16:28
131.0159432215943221.0998153176923298634776246540.82525767582287762468296861855.02018-10-01 15:16:29
142.0478296847829681.2404134236196030175305779470.73296905345493975485213283675.02018-10-01 15:16:29
153.014348906143489061.1616869506357986919448950170.79496602463006666867911259465.02018-10-01 15:16:29
161.043046720430467201.2207466787235599332375416730.64703162952018373588162227426.02018-10-01 15:16:30
172.01291401621291401621.2471289684100989741701275250.60802305639426016010867911156.02018-10-01 15:16:30
183.03874204883874204881.0153360336320558857028319210.49161874207296333267696539766.02018-10-01 15:16:30
191.0116226146611622614660.97276132024951014018402627290.54314763822070435315083097857.02018-10-01 15:16:31
202.0348678440034867844000.95988887685446117235210198980.61558929288428622843163541487.02018-10-01 15:16:31
213.010460353202104603532020.95609057356082544831921874550.60343665660948570276051859117.02018-10-01 15:16:31
221.031381059608313810596080.98725945452180115113027905650.71052524305150900577089471678.02018-10-01 15:16:32
232.094143178826941431788260.78582663250818409843403405240.66258415022573203397828801788.02018-10-01 15:16:32
243.02824295364802824295364800.78946151470671844263287926450.67256378500048676324435762918.02018-10-01 15:16:32
251.08472886094428472886094420.73596163593100386081842915470.68285035907543615460239461019.02018-10-01 15:16:33
262.0254186582832825418658283280.63002444583685532065599457320.61018174658204235960234066329.02018-10-01 15:16:33
273.0762559748498676255974849860.66305640261400650635255394770.63690444940009909734406966939.02018-10-01 15:16:33
281.022876792454960228767924549600.71180958567614096632277337630.760398850272102047205369124910.02018-10-01 15:16:34
292.068630377364882686303773648820.66531060543015323930431236780.682463224406065149434214782510.02018-10-01 15:16:34
303.02058911320946482058911320946480.72136011530421961866270530740.743839765964151266725025037710.02018-10-01 15:16:34
\n", "
" ], "text/plain": [ " mech_step s1 s2 \\\n", "0 NaN 0 0 \n", "1 1.0 2 2 \n", "2 2.0 8 8 \n", "3 3.0 26 26 \n", "4 1.0 80 80 \n", "5 2.0 242 242 \n", "6 3.0 728 728 \n", "7 1.0 2186 2186 \n", "8 2.0 6560 6560 \n", "9 3.0 19682 19682 \n", "10 1.0 59048 59048 \n", "11 2.0 177146 177146 \n", "12 3.0 531440 531440 \n", "13 1.0 1594322 1594322 \n", "14 2.0 4782968 4782968 \n", "15 3.0 14348906 14348906 \n", "16 1.0 43046720 43046720 \n", "17 2.0 129140162 129140162 \n", "18 3.0 387420488 387420488 \n", "19 1.0 1162261466 1162261466 \n", "20 2.0 3486784400 3486784400 \n", "21 3.0 10460353202 10460353202 \n", "22 1.0 31381059608 31381059608 \n", "23 2.0 94143178826 94143178826 \n", "24 3.0 282429536480 282429536480 \n", "25 1.0 847288609442 847288609442 \n", "26 2.0 2541865828328 2541865828328 \n", "27 3.0 7625597484986 7625597484986 \n", "28 1.0 22876792454960 22876792454960 \n", "29 2.0 68630377364882 68630377364882 \n", "30 3.0 205891132094648 205891132094648 \n", "\n", " s3 s4 time_step \\\n", "0 1 1 NaN \n", "1 0.8131909345436236780102490229 0.9643729240553254866696875069 1.0 \n", "2 0.9539693021832484144677491632 0.7962691221705614993857953868 1.0 \n", "3 1.093981278940890045395382479 0.7487597535278357545205434533 1.0 \n", "4 1.057258806529910753079841380 0.7046881752615119243648501740 2.0 \n", "5 1.121893348829428071097945807 0.6431067230811667161717176947 2.0 \n", "6 1.127275137625061346520911234 0.6450176385238729370708999156 2.0 \n", "7 1.033808777921668400591619859 0.5000010469203512009555177283 3.0 \n", "8 1.042876337292064460641690679 0.4866129256455138084072701482 3.0 \n", "9 1.147202128463856325041026699 0.5359157415327116245086769966 3.0 \n", "10 1.103483113740330415064717562 0.5816185202639554601698649372 4.0 \n", "11 1.062028627268706269592389269 0.6460727576526757980126738614 4.0 \n", "12 1.054119619059911460364146664 0.7183935384099270819956317232 4.0 \n", "13 1.099815317692329863477624654 0.8252576758228776246829686185 5.0 \n", "14 1.240413423619603017530577947 0.7329690534549397548521328367 5.0 \n", "15 1.161686950635798691944895017 0.7949660246300666686791125946 5.0 \n", "16 1.220746678723559933237541673 0.6470316295201837358816222742 6.0 \n", "17 1.247128968410098974170127525 0.6080230563942601601086791115 6.0 \n", "18 1.015336033632055885702831921 0.4916187420729633326769653976 6.0 \n", "19 0.9727613202495101401840262729 0.5431476382207043531508309785 7.0 \n", "20 0.9598888768544611723521019898 0.6155892928842862284316354148 7.0 \n", "21 0.9560905735608254483192187455 0.6034366566094857027605185911 7.0 \n", "22 0.9872594545218011511302790565 0.7105252430515090057708947167 8.0 \n", "23 0.7858266325081840984340340524 0.6625841502257320339782880178 8.0 \n", "24 0.7894615147067184426328792645 0.6725637850004867632443576291 8.0 \n", "25 0.7359616359310038608184291547 0.6828503590754361546023946101 9.0 \n", "26 0.6300244458368553206559945732 0.6101817465820423596023406632 9.0 \n", "27 0.6630564026140065063525539477 0.6369044494000990973440696693 9.0 \n", "28 0.7118095856761409663227733763 0.7603988502721020472053691249 10.0 \n", "29 0.6653106054301532393043123678 0.6824632244060651494342147825 10.0 \n", "30 0.7213601153042196186627053074 0.7438397659641512667250250377 10.0 \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": [ { "ename": "NameError", "evalue": "name 'non_numeric' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m--------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mstate_dict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m's1'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'3323'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m's2'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'2572'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m's3'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'2.657'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m's4'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'7.914'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'timestamp'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'2018-10-01 15:16:26'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'mech_step'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'time_step'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mstate_dict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquantize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mTWOPLACES\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mROUND_DOWN\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mstate_dict\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mstate_dict\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnon_numeric\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mstate_dict\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;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 }