Skip to content
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

Update paper.md #30

Closed
wants to merge 128 commits into from
Closed

Update paper.md #30

wants to merge 128 commits into from

Conversation

behinger
Copy link
Member

@behinger behinger commented Nov 8, 2023

No description provided.

behinger and others added 30 commits November 6, 2023 17:45
The argument `n_trials` does not exist for the function predef_eeg (at least in the current version of UnfoldSim.jl).
All contributors should be added as a comment in a pull request or an issue.
Eg : @all-contributors please add @behinger for <contributions>

<contributions can be found in the emoji key in the Unfold.jl repo (needs to be merged)>
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
basisfunction::Any
maxlength::Any

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ax = f[1, 1] = Axis(f)
for b in [p100, n170, p300, n400]
lines!(ax, b(), label = string(b))
scatter!(ax, b(), label = string(b))

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
plotConfig = (:n => 5:3:15, :tmax => 0.5:0.2:1.1)

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
design =
SingleSubjectDesign(; conditions = Dict(:condA => ["levelA", "levelB"])) |>
x -> RepeatDesign(x, 10);

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
basis = [0, 0, 0, 0.5, 1, 1, 0.5, 0, 0],
formula = @formula(0 ~ 1 + condA),
β = [1, 0.5],
);

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
repo = Documenter.Remotes.GitHub("unfoldtoolbox", "UnfoldSim.jl"),
sitename = "UnfoldSim.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
canonical = "https://unfoldtoolbox.github.io/UnfoldSim.jl",
edit_link = "main",
assets = String[],

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
using DSP
using Random
using DataFrames
using Distributions # for LogNormal Onset
using Parameters
using StatsModels
using MixedModels
using ImageFiltering # for Noise-filter (can be replaced maybe?)
using MixedModelsSim
using SignalAnalysis
using LinearAlgebra
using ToeplitzMatrices # for AR Expo. Noise "Circulant"
using StatsModels
using HDF5, Artifacts, FileIO

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
import DSP.hanning
import Base.length
import Base.size
import Base.show
include("types.jl")
include("design.jl")
include("component.jl")
include("noise.jl")
include("simulation.jl")
include("onset.jl")
include("predefinedSimulations.jl")
include("headmodel.jl")
include("helper.jl")
include("bases.jl")

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
predef_2x2(; kwargs...) = predef_2x2(MersenneTwister(1); kwargs...) # without rng always call same one
predef_eeg(; kwargs...) = predef_eeg(MersenneTwister(1); kwargs...) # without rng always call same one
predef_eeg(nsubjects::Int; kwargs...) = predef_eeg(MersenneTwister(1), nsubjects; kwargs...) # without rng always call same one

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function predef_eeg(
rng;
# design
n_repeats = 100,
tableModifyFun = x -> shuffle(deepcopy(rng), x),
# component / signal
sfreq = 100,
p1 = (p100(; sfreq = sfreq), @formula(0 ~ 1), [5], Dict()),
n1 = (n170(; sfreq = sfreq), @formula(0 ~ 1 + condition), [5, -3], Dict()),
p3 = (p300(; sfreq = sfreq), @formula(0 ~ 1 + continuous), [5, 1], Dict()),
kwargs...,
)
design =
SingleSubjectDesign(;
conditions = Dict(
:condition => ["car", "face"],
:continuous => range(-5, 5, length = 10),
),
tableModifyFun = tableModifyFun,
) |> x -> RepeatDesign(x, n_repeats)
return predef_eeg(rng, design, LinearModelComponent, [p1, n1, p3]; sfreq, kwargs...)

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function predef_eeg(
rng::AbstractRNG,
n_subjects;
# design
n_items = 100,
tableModifyFun = x -> shuffle(deepcopy(rng), x),
conditions = Dict(
:condition => ["car", "face"],
:continuous => range(-5, 5, length = 10),
),
# component / signal
sfreq = 100,
p1 = (;
s = p100(; sfreq = sfreq),
f = @formula(0 ~ 1 + (1 | subject) + (1 | item)),
β = [5],
σs = Dict(:subject => [1], :item => [1]),
c = Dict(),
),
n1 = (;
s = n170(; sfreq = sfreq),
f = @formula(
0 ~ 1 + condition + (1 + condition | subject) + (1 + condition | item)
),
β = [5, -3],
σs = Dict(:subject => [1, 1], :item => [0.5, 0.5]),
c = Dict(),
),
p3 = (;
s = p300(; sfreq = sfreq),
f = @formula(
0 ~ 1 + continuous + (1 + continuous | subject) + (1 + continuous | item)
),
β = [5, 1],
σs = Dict(:subject => [1, 1], :item => [0.5, 0.5]),
c = Dict(),
),
kwargs...,
)

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function simulate(rng, simulation::Simulation; return_epoched::Bool = false)

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test padarray([2, 2], (-3, 2), -1) == [-1, -1, -1, 2, 2, -1, -1]
@test padarray([2, 2], -2, -1) == [-1, -1, 2, 2]
@test padarray([2, 2], 2, -1) == [2, 2, -1, -1]
@test padarray([2, 2], 2, -1) == [2, 2, -1, -1]

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

