|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "0", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "## Simple Simulation\n", |
| 9 | + "___\n", |
| 10 | + "The most basic function of the package. Generate 5 years worth of investment data against 4 channels (using example configuration)" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": null, |
| 16 | + "id": "1", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "from pysimmmulator import Simulate, load_config" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "code", |
| 25 | + "execution_count": null, |
| 26 | + "id": "2", |
| 27 | + "metadata": {}, |
| 28 | + "outputs": [], |
| 29 | + "source": [ |
| 30 | + "cfg = load_config(config_path=\"../example_config.yaml\")\n", |
| 31 | + "simmm = Simulate()\n", |
| 32 | + "mmm_input_df, channel_roi = simmm.run_with_config(config=cfg)\n", |
| 33 | + "mmm_input_df.head()" |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + "cell_type": "markdown", |
| 38 | + "id": "3", |
| 39 | + "metadata": {}, |
| 40 | + "source": [ |
| 41 | + "## Distribution to Geos\n", |
| 42 | + "___\n", |
| 43 | + "Take the MMM data that was generated in the simulation and project that into geographies" |
| 44 | + ] |
| 45 | + }, |
| 46 | + { |
| 47 | + "cell_type": "code", |
| 48 | + "execution_count": null, |
| 49 | + "id": "4", |
| 50 | + "metadata": {}, |
| 51 | + "outputs": [], |
| 52 | + "source": [ |
| 53 | + "from pysimmmulator import Geos, distribute_to_geos" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "cell_type": "code", |
| 58 | + "execution_count": null, |
| 59 | + "id": "5", |
| 60 | + "metadata": {}, |
| 61 | + "outputs": [], |
| 62 | + "source": [ |
| 63 | + "united_states = Geos(total_population=330_000_000)\n", |
| 64 | + "states = united_states.create_random_geos(count=50)" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": null, |
| 70 | + "id": "6", |
| 71 | + "metadata": {}, |
| 72 | + "outputs": [], |
| 73 | + "source": [ |
| 74 | + "dis_mmm_input_df = distribute_to_geos(mmm_input=mmm_input_df, geo_details=states)" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "code", |
| 79 | + "execution_count": null, |
| 80 | + "id": "7", |
| 81 | + "metadata": {}, |
| 82 | + "outputs": [], |
| 83 | + "source": [ |
| 84 | + "dis_mmm_input_df.head(10)" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "markdown", |
| 89 | + "id": "8", |
| 90 | + "metadata": {}, |
| 91 | + "source": [ |
| 92 | + "## Generate Studies\n", |
| 93 | + "___\n", |
| 94 | + "Using the true roi's of each channel, generate x simulated studies per channel" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "code", |
| 99 | + "execution_count": null, |
| 100 | + "id": "9", |
| 101 | + "metadata": {}, |
| 102 | + "outputs": [], |
| 103 | + "source": [ |
| 104 | + "from pysimmmulator import Study, BatchStudy\n", |
| 105 | + "import matplotlib.pyplot as plt" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "code", |
| 110 | + "execution_count": null, |
| 111 | + "id": "10", |
| 112 | + "metadata": {}, |
| 113 | + "outputs": [], |
| 114 | + "source": [ |
| 115 | + "ct = 8\n", |
| 116 | + "studies = BatchStudy(channel_rois=channel_roi)\n", |
| 117 | + "sim_studies = studies.generate(ct)" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "execution_count": null, |
| 123 | + "id": "11", |
| 124 | + "metadata": {}, |
| 125 | + "outputs": [], |
| 126 | + "source": [ |
| 127 | + "fig, ax = plt.subplots(2,2, figsize=(6,6), dpi=100)\n", |
| 128 | + "chans = list(sim_studies.keys())\n", |
| 129 | + "for a in range(2): \n", |
| 130 | + " for b in range(2):\n", |
| 131 | + " f = ax[a][b]\n", |
| 132 | + " chan = chans.pop()\n", |
| 133 | + " f.hist(sim_studies[chan], bins=ct*2, color='red', alpha=.75)\n", |
| 134 | + " f.axvline(channel_roi[chan], ls='--', color='black')\n", |
| 135 | + " f.set_title(f\"{chan} results (n={ct})\")\n", |
| 136 | + "plt.tight_layout()" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "execution_count": null, |
| 142 | + "id": "12", |
| 143 | + "metadata": {}, |
| 144 | + "outputs": [], |
| 145 | + "source": [] |
| 146 | + } |
| 147 | + ], |
| 148 | + "metadata": { |
| 149 | + "kernelspec": { |
| 150 | + "display_name": "venv", |
| 151 | + "language": "python", |
| 152 | + "name": "python3" |
| 153 | + }, |
| 154 | + "language_info": { |
| 155 | + "codemirror_mode": { |
| 156 | + "name": "ipython", |
| 157 | + "version": 3 |
| 158 | + }, |
| 159 | + "file_extension": ".py", |
| 160 | + "mimetype": "text/x-python", |
| 161 | + "name": "python", |
| 162 | + "nbconvert_exporter": "python", |
| 163 | + "pygments_lexer": "ipython3", |
| 164 | + "version": "3.13.5" |
| 165 | + } |
| 166 | + }, |
| 167 | + "nbformat": 4, |
| 168 | + "nbformat_minor": 5 |
| 169 | +} |
0 commit comments