Skip to content

Commit

Permalink
removed unnecessary data and cleaned up notebooks more
Browse files Browse the repository at this point in the history
  • Loading branch information
briandepasquale committed Aug 26, 2024
1 parent ae96701 commit 9bd56cd
Show file tree
Hide file tree
Showing 21 changed files with 272 additions and 1,055 deletions.
Binary file removed examples/data/T103_297684.mat
Binary file not shown.
Binary file removed examples/data/T103_297945.mat
Binary file not shown.
Binary file removed examples/data/T103_298331.mat
Binary file not shown.
Binary file removed examples/data/T103_298622.mat
Binary file not shown.
Binary file removed examples/data/T103_299015.mat
Binary file not shown.
Binary file removed examples/data/T103_299423.mat
Binary file not shown.
Binary file removed examples/data/T103_301336.mat
Binary file not shown.
Binary file removed examples/data/T103_302671.mat
Binary file not shown.
Binary file removed examples/data/T103_302877.mat
Binary file not shown.
Binary file removed examples/data/T103_304450.mat
Binary file not shown.
Binary file removed examples/data/T103_305189.mat
Binary file not shown.
Binary file removed examples/data/T103_305431.mat
Binary file not shown.
Binary file removed examples/data/T103_305643.mat
Binary file not shown.
Binary file removed examples/data/T103_305822.mat
Binary file not shown.
Binary file removed examples/data/T103_306584.mat
Binary file not shown.
Binary file removed examples/data/T103_306964.mat
Binary file not shown.
Binary file removed examples/data/T103_307162.mat
Binary file not shown.
Binary file removed examples/data/T103_307847.mat
Binary file not shown.
743 changes: 35 additions & 708 deletions examples/fit_choice_synthetic_data.ipynb

Large diffs are not rendered by default.

347 changes: 0 additions & 347 deletions examples/fit_neural_real_data.ipynb

Large diffs are not rendered by default.

237 changes: 237 additions & 0 deletions examples/loading_and_saving.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using Distributed\n",
"addprocs(8);"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"@everywhere using PulseInputDDM, Flatten"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Generate some data\n",
"\n",
"Create an instance of the `θchoice` [composite type](https://docs.julialang.org/en/v1/manual/types/#Composite-Types) which contains the 9 parameters of a choice DDM model. "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"θ_syn = θchoice(θz=θz(σ2_i = 1., B = 13., λ = -0.5, σ2_a = 10., σ2_s = 1.0,\n",
" ϕ = 0.4, τ_ϕ = 0.02), bias=0.1, lapse=0.1);"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"xgen = collect(Flatten.flatten(θ_syn));"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Generate 20K trials of the synthetic data using those parameters. change `rng` to get a different set with the same parameters. `dt` specifies the temporal binning of the data. `1e-2` has worked well."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"_, data = synthetic_data(;θ=θ_syn, ntrials=8_000, rng=2, dt=1e-2);"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"choiceDDM{θchoice{θz{Float64}, Float64}}\n",
" θ: θchoice{θz{Float64}, Float64}\n",
" n: Int64 53\n",
" cross: Bool false\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"model = choiceDDM(θ=θ_syn)\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"choiceoptions\n",
" fit: Array{Bool}((9,)) Bool[1, 1, 1, 1, 1, 1, 1, 1, 1]\n",
" lb: Array{Float64}((9,)) [0.0, 2.0, -5.0, 0.0, 0.0, 0.0, 0.005, -5.0, 0.0]\n",
" ub: Array{Float64}((9,)) [30.0, 100.0, 5.0, 200.0, 10.0, 1.2, 1.0, 5.0, 1.0]\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"options = choiceoptions(lb=vcat([0., 2., -5., 0., 0., 0., 0.005, -5.0, 0.0]),\n",
" ub = [30., 100., 5., 200., 10., 1.2, 1., 5.0, 1.0], \n",
" fit = trues(9))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Saving and reloading modeling results and saving data\n",
"\n",
"Use the `save_choice_model` function to save the optimized model, the options used to define the optimization, and the confidence intervals"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"save_file = \"./data/example_results.mat\"\n",
"save_choice_model(save_file, model, options)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"if you want to restart the optimization from where you stopped `reload_choice_model` will reload those model parameters and the `options`"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"θ, options = reload_choice_model(save_file);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Save the choice data using `save_choice_data` and then reload it using `load_choice_data`"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"import PulseInputDDM: save_choice_data"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"save_choice_data(\"./data/example_matfile_2.mat\", data)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"data = load_choice_data(\"./data/example_matfile_2.mat\");"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading data and fitting a choice model from real data\n",
"\n",
"Because many neuroscientists use matlab, we use the [MAT.jl](https://github.com/JuliaIO/MAT.jl) package for IO. Data can be loaded using two conventions. One of these conventions is easier when data is saved within matlab as a .MAT file, and is described below. \n",
"\n",
"The package expects your data to live in a single .mat file which should contain a struct called `rawdata`. Each element of `rawdata` should have data for one behavioral trial and `rawdata` should contain the following fields with the specified structure:\n",
"\n",
" - `rawdata.leftbups`: row-vector containing the relative timing, in seconds, of left clicks on an individual trial. 0 seconds is the start of the click stimulus.\n",
" - `rawdata.rightbups`: row-vector containing the relative timing in seconds (origin at 0 sec) of right clicks on an individual trial. 0 seconds is the start of the click stimulus.\n",
" - `rawdata.T`: the duration of the trial, in seconds. The beginning of a trial is defined as the start of the click stimulus. The end of a trial is defined based on the behavioral event “cpoke_end”. This was the Hanks convention.\n",
" - `rawdata.pokedR`: `Bool` representing the animal choice (1 = right).\n",
" \n",
"The example file located at `../choice model/example_matfile.mat` adheres to this convention and can be loaded using the `load_choice_data` method."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"data = load_choice_data(\"./data/example_matfile.mat\");"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.10.2",
"language": "julia",
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 9bd56cd

Please sign in to comment.