JuliaFormatter

src/component.jl|64|
src/component.jl|70|
src/component.jl|72|
src/component.jl|75|
src/component.jl|96|
src/component.jl|102|
src/component.jl|106|
src/headmodel.jl|3|
src/headmodel.jl|9|
src/headmodel.jl|13|
src/headmodel.jl|25|
src/headmodel.jl|28|
src/headmodel.jl|37|
src/headmodel.jl|43|
src/headmodel.jl|46|
src/headmodel.jl|49|
src/headmodel.jl|54|
src/headmodel.jl|61|
src/headmodel.jl|68|
src/headmodel.jl|85|
src/headmodel.jl|88|
src/headmodel.jl|101|
src/helper.jl|17|
src/helper.jl|50|
src/helper.jl|79|
src/helper.jl|81|
src/helper.jl|85|
src/predefinedSimulations.jl|79|
src/simulation.jl|3|
src/simulation.jl|6|
src/simulation.jl|14|
src/simulation.jl|21|
src/simulation.jl|25|
src/simulation.jl|32|
src/simulation.jl|41|
src/simulation.jl|48|
src/simulation.jl|54|
src/simulation.jl|66|
src/simulation.jl|68 col 1|
src/simulation.jl|69|
src/simulation.jl|71|
src/simulation.jl|79|
src/simulation.jl|82|
src/simulation.jl|85|
src/simulation.jl|94|
src/simulation.jl|106|
src/simulation.jl|110|
src/simulation.jl|118|
test/artifactheadmodel.jl|6|
test/artifactheadmodel.jl|16|
test/artifactheadmodel.jl|19|
test/artifactheadmodel.jl|25|
test/artifactheadmodel.jl|45|
test/headmodel.jl|3|
test/headmodel.jl|9|
test/headmodel.jl|15|
test/headmodel.jl|20|
test/helper.jl|13|
test/helper.jl|16|
test/helper.jl|18|
test/multichannel.jl|9|
test/multichannel.jl|15|
test/multichannel.jl|22|
test/multichannel.jl|27|
test/multichannel.jl|30|
test/multichannel.jl|32|
test/multichannel.jl|38|
test/simulation.jl|10|
test/simulation.jl|16|
test/simulation.jl|22|
test/simulation.jl|27|
test/simulation.jl|29|
test/simulation.jl|32|
test/simulation.jl|37|
test/simulation.jl|39|
test/simulation.jl|49|
test/simulation.jl|53|
test/simulation.jl|59|
test/simulation.jl|70|
test/simulation.jl|76|
test/simulation.jl|88|
test/simulation.jl|90|

# ## Specifying a design

# We are using a one-level design for testing here.
design = SingleSubjectDesign(conditions=Dict(:condA=>["levelA"]))
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
design = SingleSubjectDesign(conditions=Dict(:condA=>["levelA"]))
design = SingleSubjectDesign(conditions = Dict(:condA => ["levelA"]))

