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

Address joss paper comments #103

Merged
merged 120 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
b0b4b84
Formatting
jschepers Jan 9, 2024
0cf94ad
Formatting
jschepers Jan 10, 2024
e24e958
adapted Unfold epoch function for Unfoldsim
jschepers Jan 10, 2024
2674d4e
adapted simulate function
jschepers Jan 10, 2024
529877b
added new tests for the dimensions of the simulate output
jschepers Jan 10, 2024
f4c20e6
Formatting
jschepers Jan 9, 2024
79992ac
Formatting
jschepers Jan 10, 2024
d5788da
adapted Unfold epoch function for Unfoldsim
jschepers Jan 10, 2024
2d1f07c
adapted simulate function
jschepers Jan 10, 2024
bdc0f5d
added new tests for the dimensions of the simulate output
jschepers Jan 10, 2024
05c5e10
Merge branch 'adapt-simulate-output' of github.com:unfoldtoolbox/Unfo…
jschepers Jan 10, 2024
6ee6ce1
Apply suggestions from code review (JuliaFormatter)
jschepers Jan 10, 2024
663c7bc
Apply suggestions from code review (JuliaFormatter)
jschepers Jan 10, 2024
14e9143
Apply suggestions from code review (JuliaFormatter)
jschepers Jan 10, 2024
a5d2e66
Apply suggestions from code review (JuliaFormatter)
jschepers Jan 10, 2024
4b0fd2b
Apply suggestions from code review
jschepers Jan 10, 2024
d5d48f3
Apply suggestions from code review (JuliaFormatter)
jschepers Jan 10, 2024
490c7e6
Apply suggestions from code review (JuliaFormatter)
jschepers Jan 10, 2024
7e65e7e
Apply suggestions from code review
jschepers Jan 10, 2024
d396dea
Apply suggestions from code review
jschepers Jan 10, 2024
aa1a470
Apply suggestions from code review
jschepers Jan 10, 2024
e2341fb
Apply suggestions from code review
jschepers Jan 10, 2024
6539abf
Apply suggestions from code review (JuliaFormatter)
jschepers Jan 10, 2024
92cb0b6
Apply suggestions from code review
jschepers Jan 10, 2024
350bd06
Apply suggestions from code review
jschepers Jan 10, 2024
b70d1fd
Apply suggestions from code review
jschepers Jan 10, 2024
4938c0f
Apply suggestions from code review
jschepers Jan 10, 2024
54999a9
test manual formatting with JuliaFormatter
jschepers Jan 11, 2024
5ec880f
added new HowTo
behinger Jan 16, 2024
f31a481
merge
behinger Jan 18, 2024
8880ec5
added using Random
behinger Jan 18, 2024
e00d05a
Update design.jl
behinger Jan 23, 2024
7cfb6a9
adapted generate function for MultiSubjectDesigns without conditions …
jschepers Jan 22, 2024
83821b6
remove commented code
jschepers Jan 22, 2024
d3cab54
Added more tests for simulated data with a multi-subject design witho…
jschepers Jan 25, 2024
42bb943
Merge pull request #68 from unfoldtoolbox/single-subject-nothing
behinger Feb 2, 2024
78d1e78
Merge pull request #66 from unfoldtoolbox/ManualOnsetDesign
behinger Feb 2, 2024
e792c50
simulate docstring
behinger Feb 5, 2024
f114405
v0.2.0
behinger Feb 5, 2024
8e063c1
rename tableModifyFun to event_order_function
behinger Feb 6, 2024
8969c06
renaming (#73)
behinger Feb 7, 2024
23976cf
docs: update README.md
allcontributors[bot] Feb 7, 2024
5cd3300
docs: update .all-contributorsrc
allcontributors[bot] Feb 7, 2024
4af682f
v0.3.0
jschepers Feb 8, 2024
1f773b1
added axes labels to the noise type plots
jschepers Feb 9, 2024
5c9a1a0
adapted variable range + added axes labels
jschepers Feb 9, 2024
c6b3704
trying to fix predefined onsets howto
jschepers Feb 9, 2024
b790f41
removed outdated information
jschepers Feb 9, 2024
d0d1b89
deleted paper.md in root directory
jschepers Feb 9, 2024
4516f80
updated link
jschepers Feb 9, 2024
42509a2
added test_broken for MixedModelsSim bug
jschepers Feb 9, 2024
3142fda
replace image
jschepers Feb 9, 2024
3c256e9
fix image
jschepers Feb 9, 2024
347d7ab
adapt README image
jschepers Feb 12, 2024
17f3fe8
JuliaFormatter: Apply suggestions from code review
jschepers Feb 12, 2024
0913018
Adapted SimulateERP tutorial and updated README
jschepers Feb 16, 2024
83ec6aa
adapted tests for design since MixedModelsSim bug has been fixed
jschepers Feb 16, 2024
9521959
Update LICENSE
jschepers Feb 19, 2024
e075667
Update LICENSE
jschepers Feb 19, 2024
4b898fe
improved and added docstrings
behinger Feb 16, 2024
9c08544
Update src/component.jl
behinger Feb 19, 2024
4f44dce
Apply suggestions from code review
behinger Feb 19, 2024
0489ec5
Update component.jl
behinger Feb 19, 2024
36089b3
Update noise.jl
behinger Feb 19, 2024
70e49f5
Update bases.jl
behinger Feb 19, 2024
abc9f17
Update component.jl
behinger Feb 19, 2024
162f6d8
Update predefinedSimulations.jl
behinger Feb 19, 2024
5b65d98
v0.3.1
jschepers Feb 19, 2024
5128e3f
Set minimum for first onset to 1 (not 0)
jschepers Feb 26, 2024
5af1d2d
Update test/onset.jl
jschepers Feb 26, 2024
0dff173
formatted nicer, #77
behinger Feb 26, 2024
3d10aed
removed unused file
behinger Feb 26, 2024
5d34f6e
fix methods error, fix #6 hard to parse error
behinger Feb 26, 2024
6cc1fd5
fix italic-issue in docstring
behinger Feb 26, 2024
8f57729
add possibility to call simulation without specifying random generator
behinger Feb 26, 2024
a28ed81
add multisubject to index
behinger Feb 26, 2024
37b46c8
wadded warning for extreme inter-onset-distances
behinger Feb 26, 2024
32d14be
better docstring + enforce Dict{Symbol}
behinger Feb 26, 2024
35fb5c8
enforce docstring
behinger Feb 26, 2024
7de7e97
remove creation for Simulation object in tutorial
behinger Feb 26, 2024
6527837
added return_parameter flag
behinger Feb 26, 2024
7a24e59
small reaming
behinger Feb 26, 2024
f33d7d3
Update multisubject.jl
behinger Feb 26, 2024
ef09c34
Update multisubject.jl
behinger Feb 26, 2024
93cde2a
Apply suggestions from code review
behinger Feb 26, 2024
f29f579
remove old comment
behinger Feb 26, 2024
d8672d5
Update multisubject.jl
behinger Feb 26, 2024
ef4d921
Update multisubject.jl
behinger Feb 26, 2024
1bab9dd
Update docs/literate/tutorials/multisubject.jl
behinger Feb 27, 2024
75e86a1
v0.3.2
behinger Feb 27, 2024
3546e29
update to new unfoldmakie
behinger Mar 1, 2024
d2a3c8a
first test of artefacts simulation
behinger Apr 15, 2024
6fbbc69
fix #92
behinger May 1, 2024
88f3e59
Create CONTRIBUTING.md
jschepers Jun 18, 2024
60bd9f9
adapt contributions and contributors sections of the readme
jschepers Jun 18, 2024
fb05406
removed NoNoise from the noise comparison plot
jschepers Jul 31, 2024
3e697ff
(auto) add joss paper plots
jschepers Jul 31, 2024
b6a9d88
Start addressing JOSS review comments
jschepers Jul 31, 2024
1351bee
Merge branch 'address-joss-paper-comments' of github.com:unfoldtoolbo…
jschepers Jul 31, 2024
455c048
Merge branch 'main' into address-joss-paper-comments
jschepers Aug 1, 2024
d581cee
Revise paper e.g. adapt figure captions#
jschepers Aug 1, 2024
e17ed15
Try to fix subscript
jschepers Aug 1, 2024
c603dca
Try to fix subscript
jschepers Aug 1, 2024
0d8dd62
Try to fix subscript
jschepers Aug 1, 2024
1ee776d
Try to fix subscript
jschepers Aug 1, 2024
8081775
Try to fix subscript
jschepers Aug 1, 2024
a6c049e
Adapt noise figure and caption
jschepers Aug 5, 2024
d8dcb9d
(auto) add joss paper plots
jschepers Aug 5, 2024
ae032b5
adapted figure size
jschepers Aug 5, 2024
4457b2e
Merge branch 'address-joss-paper-comments' of github.com:unfoldtoolbo…
jschepers Aug 5, 2024
c966897
adapted figure size
jschepers Aug 5, 2024
783be2f
adapted figure size
jschepers Aug 5, 2024
bc57c9b
adapted figure size
jschepers Aug 5, 2024
9bf8d6b
adapted figure size
jschepers Aug 5, 2024
ff86cda
adapted figure size
jschepers Aug 5, 2024
1f80832
adapted figure size
jschepers Aug 5, 2024
e96ef9c
adapted figure size
jschepers Aug 5, 2024
c46f58f
adapted figure size
jschepers Aug 5, 2024
74985f1
adapted figure size
jschepers Aug 5, 2024
075c086
adapt date
jschepers Aug 5, 2024
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
3 changes: 2 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"bug",
"doc",
"tutorial",
"code"
"code",
"test"
]
},
{
Expand Down
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Contribution guide
Contributions are very welcome. These could be typos, bug reports, feature requests, speed optimization, better code, and better documentation.
You are very welcome to raise issues and start pull requests.

## Bug reports
If you notice any bugs, such as crashing code, incorrect results or speed issues, please raise a GitHub issue. The issue should contain a short description of the problem, (optimally) a minimal working example to reproduce the bug and which UnfoldSim.jl version you are using.

## Code contributions (Pull requests)
When opening a pull request, please add a short but meaningful description of the changes/features you implemented. Moreover, please add tests (where appropriate) to ensure that your code is working as expected.

## Adding documentation
1. We recommend to write a Literate.jl document and place it in `docs/literate/FOLDER/FILENAME.jl` with `FOLDER` being `HowTo`, `Explanation`, `Tutorial` or `Reference` ([recommended reading on the 4 categories](https://documentation.divio.com/)).
2. Literate.jl converts the `.jl` file to a `.md` automatically and places it in `docs/src/generated/FOLDER/FILENAME.md`.
3. Edit [make.jl](https://github.com/unfoldtoolbox/Unfold.jl/blob/main/docs/make.jl) with a reference to `docs/src/generated/FOLDER/FILENAME.md`.

## Formatting (Beware of reviewdog :dog:)
We use the [julia-format](https://github.com/julia-actions/julia-format) Github action to ensure that the code follows the formatting rules defined by [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl).
When opening a pull request [reviewdog](https://github.com/reviewdog/reviewdog) will automatically make formatting suggestions for your code.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Luis Lips, Benedikt Ehinger, Judith Schepers
Copyright (c) 2022-2024: Benedikt Ehinger, Judith Schepers, Luis Lips, Maanik Marathe and other contributors: https://github.com/unfoldtoolbox/UnfoldSim.jl?tab=readme-ov-file#contributors.


Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UnfoldSim"
uuid = "ed8ae6d2-84d3-44c6-ab46-0baf21700804"
authors = ["Benedikt Ehinger", "Luis Lips", "Judith Schepers", "Maanik Marathe"]
version = "0.1.7"
version = "0.3.2"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand Down
64 changes: 31 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
A Julia package to simulate multivariate time series, e.g. model-based ERPs, fMRI activity, pupil dilation etc.
UnfoldSim.jl provides multi-channel support via EEG-forward models. Moreover, it is possible to simulate overlapping event-related activity and to add noise of a certain type e.g. Pink noise.

Many Tutorials, Guides, How-Tos and References available in the [documentation](https://unfoldtoolbox.github.io/UnfoldSim.jl/dev/)!
Many tutorials, guides, how-tos and references are available in the [documentation](https://unfoldtoolbox.github.io/UnfoldSim.jl/dev/)!

![grafik](https://user-images.githubusercontent.com/10183650/213565922-90feec23-3b51-4602-b50c-31561dbfc261.png)
![readme_figure](https://github.com/unfoldtoolbox/UnfoldSim.jl/assets/22366977/b69d186c-fd3d-4449-9f2e-03d7e01b8cb3)

## Install

Expand All @@ -41,46 +41,45 @@ AppStore -> JuliaUp, or `winget install julia -s msstore` in CMD

```julia
using Pkg
Pkg.add("https://github.com/unfoldtoolbox/UnfoldSim.jl/tree/main")
Pkg.add("UnfoldSim")
```

Once the toolbox is registered this will translate to ```Pkg.add("UnfoldSim")```


# Quickstart
```julia
data,evts = UnfoldSim.predef_eeg(;n_repeats=1,noiselevel=0.8)
using UnfoldSim
data, events = UnfoldSim.predef_eeg(; n_repeats = 1, noiselevel = 0.8)
```
Produces continuous "EEG" with PinkNoise and some Overlap between 20 events (2 conditions * 10 levels of continuous variable).
Produces continuous "EEG" with PinkNoise and some overlap between 20 events (2 conditions * 10 levels of the continuous variable).

## Slightly longer
```julia
# start by defining the design / event-table
design = SingleSubjectDesign(;conditions=Dict(:condA=>["levelA","levelB"])) |> d->RepeatDesign(d,10);
# next define a ground-truth signal + relation to events/design with Wilkinson Formulas
using UnfoldSim
using Random

# Start by defining the design / events data frame
design =
SingleSubjectDesign(; conditions = Dict(:condA => ["levelA", "levelB"])) |>
d -> RepeatDesign(d, 10);

# Next define a ground truth signal + relation to events/design with Wilkinson formulas
signal = LinearModelComponent(;
basis=[0,0,0,0.5,1,1,0.5,0,0],
formula = @formula(0~1+condA),
β = [1,0.5]
);
# finally, define some Onset Distribution and Noise, and simulate!
data,events = simulate(Random.MersenneTwister(1),design, signal, UniformOnset(;offset=5,width=4), PinkNoise());
basis = [0, 0, 0, 0.5, 1, 1, 0.5, 0, 0],
formula = @formula(0 ~ 1 + condA),
β = [1, 0.5],
);
# finally, define some inter-onset distribution and noise, and simulate data!
data, events = simulate(
Random.MersenneTwister(1),
design,
signal,
UniformOnset(; offset = 5, width = 4),
PinkNoise(),
);
```
All components (design, components, onsets, noise) can be easily modified and you can simply plugin your own!

## Contributions

Contributions are very welcome. These could be typos, bugreports, feature-requests, speed-optimization, new solvers, better code, better documentation.

### How-to Contribute

You are very welcome to raise issues and start pull requests!

### Adding Documentation

1. We recommend to write a Literate.jl document and place it in `docs/literate/FOLDER/FILENAME.jl` with `FOLDER` being `HowTo`, `Explanation`, `Tutorial` or `Reference` ([recommended reading on the 4 categories](https://documentation.divio.com/)).
2. Literate.jl converts the `.jl` file to a `.md` automatically and places it in `docs/src/generated/FOLDER/FILENAME.md`.
3. Edit [make.jl](https://github.com/unfoldtoolbox/Unfold.jl/blob/main/docs/make.jl) with a reference to `docs/src/generated/FOLDER/FILENAME.md`.
Contributions of any kind are very welcome. Please have a look at [CONTRIBUTING.md](https://github.com/unfoldtoolbox/UnfoldSim.jl/blob/main/CONTRIBUTING.md) for guidance on contributing to UnfoldSim.jl.

## Contributors
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
Expand All @@ -92,7 +91,7 @@ You are very welcome to raise issues and start pull requests!
<td align="center" valign="top" width="14.28%"><a href="https://github.com/maanikmarathe"><img src="https://avatars.githubusercontent.com/u/66105649?v=4?s=100" width="100px;" alt="Maanik Marathe"/><br /><sub><b>Maanik Marathe</b></sub></a><br /><a href="#doc-maanikmarathe" title="Documentation">📖</a> <a href="#code-maanikmarathe" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://www.benediktehinger.de"><img src="https://avatars.githubusercontent.com/u/10183650?v=4?s=100" width="100px;" alt="Benedikt Ehinger"/><br /><sub><b>Benedikt Ehinger</b></sub></a><br /><a href="#bug-behinger" title="Bug reports">🐛</a> <a href="#code-behinger" title="Code">💻</a> <a href="#doc-behinger" title="Documentation">📖</a> <a href="#ideas-behinger" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-behinger" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-behinger" title="Maintenance">🚧</a> <a href="#review-behinger" title="Reviewed Pull Requests">👀</a> <a href="#test-behinger" title="Tests">⚠️</a> <a href="#tutorial-behinger" title="Tutorials">✅</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/llips"><img src="https://avatars.githubusercontent.com/u/38983684?v=4?s=100" width="100px;" alt="Luis"/><br /><sub><b>Luis</b></sub></a><br /><a href="#bug-llips" title="Bug reports">🐛</a> <a href="#code-llips" title="Code">💻</a> <a href="#doc-llips" title="Documentation">📖</a> <a href="#ideas-llips" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jschepers"><img src="https://avatars.githubusercontent.com/u/22366977?v=4?s=100" width="100px;" alt="Judith Schepers"/><br /><sub><b>Judith Schepers</b></sub></a><br /><a href="#ideas-jschepers" title="Ideas, Planning, & Feedback">🤔</a> <a href="#bug-jschepers" title="Bug reports">🐛</a> <a href="#doc-jschepers" title="Documentation">📖</a> <a href="#tutorial-jschepers" title="Tutorials">✅</a> <a href="#code-jschepers" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jschepers"><img src="https://avatars.githubusercontent.com/u/22366977?v=4?s=100" width="100px;" alt="Judith Schepers"/><br /><sub><b>Judith Schepers</b></sub></a><br /><a href="#ideas-jschepers" title="Ideas, Planning, & Feedback">🤔</a> <a href="#bug-jschepers" title="Bug reports">🐛</a> <a href="#doc-jschepers" title="Documentation">📖</a> <a href="#tutorial-jschepers" title="Tutorials">✅</a> <a href="#code-jschepers" title="Code">💻</a> <a href="#test-jschepers" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vladdez"><img src="https://avatars.githubusercontent.com/u/33777074?v=4?s=100" width="100px;" alt="Vladimir Mikheev"/><br /><sub><b>Vladimir Mikheev</b></sub></a><br /><a href="#bug-vladdez" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://reboreexplore.github.io/"><img src="https://avatars.githubusercontent.com/u/43548330?v=4?s=100" width="100px;" alt="Manpa Barman"/><br /><sub><b>Manpa Barman</b></sub></a><br /><a href="#infra-ReboreExplore" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://reneskukies.de/"><img src="https://avatars.githubusercontent.com/u/57703446?v=4?s=100" width="100px;" alt="René Skukies"/><br /><sub><b>René Skukies</b></sub></a><br /><a href="#doc-ReneSkukies" title="Documentation">📖</a></td>
Expand All @@ -108,13 +107,12 @@ You are very welcome to raise issues and start pull requests!


This project follows the [all-contributors](https://allcontributors.org/docs/en/specification) specification.

Contributions of any kind welcome!
Please reach out, if you have contributed to UnfoldSim.jl but we have not listed you as a contributor yet.

## Citation

TBA

## Acknowledgements

Funded by Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Germany´s Excellence Strategy – EXC 2075 – 390740016
Funded by Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Germany´s Excellence Strategy – EXC 2075 – 390740016. Furthermore, the authors thank the International Max Planck Research School for Intelligent Systems (IMPRS-IS) for supporting Judith Schepers.
10 changes: 5 additions & 5 deletions docs/literate/HowTo/newComponent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ Base.length(c::TimeVaryingComponent) = length(c.maxlength)

# While we could have put the TimeVaryingComponent.basisfunction directly into the simulate function, I thought this is a bit more modular
function UnfoldSim.simulate(rng, c::TimeVaryingComponent, design::AbstractDesign)
evts = generate(design)
evts = generate_events(design)
return c.basisfunction(evts, c.maxlength)
end

# finally, the actual function that does the shifting + duration
function basis_shiftduration(evts, maxlength)
basis = hanning.(Int.(round.(evts.duration))) ## hanning as long as duration
if "shift" ∈ names(evts)
basis = padarray.(basis, Int.(round.(.-evts.shift)), 0) ## shift by adding 0 in front
basis = pad_array.(basis, Int.(round.(.-evts.shift)), 0) ## shift by adding 0 in front
end
## we should make sure that all bases have maxlength by appending / truncating
difftomax = maxlength .- length.(basis)
if any(difftomax .< 0)
@warn "basis longer than max length in at least one case. either increase maxlength or redefine function. Trying to truncate the basis"
basis[difftomax.>0] = padarray.(basis[difftomax.>0], difftomax[difftomax.>0], 0)
basis[difftomax.>0] = pad_array.(basis[difftomax.>0], difftomax[difftomax.>0], 0)
return [b[1:maxlength] for b in basis]
else
return padarray.(basis, difftomax, 0)
return pad_array.(basis, difftomax, 0)
end
end

Expand All @@ -57,4 +57,4 @@ erp = UnfoldSim.simulate(
TimeVaryingComponent(basis_shiftduration, 50),
design,
)
plot_erpimage(hcat(erp...), sortvalues = generate(design).shift)
plot_erpimage(hcat(erp...), sortvalues = generate_events(design).shift)
6 changes: 3 additions & 3 deletions docs/literate/HowTo/newDesign.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ end;
size(design::ImbalanceSubjectDesign) = (design.nTrials,);

# #### 3) `generate`
# We need a type `generate(design::ImbalanceSubjectDesign)` function. This function should return the actual table as a `DataFrame`
function generate(design::ImbalanceSubjectDesign)
# We need a type `generate_events(design::ImbalanceSubjectDesign)` function. This function should return the actual table as a `DataFrame`
function generate_events(design::ImbalanceSubjectDesign)
nA = Int(round.(design.nTrials .* design.balance))
nB = Int(round.(design.nTrials .* (1 - design.balance)))
@assert nA + nB ≈ design.nTrials
Expand All @@ -35,7 +35,7 @@ end;

# Finally, we can test the function and see whether it returns a Design-DataFrame as we requested
design = ImbalanceSubjectDesign(; nTrials = 6, balance = 0.2)
generate(design)
generate_events(design)

# !!! warning "Important"
# It is the users task to ensure that each run is reproducible. So if you have a random process (e.g. shuffling), be sure to
Expand Down
53 changes: 53 additions & 0 deletions docs/literate/HowTo/predefinedData.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# # Use existing experimental designs & onsets in the simulation

# Let's say you want to use the events data frame (containing the levels of the experimental variables and the event onsets (latencies)) from a previous study in your simulation.

using UnfoldSim
using DataFrames
using Random
using CairoMakie # for plotting

# From a previous study, we (somehow, e.g. by using [pyMNE.jl](https://unfoldtoolbox.github.io/Unfold.jl/dev/HowTo/pymne/)) imported an event data frame like this:
my_events = DataFrame(:condition => [:A, :B, :B, :A, :A], :latency => [7, 13, 22, 35, 41])

# To use exactly these values, we can generate a new `AbstractDesign`, which will always return this event dataframe
struct MyManualDesign <: AbstractDesign
my_events::Any
end
UnfoldSim.generate_events(d::MyManualDesign) = deepcopy(d.my_events) ## generate function which is called internally in UnfoldSim
UnfoldSim.size(d::MyManualDesign) = size(d.my_events, 1); ## necessary function to tell what the dimensionality of the experimental design is
# !!! note
# Note the `UnfoldSim.generate_events` which tells Julia to "overload" the `generate_events` function as defined in UnfoldSim.


# Next we generate a `MyManualDesign`
mydesign = MyManualDesign(my_events);

# We could already use this "solo" and simulate some data, for example:
signal = LinearModelComponent(;
basis = [1, 1, 0.5, 0, 0],
formula = @formula(0 ~ 1 + condition),
β = [1, 0.5],
);

data, events =
simulate(MersenneTwister(1), mydesign, signal, UniformOnset(; width = 10, offset = 5))
lines(data) # plotting
vlines!(my_events.latency; linestyle = :dash)
current_figure()
# Looks good, but the events don't match our custom onsets yet.

# ## Custom Timings
# Finally, we want to use our custom timings as well. For this we define a new `AbstractOnset`. Again, it simply returns our manually provided latencies
struct MyManualOnset <: AbstractOnset end
UnfoldSim.simulate_onsets(rng, onset::MyManualOnset, simulation::Simulation) =
generate_events(simulation.design).latency
# !!! hint
# This is a bit of a trick, it relies that `MyManualOnset` is always used in combination with `MyManualDesign`. You could of course repeat the structure from `MyManualDesign` also for `MyManualOnset` and have an explicit field in the structure containing the onsets.

# And that's it
data, events = simulate(MersenneTwister(1), mydesign, signal, MyManualOnset())
lines(data) # plotting
vlines!(my_events.latency, linestyle = :dash)
current_figure()
# now everything matches, lovely!
2 changes: 1 addition & 1 deletion docs/literate/HowTo/repeatTrials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ designOnce = MultiSubjectDesign(;
);

design = RepeatDesign(designOnce, 4);
generate(design)
generate_events(design)

# As you can see, the design was simply repeated.

Expand Down
4 changes: 2 additions & 2 deletions docs/literate/reference/basistypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ f
f = Figure()
plotConfig = (
:peak => 1:3:10,
:psUnder => 10:5:30,
:post_undershoot => 10:5:30,
:amplitude => 2:5,
:shift => 0:3:10,
:peak_width => 0.1:0.5:1.5,
:psUnder_width => 0.1:0.5:1.5,
:post_undershoot_width => 0.1:0.5:1.5,
)

for (ix, pl) in enumerate(plotConfig)
Expand Down
24 changes: 19 additions & 5 deletions docs/literate/reference/noisetypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ import StatsBase.autocor
# There are several noise-types directly implemented. Here is a comparison:

f = Figure()
ax_sig = f[1, 1:2] = Axis(f; title = "1.000 samples of noise")
ax_spec = f[2, 1] = Axis(f; title = "Welch Periodigram")
ax_auto = f[2, 2] = Axis(f; title = "Autocorrelogram (every 10th lag)")
ax_sig =
f[1, 1:3] =
Axis(f; title = "1.000 samples of noise", xlabel = "Time", ylabel = "Amplitude")
ax_spec =
f[2, 1:2] = Axis(
f;
title = "Welch Periodogram",
xlabel = "Normalized frequency",
ylabel = "log(Power)",
)
ax_auto =
f[2, 3:4] = Axis(
f;
title = "Autocorrelogram (every 10th lag)",
xlabel = "Lag",
ylabel = "Autocorrelation",
)
for n in [PinkNoise RedNoise WhiteNoise NoNoise ExponentialNoise]

## generate
noisevec = gen_noise(StableRNG(1), n(), 10000)
noisevec = simulate_noise(StableRNG(1), n(), 10000)

## plot 1000 samples
lines!(ax_sig, noisevec[1:1000]; label = string(n))
Expand All @@ -29,7 +43,7 @@ for n in [PinkNoise RedNoise WhiteNoise NoNoise ExponentialNoise]
lines!(ax_auto, lags, autocor_vec)

end
f[1:2, 3] = Legend(f, ax_sig, "NoiseType")
f[1, 4] = Legend(f, ax_sig, "Noise type", tellheight = true)
f


Expand Down
Loading
Loading