{ "cells": [ { "cell_type": "markdown", "source": [ "# Simulate Data from the SceneWalk Model" ], "metadata": {} }, { "cell_type": "code", "source": [ "import os\n", "import shutil\n", "import sys\n", "from collections import OrderedDict\n", "import numpy as np\n", "from matplotlib import pyplot as plt\n", "from scipy.stats import norm as normal, truncnorm as truncated_normal\n", "import seaborn as sns\n", "from scenewalk.scenewalk_model_object import scenewalk as scenewalk_model\n", "from scenewalk.utils import loadData\n", "from scenewalk.simulation import simulate_dataset" ], "outputs": [], "execution_count": 1, "metadata": { "collapsed": false, "outputHidden": false, "inputHidden": false, "execution": { "iopub.status.busy": "2020-04-01T00:00:01.876Z", "iopub.execute_input": "2020-04-01T00:00:01.880Z", "iopub.status.idle": "2020-04-01T00:00:02.857Z", "shell.execute_reply": "2020-04-01T00:00:02.868Z" } } }, { "cell_type": "markdown", "source": [ "Get some basis data" ], "metadata": { "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "dataDict = loadData.load_data(\"spst_all\")\n", "dataDict = loadData.shorten_set(dataDict, 2)\n", "x_dat, y_dat, dur_dat, im_dat, densities_dat, d_range = loadData.dataDict2vars(dataDict)" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "shortening from 35 to 2\n" ] } ], "execution_count": 2, "metadata": { "collapsed": false, "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } }, "execution": { "iopub.status.busy": "2020-04-01T00:00:02.863Z", "iopub.execute_input": "2020-04-01T00:00:02.865Z", "iopub.status.idle": "2020-04-01T00:00:02.891Z", "shell.execute_reply": "2020-04-01T00:00:02.998Z" } } }, { "cell_type": "markdown", "source": [ "## Scenewalk Model\n", "Here you define the setup of the model." ], "metadata": {} }, { "cell_type": "code", "source": [ "sw = scenewalk_model(\"subtractive\", \"zero\", \"off\", \"off\", \"off\", {'x': d_range[0], 'y': d_range[1]}, {\"logged_z\":True, \"coupled_oms\":True})\n", "\n", "sw.whoami()" ], "outputs": [ { "output_type": "execute_result", "execution_count": 3, "data": { "text/plain": [ "'I am a subtractive scenewalk model, initialized with zero activation, in 2 exponents mode, with om_i as a fraction, with logged z'" ] }, "metadata": {} } ], "execution_count": 3, "metadata": { "collapsed": false, "outputHidden": false, "inputHidden": false, "execution": { "iopub.status.busy": "2020-04-01T00:00:02.899Z", "iopub.execute_input": "2020-04-01T00:00:02.912Z", "iopub.status.idle": "2020-04-01T00:00:02.921Z", "shell.execute_reply": "2020-04-01T00:00:03.001Z" } } }, { "cell_type": "markdown", "source": [ "It will tell you which parameters it needs and the order if you're passing them in as a list:" ], "metadata": {} }, { "cell_type": "code", "source": [ "sw.get_param_list_order()" ], "outputs": [ { "output_type": "execute_result", "execution_count": 4, "data": { "text/plain": [ "['omegaAttention',\n", " 'omfrac',\n", " 'sigmaAttention',\n", " 'sigmaInhib',\n", " 'gamma',\n", " 'lamb',\n", " 'inhibStrength',\n", " 'zeta']" ] }, "metadata": {} } ], "execution_count": 4, "metadata": { "collapsed": false, "outputHidden": false, "inputHidden": false, "execution": { "iopub.status.busy": "2020-04-01T00:00:02.927Z", "iopub.execute_input": "2020-04-01T00:00:02.930Z", "iopub.status.idle": "2020-04-01T00:00:02.936Z", "shell.execute_reply": "2020-04-01T00:00:03.005Z" } } }, { "cell_type": "code", "source": [ "param_dict = OrderedDict({\n", " \"omegaAttention\": 18.5,\n", " \"omfrac\": 10,\n", " \"sigmaAttention\": 6,\n", " \"sigmaInhib\": 12,\n", " \"gamma\" : 8,\n", " \"lamb\" : 0.6,\n", " \"inhibStrength\" :0.7,\n", " \"zeta\" : -2,\n", "})" ], "outputs": [], "execution_count": 5, "metadata": { "collapsed": false, "outputHidden": false, "inputHidden": false, "execution": { "iopub.status.busy": "2020-04-01T00:00:02.942Z", "iopub.execute_input": "2020-04-01T00:00:02.946Z", "iopub.status.idle": "2020-04-01T00:00:02.950Z", "shell.execute_reply": "2020-04-01T00:00:03.008Z" } } }, { "cell_type": "code", "source": [ "sw.update_params(param_dict)\n", "#print(sw.get_params())\n", "print(\"have we provided all relevant parameters?:\", sw.check_params_for_config())\n", "print(\"are the parameters within the defined bounds?:\", sw.check_params_in_bounds())\n" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "have we provided all relevant parameters?: True\n", "are the parameters within the defined bounds?: True\n" ] } ], "execution_count": 6, "metadata": { "collapsed": false, "outputHidden": false, "inputHidden": false, "execution": { "iopub.status.busy": "2020-04-01T00:00:02.956Z", "iopub.execute_input": "2020-04-01T00:00:02.959Z", "iopub.status.idle": "2020-04-01T00:00:02.965Z", "shell.execute_reply": "2020-04-01T00:00:03.010Z" } } }, { "cell_type": "markdown", "source": [ "## Now Simulate" ], "metadata": { "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "sim_id = simulate_dataset.simulate(dur_dat, im_dat, densities_dat, sw, params=None, start_loc=\"center\", x_path=None, y_path=None, resample_durs=False, verbose = True)" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "sub 0\n", "sub 1\n" ] } ], "execution_count": 7, "metadata": { "collapsed": false, "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } }, "execution": { "iopub.status.busy": "2020-04-01T00:00:02.969Z", "iopub.execute_input": "2020-04-01T00:00:02.972Z", "iopub.status.idle": "2020-04-01T00:00:09.654Z", "shell.execute_reply": "2020-04-01T00:00:09.706Z" } } }, { "cell_type": "markdown", "source": [ "## Load simulated data" ], "metadata": { "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "sim_dat_dict = loadData.load_sim_data(os.path.abspath(sim_id))" ], "outputs": [], "execution_count": 8, "metadata": { "collapsed": false, "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } }, "execution": { "iopub.status.busy": "2020-04-01T00:00:09.660Z", "iopub.execute_input": "2020-04-01T00:00:09.664Z", "iopub.status.idle": "2020-04-01T00:00:09.669Z", "shell.execute_reply": "2020-04-01T00:00:09.711Z" } } }, { "cell_type": "markdown", "source": [ "## More settings for simulations" ], "metadata": { "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "markdown", "source": [ "Advanced settings include\n", "instead of params=None you can give it a dictionary of all parameters the model needs by subject. i.e." ], "metadata": { "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "param_subj_dict = {\n", " 0 : param_dict,\n", " 1 : param_dict,\n", " 2 : param_dict,\n", " 3 : param_dict,\n", " 4 : param_dict\n", "}" ], "outputs": [], "execution_count": 9, "metadata": { "collapsed": false, "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } }, "execution": { "iopub.status.busy": "2020-04-01T00:00:09.675Z", "iopub.execute_input": "2020-04-01T00:00:09.679Z", "iopub.status.idle": "2020-04-01T00:00:09.684Z", "shell.execute_reply": "2020-04-01T00:00:09.715Z" } } }, { "cell_type": "code", "source": [ "sim_id = simulate_dataset.simulate(dur_dat, im_dat, densities_dat, sw, params=param_subj_dict, start_loc=\"center\", x_path=None, y_path=None, resample_durs=False, verbose=True)" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "sub 0\n", "sub 1\n" ] } ], "execution_count": 10, "metadata": { "collapsed": false, "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } }, "execution": { "iopub.status.busy": "2020-04-01T00:00:09.689Z", "iopub.execute_input": "2020-04-01T00:00:09.694Z", "iopub.status.idle": "2020-04-01T00:00:16.248Z", "shell.execute_reply": "2020-04-01T00:00:16.268Z" } } }, { "cell_type": "code", "source": [ "sw.get_params()" ], "outputs": [ { "output_type": "execute_result", "execution_count": 11, "data": { "text/plain": [ "OrderedDict([('omegaAttention', 18.5),\n", " ('omegaInhib', 1.85),\n", " ('sigmaAttention', 6),\n", " ('sigmaInhib', 12),\n", " ('gamma', 8),\n", " ('lamb', 0.6),\n", " ('inhibStrength', 0.7),\n", " ('zeta', 0.01)])" ] }, "metadata": {} } ], "execution_count": 11, "metadata": { "collapsed": false, "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } }, "execution": { "iopub.status.busy": "2020-04-01T00:00:16.254Z", "iopub.execute_input": "2020-04-01T00:00:16.257Z", "iopub.status.idle": "2020-04-01T00:00:16.265Z", "shell.execute_reply": "2020-04-01T00:00:16.270Z" } } } ], "metadata": { "kernel_info": { "name": "swtemp" }, "language_info": { "name": "python", "version": "3.8.0", "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py" }, "kernelspec": { "name": "swtemp", "language": "python", "display_name": "swtemp" }, "nteract": { "version": "0.22.0" } }, "nbformat": 4, "nbformat_minor": 4 }