diff --git a/src/MadsMonteCarlo.jl b/src/MadsMonteCarlo.jl index 50e9c453..10bc2aec 100644 --- a/src/MadsMonteCarlo.jl +++ b/src/MadsMonteCarlo.jl @@ -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 @@ -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) @@ -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 @@ -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