Skip to content

Commit

Permalink
20230712
Browse files Browse the repository at this point in the history
  • Loading branch information
paschermayr committed Jul 12, 2023
1 parent 166f0a4 commit 700778f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Baytes"
uuid = "72ddfcfc-6e9d-43df-829b-7aed7c549d4f"
authors = ["Patrick Aschermayr <p.aschermayr@gmail.com>"]
version = "0.3.6"
version = "0.3.7"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down Expand Up @@ -31,7 +31,7 @@ BaytesSMC = "0.3"
DocStringExtensions = "0.8, 0.9"
JLD2 = "0.4"
MCMCDiagnosticTools = "0.3"
ModelWrappers = "0.4"
ModelWrappers = "0.5"
PrettyTables = "2"
ProgressMeter = "1.7"
SimpleUnPack = "1"
Expand Down
2 changes: 2 additions & 0 deletions src/Baytes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ using ModelWrappers:
ModelWrapper,
Tagged,
Objective,
length_constrained,
length_unconstrained,
#= DiffObjective,
AbstractDifferentiableTune,
ℓObjectiveResult,
Expand Down
2 changes: 1 addition & 1 deletion src/sampling/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function chainsummary(
@unpack Ndigits, quantiles = printdefault
@unpack progress = trace.summary
@unpack tagged, paramnames = transform
Nparams = length(tagged)
Nparams = length_constrained(tagged)
Nchains = length(transform.chains)
## Flatten parameter to 3D array
computingtime = progress.enabled ? (progress.tlast - progress.tinit) : NaN
Expand Down
21 changes: 10 additions & 11 deletions src/sampling/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function trace_to_3DArray(
## Get trace information
@unpack tagged, chains, effective_iterations = transform
## Preallocate array
mcmcchain = zeros(length(effective_iterations), length(chains), length(tagged))
mcmcchain = zeros(length(effective_iterations), length(chains), length_constrained(tagged))
## Flatten corresponding parameter
#!NOTE: Commented-out loop below is threadsave, but chain is not flattened in correct order, which might be troublesome for MCMC chain analysis.
# Threads.@threads for (idx, chain) in collect(enumerate(chains))
Expand Down Expand Up @@ -171,17 +171,16 @@ function trace_to_3DArrayᵤ(
## Get trace information
@unpack tagged, chains, effective_iterations = transform
## Preallocate array
mcmcchain = zeros(length(effective_iterations), length(chains), length(tagged))
mcmcchain = zeros(length(effective_iterations), length(chains), length_unconstrained(tagged))
## Flatten corresponding parameter
#!NOTE: This is threadsave, but chain is not flattened in correct order, which might be troublesome for MCMC chain analysis.
# Threads.@threads for (idx, chain) in collect(enumerate(chains))
for (idx, chain) in collect(enumerate(chains))
for (iter0, iterburnin) in enumerate(effective_iterations)
# mcmcchain[iter0, :, idx] .=
mcmcchain[iter0, idx, :] .=
flatten(tagged.info.reconstruct,
unconstrain(tagged.info.transform, subset(trace.val[chain][iterburnin], tagged.parameter) )
)
# flatten(tagged.info.reconstruct, unconstrain(tagged.info.transform, subset(trace.val[chain][iterburnin], tagged.parameter) ) )
ModelWrappers.unconstrain_flatten(tagged.info, subset(trace.val[chain][iterburnin], tagged.parameter))
end
end
## Return MCMCChain
Expand All @@ -205,7 +204,7 @@ function trace_to_2DArray(
## Get trace information
@unpack tagged, chains, effective_iterations = transform
## Preallocate array
mcmcchain = zeros(length(effective_iterations) * length(chains), length(tagged))
mcmcchain = zeros(length(effective_iterations) * length(chains), length_constrained(tagged))
## Flatten corresponding parameter
#!NOTE: This is threadsave, but chain is not flattened in correct order, which might be troublesome for MCMC chain analysis.
# Threads.@threads for (idx, chain) in collect(enumerate(chains))
Expand Down Expand Up @@ -235,17 +234,17 @@ function trace_to_2DArrayᵤ(
## Get trace information
@unpack tagged, chains, effective_iterations = transform
## Preallocate array
mcmcchain = zeros(length(effective_iterations) * length(chains), length(tagged))
mcmcchain = zeros(length(effective_iterations) * length(chains), length_unconstrained(tagged))
## Flatten corresponding parameter
#!NOTE: This is threadsave, but chain is not flattened in correct ordered, which might be troublesome for MCMC chain analysis.
# Threads.@threads for (idx, chain) in collect(enumerate(chains))
iter = 0
for (idx, chain) in collect(enumerate(chains))
for (iter0, iterburnin) in enumerate(effective_iterations)
iter += 1
mcmcchain[iter, :] .= flatten(tagged.info.reconstruct,
unconstrain(tagged.info.transform, subset(trace.val[chain][iterburnin], tagged.parameter) )
)
mcmcchain[iter, :] .=
# flatten(tagged.info.reconstruct, unconstrain(tagged.info.transform, subset(trace.val[chain][iterburnin], tagged.parameter) ) )
ModelWrappers.unconstrain_flatten(tagged.info, subset(trace.val[chain][iterburnin], tagged.parameter))
end
end
## Return MCMCChain
Expand Down Expand Up @@ -329,7 +328,7 @@ function flatten_chainvals(
## Get trace information
@unpack tagged, chains, effective_iterations = transform
## Preallocate array
mcmcchain = [ [ zeros(tagged.info.reconstruct.default.output, length(tagged)) for _ in eachindex(effective_iterations) ] for _ in eachindex(chains) ]
mcmcchain = [ [ zeros(tagged.info.reconstruct.default.output, length_constrained(tagged)) for _ in eachindex(effective_iterations) ] for _ in eachindex(chains) ]
## Flatten corresponding parameter
#!NOTE: This is threadsave, but chain is not flattened in correct order, which might be troublesome for MCMC chain analysis, hence we opt out of it.
# Threads.@threads for (idx, chain) in collect(enumerate(chains))
Expand Down

2 comments on commit 700778f

@paschermayr
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/87373

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:

git tag -a v0.3.7 -m "<description of version>" 700778fad2792f56d04711df518bae63100c6ced
git push origin v0.3.7

Please sign in to comment.