Comment on lines +15 to +16
c = LinearModelComponent(;basis=p100(),formula = @formula(0~1),β = [1]);
c2 = LinearModelComponent(;basis=p300(),formula = @formula(0~1),β = [1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
c = LinearModelComponent(;basis=p100(),formula = @formula(0~1),β = [1]);
c2 = LinearModelComponent(;basis=p300(),formula = @formula(0~1),β = [1]);
c = LinearModelComponent(; basis = p100(), formula = @formula(0 ~ 1), β = [1]);
c2 = LinearModelComponent(; basis = p300(), formula = @formula(0 ~ 1), β = [1]);


# ## The multichannel component
# next similar to the nested design above, we can nest the component in a `MultichannelComponent`. We could either provide the projection marix manually, e.g.:
mc = UnfoldSim.MultichannelComponent(c, [1,2,-1,3,5,2.3,1])
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
mc = UnfoldSim.MultichannelComponent(c, [1,2,-1,3,5,2.3,1])
mc = UnfoldSim.MultichannelComponent(c, [1, 2, -1, 3, 5, 2.3, 1])

Comment on lines +24 to +26
hart = headmodel(type="hartmut")
mc = UnfoldSim.MultichannelComponent(c, hart=>"Left Postcentral Gyrus")
mc2 = UnfoldSim.MultichannelComponent(c2, hart=>"Right Occipital Pole")
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
hart = headmodel(type="hartmut")
mc = UnfoldSim.MultichannelComponent(c, hart=>"Left Postcentral Gyrus")
mc2 = UnfoldSim.MultichannelComponent(c2, hart=>"Right Occipital Pole")
hart = headmodel(type = "hartmut")
mc = UnfoldSim.MultichannelComponent(c, hart => "Left Postcentral Gyrus")
mc2 = UnfoldSim.MultichannelComponent(c2, hart => "Right Occipital Pole")

# You could also specify a noise-specific component which is applied prior to projection & summing with other components
#
# finally we need to define the onsets of the signal
onset = UniformOnset(;width=20,offset=4);
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
onset = UniformOnset(;width=20,offset=4);
onset = UniformOnset(; width = 20, offset = 4);

Comment on lines +3 to +7
dr = filter(isdir,readdir(joinpath("src","generated"),join=true))
push!(dr,"./build")
servedocs(skip_dirs=dr,literate_dir=joinpath("literate"),foldername=".",host="0.0.0.0")


Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
dr = filter(isdir,readdir(joinpath("src","generated"),join=true))
push!(dr,"./build")
servedocs(skip_dirs=dr,literate_dir=joinpath("literate"),foldername=".",host="0.0.0.0")
dr = filter(isdir, readdir(joinpath("src", "generated"), join = true))
push!(dr, "./build")
servedocs(
skip_dirs = dr,
literate_dir = joinpath("literate"),
foldername = ".",
host = "0.0.0.0",
)


using HDF5,Artifacts,FileIO

using LinearAlgebra # headmodel
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
using LinearAlgebra # headmodel
using LinearAlgebra # headmodel

Comment on lines 66 to 67
# export bases
export p100,n170,p300,n400,hrf
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# export bases
export p100,n170,p300,n400,hrf
# noise functions
export PinkNoise, RedNoise, WhiteNoise, NoNoise, ExponentialNoise #,RealNoise (not implemented yet)

Comment on lines +69 to +70
# headmodel
export AbstractHeadmodel,Hartmut,headmodel,leadfield,orientation,magnitude
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# headmodel
export AbstractHeadmodel,Hartmut,headmodel,leadfield,orientation,magnitude
# UnfoldSim functions
export simulate, gen_noise, generate

Comment on lines +72 to +73
# multichannel
export MultichannelComponent
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# multichannel
export MultichannelComponent
# utilities
export padarray, convert
# export Offsets
export UniformOnset, LogNormalOnset
# re-export StatsModels
export DummyCoding, EffectsCoding
# export bases
export p100, n170, p300, n400, hrf
# headmodel
export AbstractHeadmodel, Hartmut, headmodel, leadfield, orientation, magnitude
# multichannel
export MultichannelComponent

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Comment on lines 49 to 53


erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...)) No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...))
\ No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
erp = UnfoldSim.simulate(
MersenneTwister(1),
TimeVaryingComponent(basis_shiftduration, 50),
design,
)
plot_erpimage(hcat(erp...), sortvalues = generate(design).shift)

"""
Wrapper for an `AbstractComponent` to project it to multiple target-channels via `projection`. optional adds `noise` to the source prior to projection.
"""
@with_kw struct MultichannelComponent <:AbstractComponent
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@with_kw struct MultichannelComponent <:AbstractComponent
@with_kw struct MultichannelComponent <: AbstractComponent

noise::AbstractNoise # optional
end

