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

Updated "Adding documentation" section in the README #134

Merged
merged 2 commits into from
Oct 30, 2023
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ deps/src/
docs/build/
docs/site/
docs/.condaPkg
docs/src/generated/*
docs/src/generated/*/*
# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ 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 `doc/src/_literate/FILENAME.jl`.
3. Edit [make.jl](https://github.com/unfoldtoolbox/Unfold.jl/blob/main/docs/make.jl) with a reference to `doc/src/_literate/FILENAME.jl`
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 `doc/src/generated/FILENAME.jl`.
3. Edit [make.jl](https://github.com/unfoldtoolbox/Unfold.jl/blob/main/docs/make.jl) with a reference to `doc/src/literate/FILENAME.jl`

## Contributors (alphabetically)

Expand Down
File renamed without changes.
14 changes: 8 additions & 6 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ using DocStringExtensions
using Literate
using Glob

GENERATED = joinpath(@__DIR__, "src", "_literate")
GENERATED = joinpath(@__DIR__, "src", "generated")
SOURCE = joinpath(@__DIR__,"literate")
for subfolder ∈ ["explanations","HowTo","tutorials"]
local SOURCE_FILES = Glob.glob(subfolder*"/*.jl", GENERATED)
local SOURCE_FILES = Glob.glob(subfolder*"/*.jl", SOURCE)
foreach(fn -> Literate.markdown(fn, GENERATED*"/"*subfolder), SOURCE_FILES)

end
Expand All @@ -18,6 +19,7 @@ end
makedocs(sitename="Unfold.jl Timeseries Analysis & Deconvolution",
#root = joinpath(dirname(pathof(Unfold)), "..", "docs"),
#prettyurls = get(ENV, "CI", nothing) == "true",
repo = Documenter.Remotes.GitHub("unfoldtoolbox", "Unfold.jl"),
pages = [
"index.md",
"Tutorials"=>[
Expand All @@ -31,14 +33,14 @@ makedocs(sitename="Unfold.jl Timeseries Analysis & Deconvolution",
"Overlap: Different events"=>"HowTo/multiple_events.md",
"Load Existing Dataset with PyMNE.jl"=>"HowTo/pymne.md" ,
"Custom Solvers / StandardErrors / B2B"=>"HowTo/custom_solvers.md",
"Unfold.jl directly from Python" => "_literate/HowTo/pyjulia_unfold.md",
"Unfold.jl directly from Python" => "generated/HowTo/pyjulia_unfold.md",
"P-values in Mass Univariate MixedModels" => "HowTo/lmm_pvalues.md",
"marginal effects (what to do with non-linear predictors)" =>"_literate/HowTo/effects.md",
"Time Basis Functions"=>"_literate/HowTo/timesplines.md",
"marginal effects (what to do with non-linear predictors)" =>"generated/HowTo/effects.md",
"Time Basis Functions"=>"generated/HowTo/timesplines.md",
],
"Explanations"=>[
"Temporal Basisfunctions" => "./explanations/basisfunctions.md",
"Non-Linear Effects" => "./_literate/explanations/nonlinear_effects.md",],
"Non-Linear Effects" => "./generated/explanations/nonlinear_effects.md",],
"Reference"=>["Types" => "references/types.md",
"Functions" => "references/functions.md"],

Expand Down
3 changes: 3 additions & 0 deletions docs/run_liveserver.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using LiveServer
servedocs(skip_dir=joinpath("src","generated"),literate_dir=joinpath("literate"),foldername=".")

4 changes: 2 additions & 2 deletions docs/src/explanations/basisfunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using Unfold,DSP
TR = 1.5
bold = hrfbasis(TR) # using default SPM parameters
eventonset = 1.3
bold_kernel = Unfold.kernel(bold)
bold_kernel = e->Unfold.kernel(bold,e)
lines(bold_kernel(eventonset)[:,1]) # (returns a matrix, thus [:,1])
```
This is the shape that is assumed to reflect activity to an event. Generally, we would like to know how much to scale this response-shape per condition, e.g. in `condA` we might scale it by 0.7, in `condB` by 1.2.
Expand Down Expand Up @@ -60,7 +60,7 @@ Okay, let's have a look at a different basis function: The FIR basisfunction.
using Unfold #hide

basisfunction = firbasis(τ=(-0.4,.8),sfreq=50,name="myFIRbasis")
fir_kernel = Unfold.kernel(basisfunction)
fir_kernel = e->Unfold.kernel(basisfunction,e)
m = fir_kernel(0)
f = Figure()
f[1,1] = Axis(f)
Expand Down
2 changes: 1 addition & 1 deletion ext/UnfoldMixedModelsExt/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fake_lmm(m::UnfoldLinearMixedModel) = fake_lmm.(m,1:length(modelfit(m).fits))

Calculate likelihoodratiotest
"""
function MixedModels.likelihoodratiotest(m::UnfoldLinearMixedModel)
function MixedModels.likelihoodratiotest(m::UnfoldLinearMixedModel...)
#@info lrtest(fake_lmm.(m,1)...)
n = length(Unfold.modelfit(m[1]).fits)
lrt = Array{MixedModels.LikelihoodRatioTest}(undef,n)
Expand Down
2 changes: 1 addition & 1 deletion src/Unfold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ else

function solver_krylov(args...;kwargs...)
ext = checkFun(:UnfoldKrylovExt)
msg = "BSplineKit not loaded. Please use `]add Krylov,CUDA, using Krylov,CUDA` to install/load it, if you want to use krylov/GPU"
msg = "Krylov or CUDA not loaded. Please use `]add Krylov,CUDA, using Krylov,CUDA` to install/load it, if you want to use GPU-fitting"
isnothing(ext) ? throw(msg) : ext.solver_krylov(args...;kwargs...)
end

Expand Down
34 changes: 16 additions & 18 deletions src/basisfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,43 @@ $(FIELDS)
(tipp: most users would you want to call firbasis, not generate it manually)
# Examples
```julia-repl
julia> b = FIRBasis(kernelfunction,"derivative",["f(x)"],range(0,(length(kernelfunction([0, 1]))-1)*TR,step=TR),"hrf_kernel","basis_A",0)
julia> b = FIRBasis(range(0,1,length=10),"basisA",-1)
```
"""
struct FIRBasis <: BasisFunction
"a design-matrix kernel function used to timeexpand, given a timepoint in 'sample' timeunits"
kernel::Function

" vector of times along rows of kernel-output (in seconds)"
times::AbstractVector
times::Vector
"name of the event, random 1:1000 if unspecified"
name::String
"by how many samples do we need to shift the event onsets? This number is determined by how many 'negative' timepoints the basisfunction defines"
shiftOnset::Integer
shiftOnset::Int64
end

@deprecate FIRBasis(kernel::Function,times,name,shiftOnset) FIRBasis(times,name,shiftOnset)
collabel(basis::FIRBasis) = :time
colnames(basis::FIRBasis) = basis.times[1:end-1]


struct SplineBasis <: BasisFunction
"a design-matrix kernel function used to timeexpand, given a timepoint in 'sample' timeunits"
kernel::Function
"name of column dimension (e.g 'time' for FIR, 'derivative', for HRF etc.)"

"vector of names along columns of kernel-output"
colnames::AbstractVector
" vector of times along rows of kernel-output (in seconds)"
times::AbstractVector
times::Vector
"name of the event, random 1:1000 if unspecified"
name::String
"by how many samples do we need to shift the event onsets? This number is determined by how many 'negative' timepoints the basisfunction defines"
shiftOnset::Integer
shiftOnset::Int64
end


struct HRFBasis <: BasisFunction
"a design-matrix kernel function used to timeexpand, given a timepoint in 'sample' timeunits"
kernel::Function
"vector of names along columns of kernel-output"
colnames::AbstractVector
" vector of times along rows of kernel-output (in seconds)"
times::AbstractVector
times::Vector
"name of the event, random 1:1000 if unspecified"
name::String
end
Expand Down Expand Up @@ -105,12 +100,12 @@ function firbasis(τ, sfreq, name::String)
τ = round_times(τ, sfreq)
times = range(τ[1], stop = τ[2]+1 ./ sfreq, step = 1 ./ sfreq) # stop + 1 step, because we support fractional event-timings

kernel = e -> firkernel(e, times[1:end-1])



shiftOnset = Int64(floor(τ[1] * sfreq))

return FIRBasis(kernel, times, name, shiftOnset)
return FIRBasis(times, name, shiftOnset)
end
# cant multiple dispatch on optional arguments
#firbasis(;τ,sfreq) = firbasis(τ,sfreq)
Expand All @@ -132,12 +127,12 @@ function firkernel(e, times)
# XXX we will soon assume that the second entry would be the duration
e = Float64(e[1])
end
e = [1 .- (e .% 1) e .% 1]
e[isapprox.(e, 0, atol = 1e-15)] .= 0
eboth = [1 .- (e .% 1) e .% 1]
eboth[isapprox.(eboth, 0, atol = 1e-15)] .= 0
ksize = length(times) # kernelsize

kernel =
spdiagm(ksize + 1, ksize, 0 => repeat([e[1]], ksize), -1 => repeat([e[2]], ksize))
spdiagm(ksize + 1, ksize, 0 => repeat([eboth[1]], ksize), -1 => repeat([eboth[2]], ksize))

# dropzeros!(kernel) # we often get implicit 0, especially if the latencies are rounded
return (kernel)
Expand Down Expand Up @@ -208,7 +203,10 @@ collabel(term::Array{<:AbstractTerm}) = collabel(term[1].rhs) # in case of comb

shiftOnset(basis::BasisFunction) = basis.shiftOnset
colnames(basis::BasisFunction) = basis.colnames
kernel(basis::BasisFunction) = basis.kernel
kernel(basis::BasisFunction,e) = basis.kernel(e)
@deprecate kernel(basis::BasisFunction) basis.kernel

kernel(basis::FIRBasis,e) = firkernel(e,basis.times[1:end-1])

times(basis::BasisFunction) = basis.times
name(basis::BasisFunction) = basis.name
Expand Down
Loading