Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Jan 30, 2024
1 parent 742048f commit 421fb96
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/MadsMonteCarlo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ end
function loadecmeeresults(madsdata::AbstractDict, filename::AbstractString)
if isfile(filename)
@info("Load AffineInvariantMCMC results from $(filename) ...")
if Mads.jld2haskey(filename, ["chain", "llhoods"]; quiet=false)
if !Mads.jld2haskey(filename, "chain", "llhoods"; quiet=false)
@warn("$(filename) does not contain AffineInvariantMCMC results!")
return nothing, nothing, nothing
end
chain, llhoods, params, obs = JLD2.load(filename, "chain", "llhoods", "params", "obs")
@info("AffineInvariantMCMC results loaded: number of parameters = $(size(chain, 1)); number of realizations = $(size(chain, 2))")
if Mads.jld2haskey(filename, ["observations", "params", "obs"]; quiet=false)
if !Mads.jld2haskey(filename, "observations", "params", "obs"; quiet=false)
@warn("$(filename) does not contain AffineInvariantMCMC observation results!")
return chain, llhoods, nothing
end
Expand Down Expand Up @@ -87,14 +87,11 @@ function emceesampling(madsdata::AbstractDict; filename::AbstractString="", load
@warn("No preexisting data to load! AffineInvariantMCMC will be not executed!")
return nothing, nothing, nothing
end
else
elseif isnothing(observations)
@info("AffineInvariantMCMC preexisting data loaded!")
return chain, llhoods, observations
end
end
if numwalkers <= 1
numwalkers = 2
end
Mads.setseed(seed; rng=rng)
optparamkeys = getoptparamkeys(madsdata)
p0 = Array{Float64}(undef, length(optparamkeys), numwalkers)
Expand All @@ -112,7 +109,7 @@ function emceesampling(madsdata::AbstractDict; filename::AbstractString="", load
p0[i, j] = pmin[i] + rand(Mads.rng, d) * (pmax[i] - pmin[i])
end
end
chain, llhoods, observations = emceesampling(madsdata, p0; numwalkers=numwalkers, seed=seed, rng=rng, kw...)
chain, llhoods, observations = emceesampling(madsdata, p0; filename=filename, numwalkers=numwalkers, seed=seed, rng=rng, kw...)
return chain, llhoods, observations
end

Expand Down Expand Up @@ -149,14 +146,8 @@ function emceesampling(madsdata::AbstractDict, p0::AbstractMatrix; filename::Abs
if save && filename != ""
JLD2.save(filename, "chain", chain, "llhoods", llhoods, "params", Mads.getoptparamkeys(madsdata), "obs", Mads.getobskeys(madsdata))
end
local observations
try
observations = Mads.forward(madsdata, permutedims(chain))
catch e
@warn("AffineInvariantMCMC observations cannot be computed!")
observations = nothing
end
if !isnothing(observations) && save && filename != ""
observations = Mads.forward(madsdata, permutedims(chain))
if save && filename != ""
Mads.jld2append(filename, "observations", observations)
end
return chain, llhoods, observations
Expand Down

0 comments on commit 421fb96

Please sign in to comment.