MultichannelComponent(c::AbstractComponent,p) = MultichannelComponent(c::AbstractComponent,p,NoNoise())
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
MultichannelComponent(c::AbstractComponent,p) = MultichannelComponent(c::AbstractComponent,p,NoNoise())
MultichannelComponent(c::AbstractComponent, p) =
MultichannelComponent(c::AbstractComponent, p, NoNoise())

Comment on lines +72 to +73
function MultichannelComponent(c::AbstractComponent,p::Pair{<:AbstractHeadmodel,String},n::AbstractNoise)
ix = closest_src(p[1],p[2])
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function MultichannelComponent(c::AbstractComponent,p::Pair{<:AbstractHeadmodel,String},n::AbstractNoise)
ix = closest_src(p[1],p[2])
function MultichannelComponent(
c::AbstractComponent,
p::Pair{<:AbstractHeadmodel,String},
n::AbstractNoise,
)
ix = closest_src(p[1], p[2])

function MultichannelComponent(c::AbstractComponent,p::Pair{<:AbstractHeadmodel,String},n::AbstractNoise)
ix = closest_src(p[1],p[2])
mg = magnitude(p[1])
return MultichannelComponent(c,mg[:,ix],n)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return MultichannelComponent(c,mg[:,ix],n)
return MultichannelComponent(c, mg[:, ix], n)

