Skip to content

Commit

Permalink
calibrate
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Nov 21, 2023
1 parent 871633f commit 1b64e75
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/MadsCalibrate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function calibraterandom(madsdata::AbstractDict, numberofsamples::Integer=1; tol
allconverged = Vector{Bool}(undef, numberofsamples)
allparameters = Matrix{Float64}(undef, numberofsamples, length(keys(paramoptvalues)))
local bestparameters
local bestresult
bestphi = Inf
@ProgressMeter.showprogress 5 "Calibrating ..." for i in 1:numberofsamples
if i == 1 && first_init
Expand All @@ -71,17 +70,17 @@ function calibraterandom(madsdata::AbstractDict, numberofsamples::Integer=1; tol
!quiet && @info("Random initial guess #$(i): OF = $(allphi[i]) (converged=$(allconverged[i]))")
if allphi[i] < bestphi || i == 1
bestparameters = parameters
bestresult = results
bestphi = allphi[i]
end
if all_results
allparameters[i,:] = [parameters[paramkey] for paramkey in keys(paramoptvalues)]
end
end
if save_results
JLD2.save(joinpath(Mads.getmadsproblemdir(madsdata), "calibraterandom_results.jld2"), "phi", allphi, "allconverged", converged, "allparameters", parameters)
JLD2.save(joinpath(Mads.getmadsproblemdir(madsdata), "calibraterandom_results.jld2"), "phi", allphi, "converged", converged, "parameters", parameters)
end
Mads.setparamsinit!(madsdata, paramdict) # restore the original initial values
bestresult = Mads.forward(madsdata, bestparameters)
if all_results
return bestparameters, bestresult, allphi, allparameters
else
Expand Down Expand Up @@ -157,7 +156,7 @@ function calibraterandom_parallel(madsdata::AbstractDict, numberofsamples::Integ
@warn("Something is very wrong! All the objective function estimates are NaN!")
end
if save_results
JLD2.save(joinpath(Mads.getmadsproblemdir(madsdata), "calibraterandom_results.jld2"), "allphi", allphi, "allconverged", allconverged, "allparameters", allparameters)
JLD2.save(joinpath(Mads.getmadsproblemdir(madsdata), "calibraterandom_results.jld2"), "phi", allphi, "converged", converged, "parameters", parameters)
end
ibest = first(sortperm(allphi))
for (j, paramkey) in enumerate(keys(paramoptvalues))
Expand Down

0 comments on commit 1b64e75

Please sign in to comment.