Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ authors = ["Till Prölß", " René Skukies", " Benedikt Ehinger"]
version = "0.1.0"

[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
Expand All @@ -16,3 +15,16 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Unfold = "181c99d8-e21b-4ff3-b70b-c233eddec679"

[compat]
DSP = "0.8"
DataFrames = "1"
DataFramesMeta = "0.15"
Distributions = "0.25"
FFTW = "1"
Parameters = "0.12"
Peaks = "0.5, 0.6"
StableRNGs = "1"
Statistics = "1"
Unfold = "0.8"
julia = "1.11"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ cfg = RideConfig(
r_range = [0, 0.4],
c_range = [-0.4, 0.4],
#the range in which the initial peak estimation for the C component is performed
formulas = [@formula(0 ~ 1), @formula(0 ~ 1), @formula(0 ~ 1)] # formulas used for S, R, and C component (in this order!); if not specified these will default to `@formula(0~1)`
c_estimation_range = [0, 0.9],
#the range for one epoch
epoch_range = [-0.1, 1]
Expand Down
1 change: 1 addition & 0 deletions dev/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unfold = "181c99d8-e21b-4ff3-b70b-c233eddec679"
UnfoldBIDS = "b54e767b-1ebd-4480-ac2a-f5f4d8853074"
UnfoldSim = "ed8ae6d2-84d3-44c6-ab46-0baf21700804"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"

Expand Down
8 changes: 4 additions & 4 deletions dev/runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using BenchmarkTools
#simulate data
begin
sim_inputs = simulation_inputs()
sim_inputs.noise = PinkNoise(; noiselevel = 1)
sim_inputs.noise = PinkNoise(; noiselevel = 0)
#sim_inputs.c_width = 30
#sim_inputs.c_offset = 10
#sim_inputs.r_width = 60
Expand Down Expand Up @@ -47,15 +47,15 @@ begin
save_interim_results = true,
)

save_to_hdf5_ride_format(
#=save_to_hdf5_ride_format(
"./dev/data/simulated_data.h5",
data,
evts,
cfg.epoch_range,
'S',
'R',
cfg.sfreq,
)
)=#

#remove the C events from the evts table, these will be estimated by the ride algorithm
evts_without_c = @subset(evts, :event .!= 'C')
Expand Down Expand Up @@ -120,7 +120,7 @@ begin
Legend(f[1, 2], [s, r, c], ["S", "R", "C"])
Label(f[0, :], text = "Expected Results")
display(f)
save("actual_erps.png", f)
#save("actual_erps.png", f)
end

