-
Notifications
You must be signed in to change notification settings - Fork 7
Feature sequential sampling models #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zooaal
wants to merge
37
commits into
v4.0
Choose a base branch
from
feature-sequentialSamplingModels
base: v4.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
ffc7094
add: Sequential Sampling Model, Evidence Accumulation Simulation
Zooaal 0324d96
update: major fixes
Zooaal a0f9253
Update src/component.jl
Zooaal ff43378
Update src/component.jl
Zooaal 115bd41
Apply suggestions from code review
Zooaal 6d0e09e
Apply suggestions from code review
Zooaal cf1a757
fixture from code review
Zooaal 7bdc931
Update DriftComponent to use max_length instead of an time vector
Zooaal 844262e
changed two KellyModel Parameter names
Zooaal c524e9b
Update CITATION.cff
jschepers 0da7b23
Change citation title to paper title
jschepers e3e8e54
added joss badge to readme
jschepers 46d3e28
Edit citation section in README
jschepers ae90422
Add BibTeX entry to readme
jschepers af929ef
Format citation section in README
jschepers 8de419c
Format citation section in README
jschepers 3974473
Minor change
jschepers 9a7b332
Fix and update CITATION.cff file
jschepers 1c35c8d
Add JOSS paper as preferred citation
jschepers f020998
Apply basic suggestions from code review
Zooaal e68c5dc
Update from code review
Zooaal 82834d2
Apply suggestions from code review
Zooaal 9c0cdf7
add onset transform to Int and comment on Kelly Model String Fields
Zooaal b0500b0
v0.4.1 - compat DSP and SignalAnalysis
behinger 2e23679
merge
behinger dae4cc9
Kelly Model is no longer exported, fix
behinger 0e2657a
added SequentialSamplingModels to docs
behinger d48031c
Update CI.yml to run CI for PR on all branches not just main
jschepers 3ccfa77
Update unfold family table & redirect doc links
xuyg16 192f7b3
Update CI.yml
behinger acec4ff
Update CI.yml
behinger 07cc43a
merged tutorials, added Truncated, added urgency signal
behinger ba1ee0b
merge main
behinger 04460ce
fix merge conflict remainder in tests
behinger d1ff5e8
added empty docstrings to abstracttypes
behinger bfa3e80
fix tests, added warning tau=0, export KellyModel,LBA,DDM
behinger 4a042b8
oops forgot to save
behinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| # # Simulate an Evidence Accumulation Overlap and Deconvolution | ||
|
|
||
| # We want to use the SequenceDesign with three components to simulate an full evidence accumulation process with a Overlap between the evidence accumulation and the response signal. Afterwards we use the Deconvolution Method from Unfold to unfold the signals again. | ||
|
|
||
|
|
||
|
|
||
| # ### Setup | ||
| # ```@raw html | ||
| # <details> | ||
| # <summary>Click to expand</summary> | ||
| # ``` | ||
| using UnfoldSim | ||
| using Unfold | ||
| using StableRNGs | ||
| using CairoMakie, UnfoldMakie | ||
| using SequentialSamplingModels | ||
|
|
||
| fs = 500 | ||
| Δt = 1 / fs; # time step | ||
| tEnd = 1.0 # trial Duration | ||
| time_vec = 0:Δt:tEnd; # time base - let's make it a typical stimulus duration | ||
| max_length = tEnd / Δt | ||
|
|
||
| c_stimulus = LinearModelComponent(; | ||
| basis = ones(Int(0.1 * fs)), | ||
| formula = @formula(0 ~ 1 + condition), | ||
| β = [1, 0], | ||
| ) | ||
| c_response = LinearModelComponent(; | ||
| basis = ones(Int(0.2 * fs)), | ||
| formula = @formula(0 ~ 1 + condition), | ||
| β = [-0.5, 0], | ||
| ) | ||
|
|
||
| # ```@raw html | ||
| # </details > | ||
| # ``` | ||
| # ## Design | ||
| # Let's generate a single design with two drift_rates | ||
| design_single = | ||
| SingleSubjectDesign(conditions = Dict(:drift_rate => [1, 2], :condition => [1])) | ||
| design_seq = SequenceDesign(design_single, "SCR_") | ||
| design_rep = RepeatDesign(design_seq, 100) # 100 SCR-repeats | ||
|
|
||
| # # Simplified S-C-R drift-model with LBA | ||
| # ## LBA | ||
| # The following parameters are described in the [SequentialSamplingModels.LBA model documentation](https://itsdfish.github.io/SequentialSamplingModels.jl/dev/lba/) | ||
| v = [0.8] ## Drift Rate, needs to be in [ ] for compatability with `SequentialSamplingModels.jl`` | ||
| A = 0.2 ## The starting point is sampled uniformly between `[0, A]` | ||
| k = 0.4 ## Difference of A with the bound/threshold ($A + k = b$), where b is the decision threshold. | ||
|
|
||
| lba_parameter = Dict(:ν => v, :A => A, :k => k, :τ => 0.0) # we didnt specify σ thus it is 1 by default, | ||
|
|
||
| # !!! important | ||
| # The non-decision time has to be specified here as "τ=>0." because it is not defined whether non-decision time applies to stimulus encoding or response execution. If you have a non-0 value here, the events following the DriftComponent will be shifted by τ. | ||
| drift = DriftComponent(max_length, fs, LBA, lba_parameter) | ||
|
|
||
| # Let's have a quick look at the simulation | ||
| series( | ||
| hcat(simulate_component.(StableRNG.(1:10), Ref(drift), Ref(design_single))...)', | ||
| solid_color = (:black, 0.5), | ||
| ) | ||
| # Super! Our start values are sampled between [0, 0.2] as indicated, and the boundary is at A+k = 0.2 + 0.4 = 0.6 | ||
|
|
||
| # ### Simulate EEG data | ||
| components = Dict('S' => [c_stimulus], 'C' => [drift], 'R' => [c_response]) | ||
|
|
||
| # Next we define a SequenceOnset ingredient, this allows us fine-grained control on when events should happen. | ||
|
|
||
| seq_onset = SequenceOnset( | ||
| Dict( | ||
| 'S' => UniformOnset(width = 0, offset = 0.2 * fs), # distance S<->C - we could choose 0.1*fs to immediately start after the stimulus component | ||
| 'C' => DriftOnset(), ## automatically determines which is the respective DriftComponent | ||
| 'R' => UniformOnset(width = 0, offset = 2 * fs), # distance R<->S | ||
| ), | ||
| ) | ||
|
|
||
| # ## Simulate data with the created design, components and onsets | ||
| data, evts = UnfoldSim.simulate( | ||
| StableRNG(12), | ||
| design_rep, | ||
| components, | ||
| seq_onset, | ||
| NoNoise(), # PinkNoise(noiselevel=1) | ||
| ) | ||
| # ## Plot EEG to see the overlap as it appears | ||
| f_data, _ax, _h = lines(data[1:5000]) | ||
| vlines!(evts.latency, color = Int.(evts.event), alpha = 0.3) | ||
| xlims!(700, 3500) | ||
| f_data | ||
|
|
||
| # # Complex S-C-R drift-model ala `Kelly et al.` | ||
|
|
||
| # In addition to changing the model to a more realistic version, we will also make use of the `drift_rate` specification in our `design`` | ||
|
|
||
| v = "drift_rate" ## take the drift rate directly from the design | ||
|
|
||
| # The KellyModel has _many_ default parameters, let's grab them and immediately change a few | ||
|
|
||
| kelly_model = | ||
| UnfoldSim.KellyModel(drift_rate = v, motor_delay = 0.4, sensor_encoding_delay = 0.2) | ||
|
|
||
|
|
||
|
|
||
| % parameters: | ||
| % Urgency: | ||
| Z = 0.3; % starting level at evidence onset | ||
| U = 1; % slope (buildup rate) of dynamic urgency at the motor level (prop. to bound /sec) | ||
| Sz = 0.4; % start point variability at the motor level applied independently to both sides - full width of uniform distribution | ||
| Su = 0.17 % between-trial var in urgency rate | ||
|
|
||
| d = [1 2]; % drift rate | ||
| s = 0.5; % gaussian noise /sec at accumulator level | ||
| evonT = 0.2; % time at which sensory evidence starts impacting on the sensory accumulator | ||
| %accT = 0.2; % Accumulation onset time. Let's say same as evidence encoding onset. | ||
| mT = 0.1; % motor time | ||
| st = 0.1; % motor time variability | ||
| Terz = 0.1; % variability applied to sensory encoding delays | ||
|
|
||
| postAccDurM = 0.1; % mean duration of post decision accumulation | ||
| postAccDurS = 0.2; % range of uniform dist of post-decision accumulation duration | ||
|
|
||
| CPPrampdownDur = 0.1; % in Sec; CPP will linearly ramp back down after the accumulation stops | ||
|
|
||
|
|
||
| kelly_model = UnfoldSim.KellyModel( | ||
| drift_rate = v, | ||
| motor_delay = 0.1, | ||
| motor_delay_varibility = 0.1, | ||
| sensor_encoding_delay_variability = 0.1, | ||
| sensor_encoding_delay = 0.1, | ||
| accumulative_level_noise=0.5, | ||
| urgency = 1, | ||
| urgency_variability = 0.17, | ||
| post_accumulation_duration = 0.1, | ||
| post_accumulation_duration_variability = 0.2, | ||
| boundary = 0.7, | ||
| ramp_down_duration = 0.1 | ||
| ) | ||
| kelly_model_parameter = UnfoldSim.create_kelly_parameters_dict(kelly_model) | ||
| drift = DriftComponent(max_length, fs, UnfoldSim.KellyModel, kelly_model_parameter) | ||
| components = Dict('S' => [c_stimulus], 'C' => [drift], 'R' => [c_response]) | ||
|
|
||
| # We are ready to simulate! | ||
| data, evts = UnfoldSim.simulate( | ||
| StableRNG(12), | ||
| design_rep, | ||
| components, | ||
| seq_onset, | ||
| NoNoise(), # PinkNoise(noiselevel=1) | ||
| ) | ||
| # ## Plot EEG to see the overlap as it appears | ||
| f_data, _ax, _h = lines(data[1:5000]) | ||
| vlines!(evts.latency, color = Int.(evts.event), alpha = 0.3) | ||
| xlims!(700, 3500) | ||
| f_data | ||
|
|
||
| # !!! note | ||
| # There are varying gaps between the stimulus offset <-> driftstart and driftend <-> response start. This is because the `KellyModel` by default has a `sensor_encoding_delay` and a `motor_delay` (including a `motor_delay_variability` etc.) | ||
|
|
||
| # # ERP & Deconvolution | ||
| # Let's calculate traditional ERPs and deconvolved ones! | ||
| evts.event = string.(evts.event) # due to a Unfold-bug we have to convert :S | ||
| data_epochs, times_epoch = | ||
| Unfold.epoch(data = data, tbl = evts, τ = (-1.3, 1.3), sfreq = fs); | ||
| f = @formula(0 ~ 1 + drift_rate) | ||
| m = fit(UnfoldModel, ["S" => (f, times_epoch), "R" => (f, times_epoch)], evts, data_epochs); | ||
| plot_erp( | ||
| effects(Dict(:drift_rate => [2, 3]), m); | ||
| mapping = (; | ||
| color = :drift_rate => nonnumeric, | ||
| col = :eventname => UnfoldMakie.sorter(["S", "R"]), | ||
| ), | ||
| ) | ||
|
|
||
| # ## Deconvolution of the overlap | ||
| fir_stim = firbasis(τ = (-0.1, 1.3), sfreq = fs) | ||
| fir_resp = firbasis(τ = (-1, 0.3), sfreq = fs) | ||
|
|
||
| m = fit(UnfoldModel, ["S" => (f, fir_stim), "R" => (f, fir_resp)], evts, data); | ||
| plot_erp( | ||
| effects(Dict(:drift_rate => [2, 3]), m); | ||
| mapping = (; | ||
| color = :drift_rate => nonnumeric, | ||
| col = :eventname => UnfoldMakie.sorter(["S", "R"]), | ||
| ), | ||
| ) | ||
| # Deconvolution sucessfully removed the stimulus and response overlaps from our estimates, but it kept the drift-diffusion aspect nearly untouched. It is important to stress the "nearly", because depending on the `delay` parameters, this can potentially lead to problematic situation where it is unclear whether the drift activity should be assigned to S or R. In most realistic situations we found to be safe. | ||
| # Further note that the drift-diffusion amplitude can be reduced because it is split up between `S` and `R` events.` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