Skip to content

Conversation

@behinger
Copy link
Member

@behinger behinger commented Sep 20, 2024

  • added TRFComponent
  • added Tutorial for it

#
# ## Simulation
# we start with the simplest possible design, one condition
design = SingleSubjectDesign(conditions=Dict(:dummy=>["A"]));
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(:dummy=>["A"]));
design = SingleSubjectDesign(conditions = Dict(:dummy => ["A"]));

Comment on lines +15 to +17
brain_response = [LinearModelComponent(basis=p100(),formula=@formula(0~1),β=[1]),
LinearModelComponent(basis=n170(),formula=@formula(0~1),β=[1]),
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
brain_response = [LinearModelComponent(basis=p100(),formula=@formula(0~1),β=[1]),
LinearModelComponent(basis=n170(),formula=@formula(0~1),β=[1]),
LinearModelComponent(basis=p300(),formula=@formula(0~1),β=[1])];
brain_response = [
LinearModelComponent(basis = p100(), formula = @formula(0 ~ 1), β = [1]),
LinearModelComponent(basis = n170(), formula = @formula(0 ~ 1), β = [1]),
LinearModelComponent(basis = p300(), formula = @formula(0 ~ 1), β = [1]),
];

feature = rand(1_000)

# Next we have to nest the response in a `TRFComponent` and add ou
trf_component = TRFComponent(brain_response,feature);
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
trf_component = TRFComponent(brain_response,feature);
trf_component = TRFComponent(brain_response, feature);

trf_component = TRFComponent(brain_response,feature);

# Finally, when simulating, we have only a single "event" (that is, TRF-) onset, the first sample. Therefore, we use `TRFOnset` to indicate this.
dat,evts = simulate(design,trf_component,UnfoldSim.TRFOnset());
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
dat,evts = simulate(design,trf_component,UnfoldSim.TRFOnset());
dat, evts = simulate(design, trf_component, UnfoldSim.TRFOnset());

dat,evts = simulate(design,trf_component,UnfoldSim.TRFOnset());

# Let's plot the feature signal and the TRF response
f,ax,h =lines(dat)
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
f,ax,h =lines(dat)
f, ax, h = lines(dat)

Comment on lines +42 to +43
dat_l,_ = simulate(design,TRFComponent(brain_response,feature_luminance),UnfoldSim.TRFOnset());
dat_r,_ = simulate(design,TRFComponent(brain_response,feature_size),UnfoldSim.TRFOnset());
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
dat_l,_ = simulate(design,TRFComponent(brain_response,feature_luminance),UnfoldSim.TRFOnset());
dat_r,_ = simulate(design,TRFComponent(brain_response,feature_size),UnfoldSim.TRFOnset());
dat_l, _ =
simulate(design, TRFComponent(brain_response, feature_luminance), UnfoldSim.TRFOnset());
dat_r, _ =
simulate(design, TRFComponent(brain_response, feature_size), UnfoldSim.TRFOnset());

dat_r,_ = simulate(design,TRFComponent(brain_response,feature_size),UnfoldSim.TRFOnset());

# let's plot and compare to the previous plot
f,ax,h = lines(dat_l .+ dat_r)
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
f,ax,h = lines(dat_l .+ dat_r)
f, ax, h = lines(dat_l .+ dat_r)

Comment on lines +52 to +53
dat_combined,_ = simulate(design,[TRFComponent(brain_response,feature_size),TRFComponent(brain_response,feature_luminance)],UnfoldSim.TRFOnset());
f,ax,h = lines(dat_combined)
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
dat_combined,_ = simulate(design,[TRFComponent(brain_response,feature_size),TRFComponent(brain_response,feature_luminance)],UnfoldSim.TRFOnset());
f,ax,h = lines(dat_combined)
dat_combined, _ = simulate(
design,
[
TRFComponent(brain_response, feature_size),
TRFComponent(brain_response, feature_luminance),
],
UnfoldSim.TRFOnset(),
);
f, ax, h = lines(dat_combined)

# where you can see that the results are equivalent.

# ## Another cool feature is to modulate the feature vector based on the design
design_mod = SingleSubjectDesign(conditions=Dict(:condition=>["A","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
design_mod = SingleSubjectDesign(conditions=Dict(:condition=>["A","B"]));
design_mod = SingleSubjectDesign(conditions = Dict(:condition => ["A", "B"]));

design_mod = SingleSubjectDesign(conditions=Dict(:condition=>["A","B"]));

# Let's take only a single component for simplicity. Note how the `formula` has been changed. The β allows to control the amplitude. In this linear model component, the default contrast-function is `Dummy` (also known as `Reference` coding), which means, the second beta indicated a "difference"
brain_response_mod = LinearModelComponent(basis=p100(),formula=@formula(0~1+condition),β=[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
brain_response_mod = LinearModelComponent(basis=p100(),formula=@formula(0~1+condition),β=[1,1]);
brain_response_mod =
LinearModelComponent(basis = p100(), formula = @formula(0 ~ 1 + condition), β = [1, 1]);

Comment on lines +65 to +67
feature_mod = rand(1000,2)
feature_mod[:,2] .= 0
feature_mod[500:600,2] .= 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
feature_mod = rand(1000,2)
feature_mod[:,2] .= 0
feature_mod[500:600,2] .= 1;
feature_mod = rand(1000, 2)
feature_mod[:, 2] .= 0
feature_mod[500:600, 2] .= 1;

# As visible, the first column has again a random signal, indicating e.g. luminance changes. The second temporal feature indicates some offset (a colorchange?) between 500 and 600 samples.


dat_mod,_ = simulate(design_mod,TRFComponent([brain_response_mod],feature_mod),UnfoldSim.TRFOnset());
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
dat_mod,_ = simulate(design_mod,TRFComponent([brain_response_mod],feature_mod),UnfoldSim.TRFOnset());
dat_mod, _ = simulate(
design_mod,
TRFComponent([brain_response_mod], feature_mod),
UnfoldSim.TRFOnset(),
);

@behinger behinger changed the base branch from main to v4.0 November 4, 2024 10:48
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@behinger behinger requested a review from jschepers November 4, 2024 10:49
Comment on lines 156 to 158
widths =
UnfoldSim.generate_designmatrix(o.width_formula, events, o.width_contrasts) *
generate_designmatrix(o.width_formula, events, o.width_contrasts) *
o.width_β
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
widths =
UnfoldSim.generate_designmatrix(o.width_formula, events, o.width_contrasts) *
generate_designmatrix(o.width_formula, events, o.width_contrasts) *
o.width_β
widths = generate_designmatrix(o.width_formula, events, o.width_contrasts) * o.width_β

Comment on lines +160 to 161
generate_designmatrix(o.offset_formula, events, o.offset_contrasts) *
o.offset_β
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
generate_designmatrix(o.offset_formula, events, o.offset_contrasts) *
o.offset_β
generate_designmatrix(o.offset_formula, events, o.offset_contrasts) * o.offset_β

Comment on lines +218 to 219
generate_designmatrix(o.offset_formula, events, o.offset_contrasts) *
o.offset_β
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
generate_designmatrix(o.offset_formula, events, o.offset_contrasts) *
o.offset_β
generate_designmatrix(o.offset_formula, events, o.offset_contrasts) * o.offset_β

@behinger behinger marked this pull request as draft June 27, 2025 08:55
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.

2 participants