pos = closest_src(hartmut=>"Left Middle Temporal Gyrus, posterior division")
```
"""
function closest_src(head::Hartmut,label::String)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function closest_src(head::Hartmut,label::String)
function closest_src(head::Hartmut, label::String)

Comment on lines +81 to +83
pos = head.cortical["pos"]
ix = findall(head.cortical["label"] .== label)
@assert sum(ix)>0 """could not find label $label in hartmut.cortical["label"] - try unique(hartmut.cortical["label"]) for a list"""
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
pos = head.cortical["pos"]
ix = findall(head.cortical["label"] .== label)
@assert sum(ix)>0 """could not find label $label in hartmut.cortical["label"] - try unique(hartmut.cortical["label"]) for a list"""
pos = head.cortical["pos"]
ix = findall(head.cortical["label"] .== label)
@assert sum(ix) > 0 """could not find label $label in hartmut.cortical["label"] - try unique(hartmut.cortical["label"]) for a list"""

Comment on lines +85 to +87
ix = UnfoldSim.closest_src(mean(pos[ix,:],dims=1)[1,:],pos)
return ix
end
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ix = UnfoldSim.closest_src(mean(pos[ix,:],dims=1)[1,:],pos)
return ix
end
ix = UnfoldSim.closest_src(mean(pos[ix, :], dims = 1)[1, :], pos)
return ix
end

@@ -74,12 +79,6 @@ function predef_eeg(rng::AbstractRNG,design::AbstractDesign,T::Type{<:AbstractCo
return simulate(rng,design, components, onset, noise;kwargs...);
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return simulate(rng,design, components, onset, noise;kwargs...);
return simulate(rng, design, components, onset, noise; kwargs...)

@@ -2,70 +2,117 @@
# helper to move input ::Component to ::Vector{Component}
Simulation(design::AbstractDesign,component::AbstractComponent,onset::AbstractOnset,noisetype::AbstractNoise) = Simulation(design,[component],onset,noisetype)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Simulation(design::AbstractDesign,component::AbstractComponent,onset::AbstractOnset,noisetype::AbstractNoise) = Simulation(design,[component],onset,noisetype)
Simulation(
design::AbstractDesign,
component::AbstractComponent,
onset::AbstractOnset,
noisetype::AbstractNoise,
) = Simulation(design, [component], onset, noisetype)

Copy link
Contributor

@github-actions github-actions bot left a comment

Comment on lines 49 to 53


erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...)) No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...))
\ No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
erp = UnfoldSim.simulate(
MersenneTwister(1),
TimeVaryingComponent(basis_shiftduration, 50),
design,
)
plot_erpimage(hcat(erp...), sortvalues = generate(design).shift)

@@ -2,70 +2,117 @@
# helper to move input ::Component to ::Vector{Component}
Simulation(design::AbstractDesign,component::AbstractComponent,onset::AbstractOnset,noisetype::AbstractNoise) = Simulation(design,[component],onset,noisetype)

# by default no noise
Simulation(design::AbstractDesign,component,onset::AbstractOnset) = Simulation(design,component,onset,NoNoise())
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Simulation(design::AbstractDesign,component,onset::AbstractOnset) = Simulation(design,component,onset,NoNoise())
Simulation(design::AbstractDesign, component, onset::AbstractOnset) =
Simulation(design, component, onset, NoNoise())

"""
Simulate eeg data given a simulation design, effect sizes and variances

make use of `return_epoched=true` to skip the Onset-calculation + conversion to continuous data and get the epoched data directly
"""
simulate(rng,design, signal, onset, noise;kwargs...) = simulate(rng,Simulation(design, signal, onset, noise);kwargs...)

simulate(rng, design::AbstractDesign, signal, onset::AbstractOnset, noise::AbstractNoise=NoNoise(); kwargs...) = simulate(rng, Simulation(design, signal, onset, noise); kwargs...)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
simulate(rng, design::AbstractDesign, signal, onset::AbstractOnset, noise::AbstractNoise=NoNoise(); kwargs...) = simulate(rng, Simulation(design, signal, onset, noise); kwargs...)
simulate(
rng,
design::AbstractDesign,
signal,
onset::AbstractOnset,
noise::AbstractNoise = NoNoise();
kwargs...,
) = simulate(rng, Simulation(design, signal, onset, noise); kwargs...)

Comment on lines 21 to +23
# create epoch data / erps
erps = simulate(deepcopy(rng), components,simulation)
# @debug size(erps)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# create epoch data / erps
erps = simulate(deepcopy(rng), components,simulation)
# @debug size(erps)
# unpacking fields
(; design, components, onset, noisetype) = simulation

Comment on lines +25 to +27
n_subj = length(size(design))==1 ? 1 : size(design)[2]
n_trial = size(design)[1]
n_ch = n_channels(components)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
n_subj = length(size(design))==1 ? 1 : size(design)[2]
n_trial = size(design)[1]
n_ch = n_channels(components)
# create epoch data / erps
erps = simulate(deepcopy(rng), components, simulation)
# @debug size(erps)
n_subj = length(size(design)) == 1 ? 1 : size(design)[2]
n_trial = size(design)[1]
n_ch = n_channels(components)

@@ -0,0 +1,23 @@
hart = UnfoldSim.headmodel()
@testset "hartmut" begin
@test length(hart.electrodes["label"]) == 231-4
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test length(hart.electrodes["label"]) == 231-4
@test length(hart.electrodes["label"]) == 231 - 4

Comment on lines +9 to +10
@test isa(lf,AbstractArray)
mg = magnitude(hart,type="norm")
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test isa(lf,AbstractArray)
mg = magnitude(hart,type="norm")
@test isa(lf, AbstractArray)
mg = magnitude(hart, type = "norm")

Comment on lines +15 to +17

@test isa(lf,AbstractArray)
mg_man = magnitude(lf,or)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test isa(lf,AbstractArray)
mg_man = magnitude(lf,or)
@test isa(lf, AbstractArray)
mg_man = magnitude(lf, or)

Comment on lines +20 to +23
@test size(mg) == (231-4,2004)


end
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test size(mg) == (231-4,2004)
end
@test size(mg) == (231 - 4, 2004)
end

Comment on lines +13 to +14
@test UnfoldSim.closest_src([0,0,1],[0 0 0.5; -1 -1 -1; -3 -3 -3]) == 1
@test UnfoldSim.closest_src([[0,0,1],[-1,-1,0]],[0 0 0.5; -1 -1 -1; -3 -3 -3]) == [1,2]
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test UnfoldSim.closest_src([0,0,1],[0 0 0.5; -1 -1 -1; -3 -3 -3]) == 1
@test UnfoldSim.closest_src([[0,0,1],[-1,-1,0]],[0 0 0.5; -1 -1 -1; -3 -3 -3]) == [1,2]
@test UnfoldSim.closest_src([0, 0, 1], [0 0 0.5; -1 -1 -1; -3 -3 -3]) == 1
@test UnfoldSim.closest_src(
[[0, 0, 1], [-1, -1, 0]],
[0 0 0.5; -1 -1 -1; -3 -3 -3],
) == [1, 2]

Comment on lines 49 to 53


erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...)) No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...))
\ No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
erp = UnfoldSim.simulate(
MersenneTwister(1),
TimeVaryingComponent(basis_shiftduration, 50),
design,
)
plot_erpimage(hcat(erp...), sortvalues = generate(design).shift)

# - if `offset` > `length(signal.basis)` -> no overlap
# - if `offset` < `length(signal.basis)` -> there might be overlap, depending on the other parameters of the onset distribution


Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# [^1]: Wikipedia contributors. (2023, December 5). Log-normal distribution. In Wikipedia, The Free Encyclopedia. Retrieved 12:27, December 7, 2023, from https://en.wikipedia.org/w/index.php?title=Log-normal_distribution&oldid=1188400077#

@test UnfoldSim.closest_src([0,0,1],[0 0 0.5; -1 -1 -1; -3 -3 -3]) == 1
@test UnfoldSim.closest_src([[0,0,1],[-1,-1,0]],[0 0 0.5; -1 -1 -1; -3 -3 -3]) == [1,2]


Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

@test UnfoldSim.closest_src([[0,0,1],[-1,-1,0]],[0 0 0.5; -1 -1 -1; -3 -3 -3]) == [1,2]


end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
end
end

Comment on lines +9 to +11
design = SingleSubjectDesign(conditions=Dict(:condA=>["levelA","levelB"])) |> x->RepeatDesign(x,5);
signal = LinearModelComponent(;basis=[0,1,2,3,0],formula = @formula(0~1+condA),β = [2,5]);
onset = UniformOnset(;width=20,offset=4);
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
design = SingleSubjectDesign(conditions=Dict(:condA=>["levelA","levelB"])) |> x->RepeatDesign(x,5);
signal = LinearModelComponent(;basis=[0,1,2,3,0],formula = @formula(0~1+condA),β = [2,5]);
onset = UniformOnset(;width=20,offset=4);
design =
SingleSubjectDesign(conditions = Dict(:condA => ["levelA", "levelB"])) |>
x -> RepeatDesign(x, 5);
signal = LinearModelComponent(;
basis = [0, 1, 2, 3, 0],
formula = @formula(0 ~ 1 + condA),
β = [2, 5],
);
onset = UniformOnset(; width = 20, offset = 4);

@testset "single_subject-multiple_channels" begin

## Simulate data
data, events = simulate(MersenneTwister(42), design_single_subject, signal_linear_multichannel, onset, noise)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
data, events = simulate(MersenneTwister(42), design_single_subject, signal_linear_multichannel, onset, noise)
data, events = simulate(
MersenneTwister(42),
design_single_subject,
signal_linear_multichannel,
onset,
noise,
)


# channels x eeg
@test size(data) == (n_channels_exp, eeg_length_exp)

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

@testset "multiple_subjects-single_channel" begin

## Simulate data
data, events = simulate(MersenneTwister(42), design_multiple_subjects, signal_mixed, onset, noise)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
data, events = simulate(MersenneTwister(42), design_multiple_subjects, signal_mixed, onset, noise)
data, events = simulate(
MersenneTwister(42),
design_multiple_subjects,
signal_mixed,
onset,
noise,
)

end

@testset "multiple_subjects-multiple_channels" begin

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

@testset "multiple_subjects-multiple_channels" begin

## Simulate data
data, events = simulate(MersenneTwister(42), design_multiple_subjects, signal_mixed_multichannel, onset, noise)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
data, events = simulate(MersenneTwister(42), design_multiple_subjects, signal_mixed_multichannel, onset, noise)
data, events = simulate(
MersenneTwister(42),
design_multiple_subjects,
signal_mixed_multichannel,
onset,
noise,
)

Comment on lines 49 to 53


erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...)) No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...))
\ No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
erp = UnfoldSim.simulate(
MersenneTwister(1),
TimeVaryingComponent(basis_shiftduration, 50),
design,
)
plot_erpimage(hcat(erp...), sortvalues = generate(design).shift)

Comment on lines 49 to 53


erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...)) No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
erp = UnfoldSim.simulate(MersenneTwister(1),TimeVaryingComponent(basis_shiftduration,50),design)
heatmap(hcat(erp...))
\ No newline at end of file
plot_erpimage(hcat(erp...),sortvalues=generate(design).shift)
erp = UnfoldSim.simulate(
MersenneTwister(1),
TimeVaryingComponent(basis_shiftduration, 50),
design,
)
plot_erpimage(hcat(erp...), sortvalues = generate(design).shift)

@behinger behinger closed this Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants