{ "cells": [ { "cell_type": "code", "execution_count": 65, "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", "# getcontext().prec=None\n", "# getcontext().rounding = ROUND_DOWN" ] }, { "cell_type": "code", "execution_count": 14, "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", " 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(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": 15, "metadata": {}, "outputs": [], "source": [ "\n", "# esceptions:\n", "# point to line giving problems and pass a sentinel" ] }, { "cell_type": "code", "execution_count": 16, "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']\n", "def b2m1(step, sL, s):\n", " return s['s1'] * s['s2']\n", "\n", "def b1m2(step, sL, s):\n", " return s['s1']\n", "def b2m2(step, sL, s):\n", " return s['s1'] / s['s2']\n", "\n", "def b1m3(step, sL, s):\n", " return s['s1'] + seed['z'].randint(1000)\n", "def b2m3(step, sL, s):\n", " ps = retrieve_state(sL, -3)\n", " return ps['s2']\n", "\n", "# UI Internal States per Mechanism\n", "def s1m1(step, sL, s, _input):\n", "# print(s['s1'])\n", " s['s1'] = s['s1'] + _input\n", "def s2m1(step, sL, s, _input):\n", " s['s2'] = s['s2'] + 1 + _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']\n", " \n", "def s1m3(step, sL, s, _input):\n", " s['s1'] = s['s1']\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 x + 1\n", "def env_b(x): \n", " return x + 2\n", " \n", "def what_ever(x): \n", " return x + 1\n", "\n", "# Genesis States \n", "state_dict = {\n", " 's1': Decimal(2.0),\n", " 's2': Decimal(4.0),\n", " 's3': Decimal(0.0),\n", " 's4': Decimal(0.0),\n", " 'timestamp': '2018-10-01 15:16:24'\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(1, env_a),\n", " \"s4\": env_proc(1, pipe | env_b | what_ever)\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": 73, "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", " # Purge Memory accociated with certain objs\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, t_step)\n", " \n", "# print(last_mut_obj)\n", " \n", "# non_numeric = {k: v for k, v in last_mut_obj.items() if type(v) != Decimal}\n", "# last_mut_obj = {k: round_down(v) for k, v in last_mut_obj.items() if type(v) == Decimal}\n", "# last_mut_obj.update(non_numeric)\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", " # should only occur once for genesis state, placed before loop\n", " head, *tail = simulation_list\n", " head[-1]['mech_step'], head[-1]['time_step'] = 0, 0\n", " simulation_list = [head] + tail\n", " return simulation_list" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'s1': Decimal('2'),\n", " 's2': Decimal('4'),\n", " 's3': Decimal('0'),\n", " 's4': Decimal('0'),\n", " 'timestamp': '2018-10-01 15:16:24',\n", " 'mech_step': 0,\n", " 'time_step': 0}" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "states_list[-1]" ] }, { "cell_type": "code", "execution_count": 71, "metadata": { "collapsed": true }, "outputs": [ { "data": { "text/plain": [ "\"[{'s1': Decimal('2'), 's2': Decimal('4'), 's3': Decimal('0'), 's4': Decimal('0'), 'timestamp': '2018-10-01 15:16:24', 'mech_step': 0, 'time_step': 0}, {'s1': Decimal('12'), 's2': Decimal('15'), 's3': Decimal('1.027943375654487123682656602'), 's4': Decimal('2.873162181767157652423350100'), 'timestamp': '2018-10-01 15:16:25', 'mech_step': 1, 'time_step': 1}, {'s1': Decimal('24.8'), 's2': Decimal('15'), 's3': Decimal('1.658405192679980226295085390'), 's4': Decimal('5.350515951995874829597979645'), 'timestamp': '2018-10-01 15:16:25', 'mech_step': 2, 'time_step': 1}, {'s1': Decimal('24.8'), 's2': Decimal('513.8'), 's3': Decimal('2.771923735333028371712141099'), 's4': Decimal('7.030344993582647198055332758'), 'timestamp': '2018-10-01 15:16:25', 'mech_step': 3, 'time_step': 1}, {'s1': Decimal('12791.84'), 's2': Decimal('13281.84'), 's3': Decimal('2.884737635508387705829249992'), 's4': Decimal('6.383750387315317896150130866'), 'timestamp': '2018-10-01 15:16:26', 'mech_step': 1, 'time_step': 2}, {'s1': Decimal('25584.64310752124705613077706'), 's2': Decimal('13281.84'), 's3': Decimal('2.641176859741037975691526862'), 's4': Decimal('7.563409402906505259061057559'), 'timestamp': '2018-10-01 15:16:26', 'mech_step': 2, 'time_step': 2}, {'s1': Decimal('25584.64310752124705613077706'), 's2': Decimal('39578.28310752124705613077706'), 's3': Decimal('2.493318466952763629633252152'), 's4': Decimal('5.891297175440944153224023488'), 'timestamp': '2018-10-01 15:16:26', 'mech_step': 3, 'time_step': 2}, {'s1': Decimal('1012647417.400583119401298502'), 's2': Decimal('1012661412.040583119401298502'), 's3': Decimal('2.343589605293861443271839926'), 's4': Decimal('5.974841965491865064823816188'), 'timestamp': '2018-10-01 15:16:27', 'mech_step': 1, 'time_step': 3}, {'s1': Decimal('2025294835.801152419139051417'), 's2': Decimal('1012661412.040583119401298502'), 's3': Decimal('2.722049618518731799375577601'), 's4': Decimal('6.419153303484813228317291423'), 'timestamp': '2018-10-01 15:16:27', 'mech_step': 2, 'time_step': 3}, {'s1': Decimal('2025294835.801152419139051417'), 's2': Decimal('3037996532.124843059787406050'), 's3': Decimal('2.829557844805450150205458129'), 's4': Decimal('6.506538668695062046307737283'), 'timestamp': '2018-10-01 15:16:27', 'mech_step': 3, 'time_step': 3}, {'s1': Decimal('6152838691744844166.823201459'), 's2': Decimal('6152838692757545864.146892100'), 's3': Decimal('2.488931860190471537369309149'), 's4': Decimal('6.300408321924320755651096195'), 'timestamp': '2018-10-01 15:16:28', 'mech_step': 1, 'time_step': 4}, {'s1': Decimal('12305677383489688334.64640292'), 's2': Decimal('6152838692757545864.146892100'), 's3': Decimal('2.178444472215797343328528750'), 's4': Decimal('6.784326268377325448300165109'), 'timestamp': '2018-10-01 15:16:28', 'mech_step': 2, 'time_step': 4}, {'s1': Decimal('12305677383489688334.64640292'), 's2': Decimal('18458516079285231057.91813808'), 's3': Decimal('2.161551452331358618745550185'), 's4': Decimal('6.035792378762528032341888172'), 'timestamp': '2018-10-01 15:16:28', 'mech_step': 3, 'time_step': 4}, {'s1': Decimal('2.271445438496410226588727850E+38'), 's2': Decimal('2.271445438496410226650256237E+38'), 's3': Decimal('2.158667996440737307324876748'), 's4': Decimal('6.371107803673317814010318446'), 'timestamp': '2018-10-01 15:16:29', 'mech_step': 1, 'time_step': 5}, {'s1': Decimal('4.542890876992820453177455700E+38'), 's2': Decimal('2.271445438496410226650256237E+38'), 's3': Decimal('1.992812515458891464887812476'), 's4': Decimal('7.282620522632285439020785561'), 'timestamp': '2018-10-01 15:16:29', 'mech_step': 2, 'time_step': 5}, {'s1': Decimal('4.542890876992820453177455700E+38'), 's2': Decimal('6.814336315489230680012297098E+38'), 's3': Decimal('2.050849993464547990799409445'), 's4': Decimal('6.524227074744597056029341316'), 'timestamp': '2018-10-01 15:16:29', 'mech_step': 3, 'time_step': 5}, {'s1': Decimal('3.095678628039689600133475180E+77'), 's2': Decimal('3.095678628039689600133475180E+77'), 's3': Decimal('2.010380376097353148038039474'), 's4': Decimal('5.989349144044895224884420424'), 'timestamp': '2018-10-01 15:16:30', 'mech_step': 1, 'time_step': 6}, {'s1': Decimal('6.191357256079379200266950360E+77'), 's2': Decimal('3.095678628039689600133475180E+77'), 's3': Decimal('2.226864095678880891887671486'), 's4': Decimal('6.070768581048944995923972497'), 'timestamp': '2018-10-01 15:16:30', 'mech_step': 2, 'time_step': 6}, {'s1': Decimal('6.191357256079379200266950360E+77'), 's2': Decimal('9.287035884119068800400425540E+77'), 's3': Decimal('2.324269409720218352898828188'), 's4': Decimal('6.671515324796301588344886525'), 'timestamp': '2018-10-01 15:16:30', 'mech_step': 3, 'time_step': 6}, {'s1': Decimal('5.749935700861016926665423233E+155'), 's2': Decimal('5.749935700861016926665423233E+155'), 's3': Decimal('2.302607714744926584899159503'), 's4': Decimal('7.564930163192297989174091445'), 'timestamp': '2018-10-01 15:16:31', 'mech_step': 1, 'time_step': 7}, {'s1': Decimal('1.149987140172203385333084647E+156'), 's2': Decimal('5.749935700861016926665423233E+155'), 's3': Decimal('2.333838309242175687275651869'), 's4': Decimal('8.079819700247225677794342322'), 'timestamp': '2018-10-01 15:16:31', 'mech_step': 2, 'time_step': 7}, {'s1': Decimal('1.149987140172203385333084647E+156'), 's2': Decimal('1.724980710258305077999626970E+156'), 's3': Decimal('2.127828342872591238967325177'), 's4': Decimal('7.538873530077748135396698368'), 'timestamp': '2018-10-01 15:16:31', 'mech_step': 3, 'time_step': 7}, {'s1': Decimal('1.983705633842164435837016890E+312'), 's2': Decimal('1.983705633842164435837016890E+312'), 's3': Decimal('2.316086720133955499001671373'), 's4': Decimal('6.698731880418827259665498103'), 'timestamp': '2018-10-01 15:16:32', 'mech_step': 1, 'time_step': 8}, {'s1': Decimal('3.967411267684328871674033780E+312'), 's2': Decimal('1.983705633842164435837016890E+312'), 's3': Decimal('2.404840197025546934576512657'), 's4': Decimal('6.861496713777041844809717113'), 'timestamp': '2018-10-01 15:16:32', 'mech_step': 2, 'time_step': 8}, {'s1': Decimal('3.967411267684328871674033780E+312'), 's2': Decimal('5.951116901526493307511050670E+312'), 's3': Decimal('2.304559767911563562114836868'), 's4': Decimal('7.134761053609609291468324912'), 'timestamp': '2018-10-01 15:16:32', 'mech_step': 3, 'time_step': 8}, {'s1': Decimal('2.361052825042286016164133532E+625'), 's2': Decimal('2.361052825042286016164133532E+625'), 's3': Decimal('2.331706686848056480258922690'), 's4': Decimal('6.349543276872486350505972604'), 'timestamp': '2018-10-01 15:16:33', 'mech_step': 1, 'time_step': 9}, {'s1': Decimal('4.722105650084572032328267064E+625'), 's2': Decimal('2.361052825042286016164133532E+625'), 's3': Decimal('2.206567414513102300934412097'), 's4': Decimal('6.387507504315002156007687646'), 'timestamp': '2018-10-01 15:16:33', 'mech_step': 2, 'time_step': 9}, {'s1': Decimal('4.722105650084572032328267064E+625'), 's2': Decimal('7.083158475126858048492400596E+625'), 's3': Decimal('2.755381458293744817475387505'), 's4': Decimal('6.599724434632028086026631189'), 'timestamp': '2018-10-01 15:16:33', 'mech_step': 3, 'time_step': 9}, {'s1': Decimal('3.344742265584095796507860632E+1251'), 's2': Decimal('3.344742265584095796507860632E+1251'), 's3': Decimal('2.631014270278374984244193109'), 's4': Decimal('7.289437871820951073267599940'), 'timestamp': '2018-10-01 15:16:34', 'mech_step': 1, 'time_step': 10}, {'s1': Decimal('6.689484531168191593015721264E+1251'), 's2': Decimal('3.344742265584095796507860632E+1251'), 's3': Decimal('2.767520795662379664467196631'), 's4': Decimal('6.567373343213126668766057155'), 'timestamp': '2018-10-01 15:16:34', 'mech_step': 2, 'time_step': 10}, {'s1': Decimal('6.689484531168191593015721264E+1251'), 's2': Decimal('1.003422679675228738952358190E+1252'), 's3': Decimal('2.868382538980392112200644477'), 's4': Decimal('6.933152742813279229430635728'), 'timestamp': '2018-10-01 15:16:34', 'mech_step': 3, 'time_step': 10}]\"" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "flatten(pipeline(states_list, configs, env_processes, range(10)))" ] }, { "cell_type": "code", "execution_count": 75, "metadata": { "collapsed": true }, "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
00240002018-10-01 15:16:24
1112150.91347900357833378137684121612.50224537938149438343060637612018-10-01 15:16:25
2224.8152.2486857305845532188692197125.51287007746884128939653377412018-10-01 15:16:25
3324.8548.83.4312752329536155393127174849.15222284342932628210604571712018-10-01 15:16:25
4113659.8414184.843.3228146720543445445725350397.70881538225254456160390488022018-10-01 15:16:26
5227320.6429886554941754718417714184.842.8976416333156811794413001447.87144037939911266527043420522018-10-01 15:16:26
6327320.6429886554941754718417743033.282988655494175471841773.1099373514674137757517211948.63077690792905289331599721422018-10-01 15:16:26
711175751602.4488157878316257271175767316.0888157878316257273.1762283649007351571365985979.47687555402766473298349093332018-10-01 15:16:27
822351503205.8976182110801532681175767316.0888157878316257273.6693420853932657385847473939.07896932290232850017764210932018-10-01 15:16:27
932351503205.8976182110801532683527313580.2694226544059544673.34975996098706446435798834811.1714439114040052636610562632018-10-01 15:16:27
1018294489196912759452.9706154948294489198088569828.3424199373.29162106267578062636028319811.7915857380119372108952702142018-10-01 15:16:28
11216588978393825518906.941230998294489198088569828.3424199373.19026040135236422790237030910.8352100528422372882380039242018-10-01 15:16:28
12316588978393825518906.9412309924883467595441402812.553073583.12108558165304708498273819911.9017186296980778069815841242018-10-01 15:16:28
1314.127913063042348695585266519E+384.127913063042348695668211411E+383.45118238249576888355648036310.5656460156203145282810118152018-10-01 15:16:29
1428.255826126084697391170533038E+384.127913063042348695668211411E+383.74189940679731861037715655111.5115560290072500272497913152018-10-01 15:16:29
1538.255826126084697391170533038E+381.238373918912704608708757912E+393.50226109299384254562003403510.0587350995908767698616463452018-10-01 15:16:29
1611.022379975362139926212390600E+781.022379975362139926212390600E+783.46992706653546389898112219310.8539209327031011426828305962018-10-01 15:16:30
1722.044759950724279852424781200E+781.022379975362139926212390600E+783.38983663612009305381756851710.2205276041921032039322294162018-10-01 15:16:30
1832.044759950724279852424781200E+783.067139926086419778637171800E+783.69123457683711874967611059811.3777857442305618148252315062018-10-01 15:16:30
1916.271564884128939055277180913E+1566.271564884128939055277180913E+1563.62617801935823680686355156612.2205126370512860614055141272018-10-01 15:16:31
2021.254312976825787811055436183E+1576.271564884128939055277180913E+1563.22078515043333255599060413412.7670236400115368185243901172018-10-01 15:16:31
2131.254312976825787811055436183E+1571.881469465238681716583154274E+1573.10956878027570033382925798112.8418798070583525716279923472018-10-01 15:16:31
2212.359951565750353965511297842E+3142.359951565750353965511297842E+3143.09471215038725924287956726114.2378130192524730069674725482018-10-01 15:16:32
2324.719903131500707931022595684E+3142.359951565750353965511297842E+3143.37856548607312751538170047311.6702485226548511088284011782018-10-01 15:16:32
2434.719903131500707931022595684E+3147.079854697251061896533893526E+3143.80961195940413592076084272412.1750501842605951725718621582018-10-01 15:16:32
2513.341622835612528353592630685E+6293.341622835612528353592630685E+6294.30134446582968607869876923112.6784065728960961200549137892018-10-01 15:16:33
2626.683245671225056707185261370E+6293.341622835612528353592630685E+6294.45796012493645100811682422813.3911230620646779720618895792018-10-01 15:16:33
2736.683245671225056707185261370E+6291.002486850683758506077789206E+6304.22706706849519725133027999614.4975362454358034942992364392018-10-01 15:16:33
2816.699865905292268815365221375E+12596.699865905292268815365221375E+12594.47278066076339182371743610614.66684234187518294415503523102018-10-01 15:16:34
2921.339973181058453763073044275E+12606.699865905292268815365221375E+12594.38738429071790456710398785715.84678912512812579758546608102018-10-01 15:16:34
3031.339973181058453763073044275E+12602.009959771587680644609566412E+12604.11306154440989092204479520216.08824426908686380482178405102018-10-01 15:16:34
\n", "
" ], "text/plain": [ " mech_step s1 \\\n", "0 0 2 \n", "1 1 12 \n", "2 2 24.8 \n", "3 3 24.8 \n", "4 1 13659.84 \n", "5 2 27320.64298865549417547184177 \n", "6 3 27320.64298865549417547184177 \n", "7 1 1175751602.448815787831625727 \n", "8 2 2351503205.897618211080153268 \n", "9 3 2351503205.897618211080153268 \n", "10 1 8294489196912759452.970615494 \n", "11 2 16588978393825518906.94123099 \n", "12 3 16588978393825518906.94123099 \n", "13 1 4.127913063042348695585266519E+38 \n", "14 2 8.255826126084697391170533038E+38 \n", "15 3 8.255826126084697391170533038E+38 \n", "16 1 1.022379975362139926212390600E+78 \n", "17 2 2.044759950724279852424781200E+78 \n", "18 3 2.044759950724279852424781200E+78 \n", "19 1 6.271564884128939055277180913E+156 \n", "20 2 1.254312976825787811055436183E+157 \n", "21 3 1.254312976825787811055436183E+157 \n", "22 1 2.359951565750353965511297842E+314 \n", "23 2 4.719903131500707931022595684E+314 \n", "24 3 4.719903131500707931022595684E+314 \n", "25 1 3.341622835612528353592630685E+629 \n", "26 2 6.683245671225056707185261370E+629 \n", "27 3 6.683245671225056707185261370E+629 \n", "28 1 6.699865905292268815365221375E+1259 \n", "29 2 1.339973181058453763073044275E+1260 \n", "30 3 1.339973181058453763073044275E+1260 \n", "\n", " s2 s3 \\\n", "0 4 0 \n", "1 15 0.9134790035783337813768412161 \n", "2 15 2.248685730584553218869219712 \n", "3 548.8 3.431275232953615539312717484 \n", "4 14184.84 3.322814672054344544572535039 \n", "5 14184.84 2.897641633315681179441300144 \n", "6 43033.28298865549417547184177 3.109937351467413775751721194 \n", "7 1175767316.088815787831625727 3.176228364900735157136598597 \n", "8 1175767316.088815787831625727 3.669342085393265738584747393 \n", "9 3527313580.269422654405954467 3.349759960987064464357988348 \n", "10 8294489198088569828.342419937 3.291621062675780626360283198 \n", "11 8294489198088569828.342419937 3.190260401352364227902370309 \n", "12 24883467595441402812.55307358 3.121085581653047084982738199 \n", "13 4.127913063042348695668211411E+38 3.451182382495768883556480363 \n", "14 4.127913063042348695668211411E+38 3.741899406797318610377156551 \n", "15 1.238373918912704608708757912E+39 3.502261092993842545620034035 \n", "16 1.022379975362139926212390600E+78 3.469927066535463898981122193 \n", "17 1.022379975362139926212390600E+78 3.389836636120093053817568517 \n", "18 3.067139926086419778637171800E+78 3.691234576837118749676110598 \n", "19 6.271564884128939055277180913E+156 3.626178019358236806863551566 \n", "20 6.271564884128939055277180913E+156 3.220785150433332555990604134 \n", "21 1.881469465238681716583154274E+157 3.109568780275700333829257981 \n", "22 2.359951565750353965511297842E+314 3.094712150387259242879567261 \n", "23 2.359951565750353965511297842E+314 3.378565486073127515381700473 \n", "24 7.079854697251061896533893526E+314 3.809611959404135920760842724 \n", "25 3.341622835612528353592630685E+629 4.301344465829686078698769231 \n", "26 3.341622835612528353592630685E+629 4.457960124936451008116824228 \n", "27 1.002486850683758506077789206E+630 4.227067068495197251330279996 \n", "28 6.699865905292268815365221375E+1259 4.472780660763391823717436106 \n", "29 6.699865905292268815365221375E+1259 4.387384290717904567103987857 \n", "30 2.009959771587680644609566412E+1260 4.113061544409890922044795202 \n", "\n", " s4 time_step timestamp \n", "0 0 0 2018-10-01 15:16:24 \n", "1 2.502245379381494383430606376 1 2018-10-01 15:16:25 \n", "2 5.512870077468841289396533774 1 2018-10-01 15:16:25 \n", "3 9.152222843429326282106045717 1 2018-10-01 15:16:25 \n", "4 7.708815382252544561603904880 2 2018-10-01 15:16:26 \n", "5 7.871440379399112665270434205 2 2018-10-01 15:16:26 \n", "6 8.630776907929052893315997214 2 2018-10-01 15:16:26 \n", "7 9.476875554027664732983490933 3 2018-10-01 15:16:27 \n", "8 9.078969322902328500177642109 3 2018-10-01 15:16:27 \n", "9 11.17144391140400526366105626 3 2018-10-01 15:16:27 \n", "10 11.79158573801193721089527021 4 2018-10-01 15:16:28 \n", "11 10.83521005284223728823800392 4 2018-10-01 15:16:28 \n", "12 11.90171862969807780698158412 4 2018-10-01 15:16:28 \n", "13 10.56564601562031452828101181 5 2018-10-01 15:16:29 \n", "14 11.51155602900725002724979131 5 2018-10-01 15:16:29 \n", "15 10.05873509959087676986164634 5 2018-10-01 15:16:29 \n", "16 10.85392093270310114268283059 6 2018-10-01 15:16:30 \n", "17 10.22052760419210320393222941 6 2018-10-01 15:16:30 \n", "18 11.37778574423056181482523150 6 2018-10-01 15:16:30 \n", "19 12.22051263705128606140551412 7 2018-10-01 15:16:31 \n", "20 12.76702364001153681852439011 7 2018-10-01 15:16:31 \n", "21 12.84187980705835257162799234 7 2018-10-01 15:16:31 \n", "22 14.23781301925247300696747254 8 2018-10-01 15:16:32 \n", "23 11.67024852265485110882840117 8 2018-10-01 15:16:32 \n", "24 12.17505018426059517257186215 8 2018-10-01 15:16:32 \n", "25 12.67840657289609612005491378 9 2018-10-01 15:16:33 \n", "26 13.39112306206467797206188957 9 2018-10-01 15:16:33 \n", "27 14.49753624543580349429923643 9 2018-10-01 15:16:33 \n", "28 14.66684234187518294415503523 10 2018-10-01 15:16:34 \n", "29 15.84678912512812579758546608 10 2018-10-01 15:16:34 \n", "30 16.08824426908686380482178405 10 2018-10-01 15:16:34 " ] }, "execution_count": 75, "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": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "for x in list(range(5)):\n", " print(x)" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "def simulation(states_list, configs, env_processes, time_seq, runs):\n", " pipeline_run = []\n", " for run in range(runs):\n", " if run == 0:\n", " pipeline_run += pipeline(states_list, configs, env_processes, time_seq)\n", "# pipeline_run += [run]\n", " else:\n", " pipeline_run += pipeline(pipeline_run[-1], configs, env_processes, time_seq)\n", "# pipeline_run += [run]\n", " return pipeline_run" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1]" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(range(2))" ] }, { "cell_type": "code", "execution_count": 77, "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", "
mech_steps1s2s3s4time_steptimestamp
00240002018-10-01 15:16:24
1112150.96133742191122872888797701313.05262791623336182667003413412018-10-01 15:16:25
2224.8151.7878418867054752478439788316.14210807562603620769166584212018-10-01 15:16:25
3324.8463.82.6603514160051104294423873439.30572704359699394374669537612018-10-01 15:16:25
4111551.8411991.842.4646451853433646554407158469.33777728437343571731501191922018-10-01 15:16:26
5223104.6433083830337963148274211991.842.30463914826193806262431798010.2960246753892924374554966522018-10-01 15:16:26
6023104.6433083830337963148274236429.283308383033796314827421.74501435017167714302639392610.7983192271393526493051916502018-10-01 15:16:26
7111551.8411991.842.4646451853433646554407158469.33777728437343571731501191922018-10-01 15:16:26
8223104.6433083830337963148274211991.842.30463914826193806262431798010.2960246753892924374554966522018-10-01 15:16:26
9023104.6433083830337963148274236429.283308383033796314827421.74501435017167714302639392610.7983192271393526493051916502018-10-01 15:16:26
101841731806.1068385748529941713841745131.74683857485299417132.67443317714085638901916999613.0006236569486193745271504912018-10-01 15:16:27
1121683463613.213661318738279214841745131.74683857485299417133.62410141757133180976719867316.2064237531334924799690398512018-10-01 15:16:27
1231683463613.2136613187382792142525245934.2438082766250697005.62404596810520747959405439719.0605228567092632757599263112018-10-01 15:16:27
1314251159648082116507.1228759154251159648923898829.1530228735.99385581199740180262345385019.9848285645724548773428862922018-10-01 15:16:28
1428502319296164233015.2457518304251159648923898829.1530228735.89779674502673599164725994120.3451883001598149011174066822018-10-01 15:16:28
1538502319296164233015.24575183012753478947613377799.642582985.92907068676888572790928438921.1886549224812131716461903422018-10-01 15:16:28
\n", "
" ], "text/plain": [ " mech_step s1 s2 \\\n", "0 0 2 4 \n", "1 1 12 15 \n", "2 2 24.8 15 \n", "3 3 24.8 463.8 \n", "4 1 11551.84 11991.84 \n", "5 2 23104.64330838303379631482742 11991.84 \n", "6 0 23104.64330838303379631482742 36429.28330838303379631482742 \n", "7 1 11551.84 11991.84 \n", "8 2 23104.64330838303379631482742 11991.84 \n", "9 0 23104.64330838303379631482742 36429.28330838303379631482742 \n", "10 1 841731806.1068385748529941713 841745131.7468385748529941713 \n", "11 2 1683463613.213661318738279214 841745131.7468385748529941713 \n", "12 3 1683463613.213661318738279214 2525245934.243808276625069700 \n", "13 1 4251159648082116507.122875915 4251159648923898829.153022873 \n", "14 2 8502319296164233015.245751830 4251159648923898829.153022873 \n", "15 3 8502319296164233015.245751830 12753478947613377799.64258298 \n", "\n", " s3 s4 time_step \\\n", "0 0 0 0 \n", "1 0.9613374219112287288879770131 3.052627916233361826670034134 1 \n", "2 1.787841886705475247843978831 6.142108075626036207691665842 1 \n", "3 2.660351416005110429442387343 9.305727043596993943746695376 1 \n", "4 2.464645185343364655440715846 9.337777284373435717315011919 2 \n", "5 2.304639148261938062624317980 10.29602467538929243745549665 2 \n", "6 1.745014350171677143026393926 10.79831922713935264930519165 0 \n", "7 2.464645185343364655440715846 9.337777284373435717315011919 2 \n", "8 2.304639148261938062624317980 10.29602467538929243745549665 2 \n", "9 1.745014350171677143026393926 10.79831922713935264930519165 0 \n", "10 2.674433177140856389019169996 13.00062365694861937452715049 1 \n", "11 3.624101417571331809767198673 16.20642375313349247996903985 1 \n", "12 5.624045968105207479594054397 19.06052285670926327575992631 1 \n", "13 5.993855811997401802623453850 19.98482856457245487734288629 2 \n", "14 5.897796745026735991647259941 20.34518830015981490111740668 2 \n", "15 5.929070686768885727909284389 21.18865492248121317164619034 2 \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:26 \n", "8 2018-10-01 15:16:26 \n", "9 2018-10-01 15:16:26 \n", "10 2018-10-01 15:16:27 \n", "11 2018-10-01 15:16:27 \n", "12 2018-10-01 15:16:27 \n", "13 2018-10-01 15:16:28 \n", "14 2018-10-01 15:16:28 \n", "15 2018-10-01 15:16:28 " ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.DataFrame(flatten(simulation(states_list, configs, env_processes, range(2), 2)))" ] }, { "cell_type": "code", "execution_count": 7, "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 }