From e01cfceae1855431306f00c7363fd874f678d809 Mon Sep 17 00:00:00 2001 From: ReneSkukies Date: Thu, 16 Oct 2025 17:23:57 +0200 Subject: [PATCH 1/4] beginning of clean up --- dev/runner.jl | 8 ++++---- src/ride/ride_classic_algorithm.jl | 4 ++-- src/ride/ride_unfold_algorithm.jl | 2 +- src/ride/ride_unfold_methods.jl | 2 +- test/simulate_test_data.jl | 4 +++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/dev/runner.jl b/dev/runner.jl index 062c08d..6691669 100644 --- a/dev/runner.jl +++ b/dev/runner.jl @@ -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 @@ -47,7 +47,7 @@ begin save_interim_results = true, ) - save_to_hdf5_ride_format( + #=save_to_hdf5_ride_format( "./dev/data/simulated_data.h5", data, evts, @@ -55,7 +55,7 @@ begin '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') @@ -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 diff --git a/src/ride/ride_classic_algorithm.jl b/src/ride/ride_classic_algorithm.jl index 34e6cc4..c335253 100644 --- a/src/ride/ride_classic_algorithm.jl +++ b/src/ride/ride_classic_algorithm.jl @@ -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}() @@ -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( diff --git a/src/ride/ride_unfold_algorithm.jl b/src/ride/ride_unfold_algorithm.jl index bc6d032..3386784 100644 --- a/src/ride/ride_unfold_algorithm.jl +++ b/src/ride/ride_unfold_algorithm.jl @@ -44,7 +44,7 @@ function ride_algorithm( m = fit( UnfoldModel, [ - 'S' => (@formula(0 ~ 1), firbasis(cfg.s_range, cfg.sfreq, "")), + 'S' => (@formula(0 ~ 1), firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict 'R' => (@formula(0 ~ 1), firbasis(cfg.r_range, cfg.sfreq, "")), ], evts, diff --git a/src/ride/ride_unfold_methods.jl b/src/ride/ride_unfold_methods.jl index 981633a..b6a3c5d 100644 --- a/src/ride/ride_unfold_methods.jl +++ b/src/ride/ride_unfold_methods.jl @@ -26,7 +26,7 @@ function unfold_decomposition(data, evts_with_c, cfg) m = fit( UnfoldModel, [ - 'S' => (@formula(0 ~ 1), firbasis(cfg.s_range, cfg.sfreq, "")), + 'S' => (@formula(0 ~ 1), firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict 'R' => (@formula(0 ~ 1), firbasis(cfg.r_range, cfg.sfreq, "")), 'C' => ( @formula(0 ~ 1), diff --git a/test/simulate_test_data.jl b/test/simulate_test_data.jl index 490d23a..ada5054 100644 --- a/test/simulate_test_data.jl +++ b/test/simulate_test_data.jl @@ -30,6 +30,7 @@ end components_onset::Vector{AbstractOnset} end + function UnfoldSim.simulate_onsets(rng, onset::SequenceOnset, simulation::Simulation) #calculate stimulus onsets stimulus_onsets = @@ -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 From fb615e9aff222d3acef9dde55333e11850712868 Mon Sep 17 00:00:00 2001 From: ReneSkukies Date: Tue, 21 Oct 2025 11:33:51 +0200 Subject: [PATCH 2/4] add functionality to provide own formula for UnfoldRIDE --- dev/Project.toml | 1 + src/ride/ride_structs.jl | 4 ++++ src/ride/ride_unfold_algorithm.jl | 4 ++-- src/ride/ride_unfold_methods.jl | 6 +++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dev/Project.toml b/dev/Project.toml index 053d298..fddda1b 100644 --- a/dev/Project.toml +++ b/dev/Project.toml @@ -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" diff --git a/src/ride/ride_structs.jl b/src/ride/ride_structs.jl index fd63035..c3ff751 100644 --- a/src/ride/ride_structs.jl +++ b/src/ride/ride_structs.jl @@ -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. @@ -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 epoch_range = [-0.3, 1.6], iteration_limit = 5, heuristic1 = true, @@ -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 diff --git a/src/ride/ride_unfold_algorithm.jl b/src/ride/ride_unfold_algorithm.jl index 3386784..391f27f 100644 --- a/src/ride/ride_unfold_algorithm.jl +++ b/src/ride/ride_unfold_algorithm.jl @@ -44,8 +44,8 @@ function ride_algorithm( m = fit( UnfoldModel, [ - 'S' => (@formula(0 ~ 1), firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict - 'R' => (@formula(0 ~ 1), firbasis(cfg.r_range, cfg.sfreq, "")), + 'S' => (cgf.formulas[1], firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict + 'R' => (cgf.formulas[2], firbasis(cfg.r_range, cfg.sfreq, "")), ], evts, data, diff --git a/src/ride/ride_unfold_methods.jl b/src/ride/ride_unfold_methods.jl index b6a3c5d..8469c8a 100644 --- a/src/ride/ride_unfold_methods.jl +++ b/src/ride/ride_unfold_methods.jl @@ -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, "")), # TODO: Let user supply bfdict - 'R' => (@formula(0 ~ 1), firbasis(cfg.r_range, cfg.sfreq, "")), + 'S' => (cgf.formulas[1], firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict + 'R' => (cgf.formulas[2], firbasis(cfg.r_range, cfg.sfreq, "")), 'C' => ( - @formula(0 ~ 1), + cgf.formulas[3], firbasis(c_range_adjusted(cfg.c_range), cfg.sfreq, ""), ), ], From b1d4063249290550f6490e2db0bc33f7ef39fbc6 Mon Sep 17 00:00:00 2001 From: ReneSkukies Date: Thu, 23 Oct 2025 12:07:31 +0200 Subject: [PATCH 3/4] fix typos, add formula to docs and readme --- README.md | 1 + docs/src/11-running_ride.md | 1 + src/ride/ride_unfold_algorithm.jl | 4 ++-- src/ride/ride_unfold_methods.jl | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9e27979..212225c 100644 --- a/README.md +++ b/README.md @@ -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] diff --git a/docs/src/11-running_ride.md b/docs/src/11-running_ride.md index ddb31b3..ddd87b7 100644 --- a/docs/src/11-running_ride.md +++ b/docs/src/11-running_ride.md @@ -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] diff --git a/src/ride/ride_unfold_algorithm.jl b/src/ride/ride_unfold_algorithm.jl index 391f27f..90e28a0 100644 --- a/src/ride/ride_unfold_algorithm.jl +++ b/src/ride/ride_unfold_algorithm.jl @@ -44,8 +44,8 @@ function ride_algorithm( m = fit( UnfoldModel, [ - 'S' => (cgf.formulas[1], firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict - 'R' => (cgf.formulas[2], 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, diff --git a/src/ride/ride_unfold_methods.jl b/src/ride/ride_unfold_methods.jl index 8469c8a..b96d9db 100644 --- a/src/ride/ride_unfold_methods.jl +++ b/src/ride/ride_unfold_methods.jl @@ -26,10 +26,10 @@ function unfold_decomposition(data, evts_with_c, cfg) m = fit( UnfoldModel, [ - 'S' => (cgf.formulas[1], firbasis(cfg.s_range, cfg.sfreq, "")), # TODO: Let user supply bfdict - 'R' => (cgf.formulas[2], 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' => ( - cgf.formulas[3], + cfg.formulas[3], firbasis(c_range_adjusted(cfg.c_range), cfg.sfreq, ""), ), ], From b2a3b9e0fcbebbdf4365724020db8412b9ae5236 Mon Sep 17 00:00:00 2001 From: ReneSkukies Date: Thu, 23 Oct 2025 13:37:55 +0200 Subject: [PATCH 4/4] add compats --- Project.toml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ecd7cba..c0a5bd0 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -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"