Skip to content
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
6 changes: 6 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name = "Unfold"
uuid = "181c99d8-e21b-4ff3-b70b-c233eddec679"

authors = ["Benedikt Ehinger <[email protected]>"]
version = "0.8.8"


[deps]
BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand All @@ -24,6 +26,7 @@ MLBase = "f0e99cf1-93fa-52ec-9ecc-5026115318e0"
Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RobustModels = "d6ea1423-9682-4bbd-952f-b1577cbf8c98"
Expand All @@ -35,6 +38,7 @@ StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Term = "22787eb5-b846-44ae-b979-8e399b8463ab"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Expand Down Expand Up @@ -73,6 +77,7 @@ MLBase = "0.9"
Missings = "1"
OrderedCollections = "1"
PooledArrays = "1"
PrecompileTools = "1"
ProgressMeter = "1"
Random = "1"
RobustModels = "0.4,0.5,0.6"
Expand All @@ -84,6 +89,7 @@ StatsAPI = "1"
StatsBase = "0.33,0.34"
StatsFuns = "1"
StatsModels = "0.6,0.7"
Suppressor = "0.2"
Tables = "1"
Term = "2"
TimerOutputs = "0.5"
Expand Down
4 changes: 4 additions & 0 deletions src/Unfold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ using TypedTables # DataFrames loose the pooled array, so we have to do it diffe

using Interpolations # for FIR duration scaling
using ImageTransformations # for FIR duration scaling

using Suppressor
#using Tullio
#using BSplineKit # for spline predictors

Expand Down Expand Up @@ -70,6 +72,8 @@ include("solver/main.jl")
include("solver/solvers.jl")
include("solver/prepare.jl")

include("precompile.jl")

#include("plot.jl") # don't include for now
export fit, fit!, designmatrix!
export firbasis, hrfbasis
Expand Down
48 changes: 48 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using PrecompileTools: @setup_workload, @compile_workload




@setup_workload begin
data = rand(Float64, 2, 100)
evts = DataFrame(
:latency => (range(10, 70, length = 3)),
:condition => [:a, :a, :b],
:continuous => 1:3,
)


@compile_workload begin

# cut the data into epochs
data_epochs, t = Unfold.epoch(data = data, tbl = evts, τ = (-0.1, 0.1), sfreq = 10) # channel x timesteps x trials
f = @formula 0 ~ 1 + condition + continuous # note the formulas left side is `0 ~ ` for technical reasons`


basisfunction = firbasis(τ = (-0.1, 0.1), sfreq = 10)
bf_vec = [Any => (f, basisfunction)]


for m in [
@suppress(fit(UnfoldModel, f, evts, data_epochs, t)),
@suppress(fit(UnfoldModel, [Any => (f, t)], evts, data_epochs)),
@suppress(
fit(
UnfoldModel,
[Any => (f, t)],
Unfold.drop_missing_epochs(evts, data_epochs)[1],
Unfold.drop_missing_epochs(evts, data_epochs)[2],
)
),
@suppress(fit(UnfoldModel, bf_vec, evts, data)),
]
coef(m)
coeftable(m)
effects(Dict(:condition => [:a, :b]), m)
effects(Dict(:continuous => 1:2), m)
effects(Dict(:continuous => collect(1:2)), m)

end

end
end
1 change: 1 addition & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function equalize_size(
_get_data(data::AbstractVector, n) = @view data[1:n]

n = min(size(X, 1), size(data)[end])

X_v = X[1:n, :] # with view we got performance problems downstream, hotfixing this here
data_v = _get_data(data, n)
return X_v, data_v
Expand Down
2 changes: 1 addition & 1 deletion test/designmatrix.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##---

using DataFrames, StatsModels
tbl = DataFrame([1 4]', [:latency])
X = ones(size(tbl))
shouldBeNeg = zeros(4, 4)
Expand Down
2 changes: 1 addition & 1 deletion test/predict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ end
_r2 = Unfold.r2(m_reshape, data_reshape)
@test length(_r2) == 1
_r2 = Unfold.r2(m_e_reshape, data_e_reshape)
@test length(_r2) == 45
@test size(_r2) == (1, size(data_e_reshape, 2))

end
Loading