if true == false
Expand Down
1 change: 1 addition & 0 deletions docs/src/11-running_ride.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ begin
r_range = [0, 0.4],
c_range = [-0.4, 0.4],
#the range in which the initial peak estimation for the C component is performed
formulas = [@formula(0 ~ 1), @formula(0 ~ 1), @formula(0 ~ 1)] # formulas used for S, R, and C component; if not specified these will default to `@formula(0~1)`
c_estimation_range = [0, 0.9],
#the range for one epoch
epoch_range = [-0.1, 1]
Expand Down
4 changes: 2 additions & 2 deletions src/ride/ride_classic_algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function ride_algorithm(

## data_preparation
data_reshaped = reshape(data, (1, :))
evts_s = @subset(evts, :event .== 'S')
evts_s = @subset(evts, :event .== 'S') # TODO: Let user define event names
evts_r = @subset(evts, :event .== 'R')
interim_results = Vector{RideResults}()

Expand Down Expand Up @@ -134,7 +134,7 @@ function ride_algorithm(
[(evts_s, s_erp, cfg.s_range), (evts_r, r_erp, cfg.r_range)],
cfg.sfreq,
)
if cfg.filtering
if cfg.filtering # TODO: Check if this is correct; also check for filter artefacts
data_subtracted_s_and_r = dspfilter(data_subtracted_s_and_r[1, :], 5, 20)
end
data_epoched_subtracted_s_and_r, n = Unfold.epoch(
Expand Down
4 changes: 4 additions & 0 deletions src/ride/ride_structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ through manual inspection of the data.
through manual inspection of the data.
- `c_estimation_range::Vector{Float64}`: The range used for the intial C
component latency estimation through peak picking.
- formulas = [@formula(0 ~ 1), @formula(0 ~ 1), @formula(0 ~ 1)]: Vector containing formulas for the S, R, and C component (in this order!!!).
Only used during the UnfoldRIDE algorithm.
- `epoch_range::Vector{Float64}`: The range of one epoch centered around the stimulus onset.
- `iteration_limit::Int = 4`: The maximum number of iterations of the RIDE algorithm. This
is for the outer decomposition-latency estimation loop.
Expand All @@ -39,6 +41,7 @@ cfg = RideConfig(
r_range = [0, 0.8],
c_range = [-0.4, 0.4],
c_estimation_range = [-0.1, 0.9],
formulas = [@formula(0 ~ 1), @formula(0 ~ 1), @formula(0 ~ 1 + reaction_time)] # formulas used for S, R, and C component
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to do:
formulas = ['S'=>@formula(0~1),'C'=>@formula(0~1),'R'=>@formula(0~1)], e.g. as a list of pairs? that would generalize to more events more readily and doesnt have the issue of order. You the only have to splice in the firbasis in the fit command down below

epoch_range = [-0.3, 1.6],
iteration_limit = 5,
heuristic1 = true,
Expand All @@ -54,6 +57,7 @@ cfg = RideConfig(
r_range::Vector{Float64}
c_range::Vector{Float64}
c_estimation_range::Vector{Float64}
formulas = [@formula(0 ~ 1), @formula(0 ~ 1), @formula(0 ~ 1)] # formulas used for S, R, and C component
epoch_range::Vector{Float64}
iteration_limit::Int = 4
heuristic1::Bool = true
Expand Down
4 changes: 2 additions & 2 deletions src/ride/ride_unfold_algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function ride_algorithm(
m = fit(
UnfoldModel,
[
'S' => (@formula(0 ~ 1), firbasis(cfg.s_range, cfg.sfreq, "")),
'R' => (@formula(0 ~ 1), firbasis(cfg.r_range, cfg.sfreq, "")),
'S' => (cfg.formulas[1], firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict
'R' => (cfg.formulas[2], firbasis(cfg.r_range, cfg.sfreq, "")),
],
evts,
data,
Expand Down
6 changes: 3 additions & 3 deletions src/ride/ride_unfold_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ function unfold_decomposition(data, evts_with_c, cfg)
m = fit(
UnfoldModel,
[
'S' => (@formula(0 ~ 1), firbasis(cfg.s_range, cfg.sfreq, "")),
'R' => (@formula(0 ~ 1), firbasis(cfg.r_range, cfg.sfreq, "")),
'S' => (cfg.formulas[1], firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict
'R' => (cfg.formulas[2], firbasis(cfg.r_range, cfg.sfreq, "")),
'C' => (
@formula(0 ~ 1),
cfg.formulas[3],
firbasis(c_range_adjusted(cfg.c_range), cfg.sfreq, ""),
),
],
Expand Down
4 changes: 3 additions & 1 deletion test/simulate_test_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ end
components_onset::Vector{AbstractOnset}
end


function UnfoldSim.simulate_onsets(rng, onset::SequenceOnset, simulation::Simulation)
#calculate stimulus onsets
stimulus_onsets =
Expand All @@ -54,7 +55,8 @@ function UnfoldSim.simulate_onsets(rng, onset::SequenceOnset, simulation::Simula
end

#cut result to the design size
result = result[1:size(simulation.design)]
@debug "Type of simulation desing: " typeof(simulation.design)
result = result[1:size(rng, simulation.design)]
return result
end

Expand Down
Loading