-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
distributed and reduced precision bootstrap (#694)
* distributed and reduced precision bootstrap * parallel example * note for reduced precision * version bump, notes * bootstrap save and restore * NEWS * (approximate) equality and tests --------- Co-authored-by: Douglas Bates <dmbates@gmail.com>
- Loading branch information
Showing
11 changed files
with
399 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[deps] | ||
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" | ||
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" | ||
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" | ||
MixedModels = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316" | ||
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
Scratch = "6c6a2e73-6563-6170-7368-637461726353" | ||
StandardizedPredictors = "5064a6a7-f8c2-40e2-8bdc-797ec6f1ae18" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Cache | ||
using Downloads | ||
using Scratch | ||
# This will be filled in inside `__init__()` | ||
download_cache = "" | ||
url = "https://github.com/RePsychLing/SMLP2022/raw/main/data/fggk21.arrow" | ||
#"https://github.com/bee8a116-0383-4365-8df7-6c6c8d6c1322" | ||
|
||
function data_path() | ||
fname = joinpath(download_cache, basename(url)) | ||
if !isfile(fname) | ||
@info "Local cache not found, downloading" | ||
Downloads.download(url, fname) | ||
end | ||
return fname | ||
end | ||
|
||
function __init__() | ||
global download_cache = get_scratch!(@__MODULE__, "downloaded_files") | ||
return nothing | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
include("cache.jl") | ||
using .Cache | ||
using Arrow | ||
using CategoricalArrays | ||
using DataFrames | ||
using Distributed | ||
using MixedModels | ||
using ProgressMeter | ||
using Random | ||
using StandardizedPredictors | ||
|
||
kb07 = MixedModels.dataset(:kb07) | ||
contrasts = Dict(:item => Grouping(), | ||
:subj => Grouping(), | ||
:spkr => EffectsCoding(), | ||
:prec => EffectsCoding(), | ||
:load => EffectsCoding()) | ||
m07 = fit(MixedModel, | ||
@formula( | ||
1000 / rt_raw ~ | ||
1 + spkr * prec * load + | ||
(1 + spkr * prec * load | item) + | ||
(1 + spkr * prec * load | subj) | ||
), | ||
kb07; contrasts, progress=true, thin=1) | ||
|
||
pbref = @time parametricbootstrap(MersenneTwister(42), 1000, m07); | ||
pb_restricted = @time parametricbootstrap( | ||
MersenneTwister(42), 1000, m07; optsum_overrides=(; ftol_rel=1e-3) | ||
); | ||
pb_restricted2 = @time parametricbootstrap( | ||
MersenneTwister(42), 1000, m07; optsum_overrides=(; ftol_rel=1e-6) | ||
); | ||
confint(pbref) | ||
confint(pb_restricted) | ||
confint(pb_restricted2) | ||
|
||
using .Cache | ||
using Distributed | ||
addprocs(3) | ||
@everywhere using MixedModels, Random, StandardizedPredictors | ||
df = DataFrame(Arrow.Table(Cache.data_path())) | ||
|
||
transform!(df, :Sex => categorical, :Test => categorical; renamecols=false) | ||
recode!(df.Test, | ||
"Run" => "Endurance", | ||
"Star_r" => "Coordination", | ||
"S20_r" => "Speed", | ||
"SLJ" => "PowerLOW", | ||
"BPT" => "PowerUP") | ||
df = combine(groupby(df, :Test), :, :score => zscore => :zScore) | ||
describe(df) | ||
|
||
contrasts = Dict(:Cohort => Grouping(), | ||
:School => Grouping(), | ||
:Child => Grouping(), | ||
:Test => SeqDiffCoding(), | ||
:Sex => EffectsCoding(), | ||
:age => Center(8.5)) | ||
|
||
f1 = @formula( | ||
zScore ~ | ||
1 + age * Test * Sex + | ||
(1 + Test + age + Sex | School) + | ||
(1 + Test | Child) + | ||
zerocorr(1 + Test | Cohort) | ||
) | ||
m1 = fit(MixedModel, f1, df; contrasts, progress=true, thin=1) | ||
|
||
# copy everything to workers | ||
@showprogress for w in workers() | ||
remotecall_fetch(() -> coefnames(m1), w) | ||
end | ||
|
||
# you need at least as many RNGs as cores you want to use in parallel | ||
# but you shouldn't use all of your cores because nested within this | ||
# is the multithreading of the linear algebra | ||
# 5 RNGS and 10 replicates from each | ||
pb_map = @time @showprogress pmap(MersenneTwister.(41:45)) do rng | ||
parametricbootstrap(rng, 100, m1; optsum_overrides=(; maxfeval=300)) | ||
end; | ||
@time confint(reduce(vcat, pb_map)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
8d71961
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
8d71961
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/86991
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: