Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Aug 2, 2024
1 parent 12a7998 commit 2672688
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/MadsAnasol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ end
function computemass(madsfiles::Union{Regex,String}; time::Number=0, path::AbstractString=".")
mf = searchdir(madsfiles, path=path)
nf = length(mf)
Mads.madsinfo("Number of files = $nf")
madsinfo("Number of files = $nf")
lambda = Array{Float64}(undef, nf)
mass_injected = Array{Float64}(undef, nf)
mass_reduced = Array{Float64}(undef, nf)
Expand Down
8 changes: 4 additions & 4 deletions src/MadsBayesInfoGap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ Returns:
- BIG-DT problem type
"""
function makebigdt!(madsdata::AbstractDict, choice::AbstractDict)
Mads.madsinfo("Decision parameters:")
madsinfo("Decision parameters:")
for paramname in keys(choice["Parameters"])
if Mads.isopt(madsdata, paramname)
Mads.madscritical("Decision parameter, $(paramname), is also an adjustable (type = \"opt\") parameter.")
end
c = choice["Parameters"][paramname]
madsdata["Parameters"][paramname]["init"] = c
Mads.madsinfo("Decision parameter $(paramname) set to $c.")
madsinfo("Decision parameter $(paramname) set to $c.")
end
makeloglikelihood = makearrayconditionalloglikelihood(madsdata)
logprior = makearrayfunction(madsdata, makelogprior(madsdata))
Expand Down Expand Up @@ -131,9 +131,9 @@ function bigdt(madsdata::AbstractDict, nummodelruns::Integer; numhorizons::Integ
maxfailureprobs = Array{Float64}(undef, numhorizons, length(madsdata["Choices"]))
local horizons::Vector{Float64}
local likelihoodparams::Matrix{Float64} = zeros(0, 0)
Mads.madsinfo("Choices:")
madsinfo("Choices:")
for i = eachindex(madsdata["Choices"])
Mads.madsinfo("Choice #$i: $(madsdata["Choices"][i]["name"])")
madsinfo("Choice #$i: $(madsdata["Choices"][i]["name"])")
bigdt = makebigdt(madsdata, madsdata["Choices"][i])
if length(likelihoodparams) == 0
minlikelihoodparams = bigdt.likelihoodparamsmin(maxHorizon)
Expand Down
32 changes: 16 additions & 16 deletions src/MadsFunc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ function makemadscommandfunction(madsdata_in::AbstractDict; obskeys::AbstractVec
madscritical("Julia function $(fn) is not defined!")
end
end
Mads.madsinfo("""Model setup: Julia function -> Internal model evaluation of Julia function '$(madsdata["Julia function"])'""")
madsinfo("""Model setup: Julia function -> Internal model evaluation of Julia function '$(madsdata["Julia function"])'""")
"MADS command function based on a Julia function '$(madsdata["Julia function"])'"
function madscommandfunctionvector(parameters::AbstractDict)
o = jf(collect(values(parameters)))
return OrderedCollections.OrderedDict{Union{String,Symbol},Float64}(zip(Mads.getobskeys(madsdata), o))
end
madscommandfunction = madscommandfunctionvector
elseif haskey(madsdata, "Julia model")
Mads.madsinfo("""Model setup: Julia model -> Internal model evaluation of Julia function '$(madsdata["Julia model"])'""")
madsinfo("""Model setup: Julia model -> Internal model evaluation of Julia function '$(madsdata["Julia model"])'""")
madscommandfunction = madsdata["Julia model"]
elseif haskey(madsdata, "MADS model")
filename = joinpath(madsproblemdir, madsdata["MADS model"])
Mads.madsinfo("Model setup: MADS model -> Internal MADS model evaluation a Julia script in file '$(filename)'")
madsinfo("Model setup: MADS model -> Internal MADS model evaluation a Julia script in file '$(filename)'")
madsdatacommandfunction = importeverywhere(filename)
local madscommandfunction
try
Expand All @@ -129,7 +129,7 @@ function makemadscommandfunction(madsdata_in::AbstractDict; obskeys::AbstractVec
madscommandfunction = Base.invokelatest(madsdatacommandfunction, madsdata)
elseif haskey(madsdata, "Model")
filename = joinpath(madsproblemdir, madsdata["Model"])
Mads.madsinfo("Model setup: Model -> Internal model evaluation a Julia script in file '$(filename)'")
madsinfo("Model setup: Model -> Internal model evaluation a Julia script in file '$(filename)'")
madscommandfunction = importeverywhere(filename)
elseif haskey(madsdata, "Command") || haskey(madsdata, "Julia command") || ( haskey(madsdata, "Julia function") && haskey(madsdata, "Linked directory") )
linkdir = true
Expand All @@ -139,27 +139,27 @@ function makemadscommandfunction(madsdata_in::AbstractDict; obskeys::AbstractVec
if nprocs_per_task_default > 1 && npt != nprocs_per_task_default
if !isnothing(m)
madsdata["Command"] = replace(madsdata["Command"], r"(julia)(.*-p)[\s[0-9]*|[0-9]*]" => Base.SubstitutionString("$(first(Base.julia_cmd().exec)) --startup-file=no \\g<2> $nprocs_per_task_default"))
Mads.madsinfo("Mads Command has been updated to account for the number of processors per task ($nprocs_per_task_default)\nNew Mads Command: $(madsdata["Command"])")
madsinfo("Mads Command has been updated to account for the number of processors per task ($nprocs_per_task_default)\nNew Mads Command: $(madsdata["Command"])")
else
m = match(r"julia", madsdata["Command"])
if !isnothing(m)
madsdata["Command"] = replace(madsdata["Command"], r"(julia)" => "$(first(Base.julia_cmd().exec)) --startup-file=no -p $nprocs_per_task_default")
Mads.madsinfo("Mads Command has been updated to account for the number of processors per task ($nprocs_per_task_default)\nNew Mads Command: $(madsdata["Command"])")
madsinfo("Mads Command has been updated to account for the number of processors per task ($nprocs_per_task_default)\nNew Mads Command: $(madsdata["Command"])")
end
end
else
madsdata["Command"] = replace(madsdata["Command"], "julia" => "$(first(Base.julia_cmd().exec)) --startup-file=no")
Mads.madsinfo("Mads Command has been updated to account for the location of julia: $(madsdata["Command"])")
madsinfo("Mads Command has been updated to account for the location of julia: $(madsdata["Command"])")
end
Mads.madsinfo("""Model setup: Command -> External model evaluation of command '$(madsdata["Command"])'""")
madsinfo("""Model setup: Command -> External model evaluation of command '$(madsdata["Command"])'""")
end
if haskey(madsdata, "Julia command")
filename = joinpath(madsproblemdir, madsdata["Julia command"])
Mads.madsinfo("Model setup: Julia command -> Model evaluation using a Julia script in file '$(filename)'")
madsinfo("Model setup: Julia command -> Model evaluation using a Julia script in file '$(filename)'")
madsdatacommandfunction = importeverywhere(filename)
elseif haskey(madsdata, "Julia function") && haskey(madsdata, "Linked directory") && madsdata["Linked directory"] == true
if typeof(madsdata["Julia function"]) <: Function
Mads.madsinfo("""Model setup: Julia function -> Internal model evaluation of Julia function '$(madsdata["Julia function"])' in dedicated linked directory""")
madsinfo("""Model setup: Julia function -> Internal model evaluation of Julia function '$(madsdata["Julia function"])' in dedicated linked directory""")
"MADS command function"
function madscommandfunctionexternal(parameters::AbstractVector)
o = madsdata["Julia function"](parameters)
Expand Down Expand Up @@ -218,7 +218,7 @@ function makemadscommandfunction(madsdata_in::AbstractDict; obskeys::AbstractVec
str = haskey(madsdata, "Julia command") ? "Julia command" : "Julia function"
cmd = haskey(madsdata, "Julia command") ? madsdata["Julia command"] : madsdata["Julia function"]
md = haskey(madsdata, "Julia command") ? madsdata : collect(values(parameters))
Mads.madsinfo("Executing Julia model evaluation script parsing the model outputs (`$(str)` `$(cmd)`) in directory $(tempdirname) ...")
madsinfo("Executing Julia model evaluation script parsing the model outputs (`$(str)` `$(cmd)`) in directory $(tempdirname) ...")
attempt = 0
trying = true
latest = false
Expand Down Expand Up @@ -254,7 +254,7 @@ function makemadscommandfunction(madsdata_in::AbstractDict; obskeys::AbstractVec
end
end
else
Mads.madsinfo("Executing `Command` '$(madsdata["Command"])' in directory $(tempdirname) ...")
madsinfo("Executing `Command` '$(madsdata["Command"])' in directory $(tempdirname) ...")
attempt = 0
trying = true
while trying
Expand Down Expand Up @@ -308,7 +308,7 @@ function makemadscommandfunction(madsdata_in::AbstractDict; obskeys::AbstractVec
end
madscommandfunction = madscommandfunctionrerun
elseif haskey(madsdata, "Sources") && !haskey(madsdata, "Julia model") && !haskey(madsdata, "Julia function") # we may still use "Wells" instead of "Observations"
Mads.madsinfo("MADS internal Anasol model evaluation for contaminant transport ...\n")
madsinfo("MADS internal Anasol model evaluation for contaminant transport ...\n")
return makecomputeconcentrations(madsdata; calczeroweightobs=calczeroweightobs, calcpredictions=calcpredictions)
else
Mads.madswarn("Cannot create a function to call model without an entry in the MADS problem dictionary!")
Expand Down Expand Up @@ -534,16 +534,16 @@ function makemadsloglikelihood(madsdata::AbstractDict; weightfactor::Number=1.)
madsproblemdir = Mads.getmadsproblemdir(madsdata)
if haskey(madsdata, "LogLikelihood")
filename = joinpath(madsproblemdir, madsdata["LogLikelihood"])
Mads.madsinfo("Log-likelihood function provided externally from a file: '$(filename)'")
madsinfo("Log-likelihood function provided externally from a file: '$(filename)'")
madsloglikelihood = importeverywhere(filename)
return madsloglikelihood
elseif haskey(madsdata, "ConditionalLogLikelihood")
filename = joinpath(madsproblemdir, madsdata["ConditionalLogLikelihood"])
Mads.madsinfo("Conditional Log-likelihood function provided externally from a file: '$(filename)'")
madsinfo("Conditional Log-likelihood function provided externally from a file: '$(filename)'")
conditionalloglikelihood = importeverywhere(filename)
internalweightfactor = weightfactor
else
Mads.madsinfo("Log-likelihood function computed internally ...")
madsinfo("Log-likelihood function computed internally ...")
conditionalloglikelihood = makemadsconditionalloglikelihood(madsdata; weightfactor=weightfactor)
internalweightfactor = 1
end
Expand Down
4 changes: 2 additions & 2 deletions src/MadsIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ function createtempdir(tempdirname::AbstractString)
try
attempt += 1
Mads.mkdir(tempdirname)
Mads.madsinfo("Created temporary directory: $(tempdirname)", 1)
madsinfo("Created temporary directory: $(tempdirname)", 1)
trying = false
catch errmsg
sleep(attempt * 0.5)
Expand All @@ -1609,7 +1609,7 @@ function linktempdir(madsproblemdir::AbstractString, tempdirname::AbstractString
try
attempt += 1
Mads.symlinkdirfiles(madsproblemdir, tempdirname)
Mads.madsinfo("Links created in temporary directory: $(tempdirname)", 1)
madsinfo("Links created in temporary directory: $(tempdirname)", 1)
trying = false
catch errmsg
Mads.rmdir(tempdirname)
Expand Down
22 changes: 11 additions & 11 deletions src/MadsLevenbergMarquardt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function levenberg_marquardt(f::Function, g::Function, x0, o::Function=x->(x'*x)
first_lambda = false
end
lambda_current = lambda_down = lambda_up = lambda
Mads.madsinfo(@Printf.sprintf "Iteration %02d: Starting lambda: %e" g_calls lambda_current)
madsinfo(@Printf.sprintf("Iteration %02d: Starting lambda: %e", g_calls, lambda_current), 2)
for npl = 1:np_lambda
if npl == 1 # first lambda
lambda_current = lambda_p[npl] = lambda
Expand All @@ -469,7 +469,7 @@ function levenberg_marquardt(f::Function, g::Function, x0, o::Function=x->(x'*x)
lambda = lambda_p[npl]
predicted_of = []
delta_x = []
Mads.madsinfo(@Printf.sprintf "#%02d lambda: %e" npl lambda, 2)
madsinfo(@Printf.sprintf("#%02d lambda: %e", npl, lambda), 2)
u, s, v = LinearAlgebra.svd(JpJ + lambda * DtDidentity)
is = similar(s)
for i = eachindex(s)
Expand All @@ -488,7 +488,7 @@ function levenberg_marquardt(f::Function, g::Function, x0, o::Function=x->(x'*x)
# delta_x = (JpJ + lambda * DtDidentity) \ -J' * fcur # TODO replace with SVD
predicted_of = o(J * delta_x + fcur)
# check for numerical problems in solving for delta_x by ensuring that the predicted residual is smaller than the current residual
madsoutput("$(@Printf.sprintf "#%02d OF (est): %f" npl predicted_of)", 3);
madsoutput(@Printf.sprintf("#%02d OF (est): %f", npl, predicted_of), 3);
if predicted_of > current_of + 2max(eps(predicted_of), eps(current_of))
madsoutput(" -> not good", 3);
if npl == 1
Expand Down Expand Up @@ -548,8 +548,8 @@ function levenberg_marquardt(f::Function, g::Function, x0, o::Function=x->(x'*x)

npl_best = argmin(trial_ofs)
npl_worst = argmax(trial_ofs)
madsoutput(@Printf.sprintf "OF range in the parallel lambda search: min %e max %e\n" trial_ofs[npl_best] trial_ofs[npl_worst], 2)
madsoutput(@Printf.sprintf "Lambda range in the parallel lambda search: best %e worst %e\n" lambda_p[npl_best] lambda_p[npl_worst], 2)
madsoutput(@Printf.sprintf("OF range in the parallel lambda search: min %e max %e\n", trial_ofs[npl_best], trial_ofs[npl_worst]), 2)
madsoutput(@Printf.sprintf("Lambda range in the parallel lambda search: best %e worst %e\n", lambda_p[npl_best], lambda_p[npl_worst]), 2)
lambda = lambda_p[npl_best] # Set lambda to the best value
delta_x = vec(delta_xs[npl_best])
trial_f = vec(trial_residuals[npl_best])
Expand Down Expand Up @@ -598,31 +598,31 @@ function levenberg_marquardt(f::Function, g::Function, x0, o::Function=x->(x'*x)
# check convergence criteria:
nx = LinearAlgebra.norm(delta_x)
if nx < tolX * (tolX + LinearAlgebra.norm(x))
Mads.madsinfo("Small parameter step size: $nx < $tolX (tolX)")
madsinfo("Small parameter step size: $nx < $tolX (tolX)", 2)
x_converged = true
end
ng = LinearAlgebra.norm(J' * fcur, Inf)
if ng < tolG
Mads.madsinfo("Small gradient: $ng < $tolG (LinearAlgebra.norm(J^T * fcur) < tolG)")
madsinfo("Small gradient: $ng < $tolG (LinearAlgebra.norm(J^T * fcur) < tolG)", 2)
g_converged = true
end
if length(residuals) > tolOFcount
is = sortperm(residuals)
changeOF = residuals[is][tolOFcount] - residuals[is][1]
if changeOF < tolOF
Mads.madsinfo("Small objective function changes (less than $tolOF tolOF): $changeOF < $tolOF")
madsinfo("Small objective function changes (less than $tolOF tolOF): $changeOF < $tolOF", 2)
of_converged = true
end
end
if best_of < minOF
Mads.madsinfo("Objective function less than $minOF (tolOF): $best_of < $minOF")
madsinfo("Objective function less than $minOF (tolOF): $best_of < $minOF", 2)
of_converged = true
end
if g_calls >= maxJacobians
Mads.madsinfo("Maximum number of Jacobian evaluations have been reached: $g_calls < $maxJacobians")
madsinfo("Maximum number of Jacobian evaluations have been reached: $g_calls < $maxJacobians", 2)
end
if f_calls >= maxEval
Mads.madsinfo("Maximum number of Forward evaluations have been reached: $f_calls < $maxEval")
madsinfo("Maximum number of Forward evaluations have been reached: $f_calls < $maxEval", 2)
end
converged = g_converged | x_converged | of_converged
end
Expand Down
6 changes: 3 additions & 3 deletions src/MadsPlot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ function plotlocalsa(filenameroot::AbstractString; keyword::AbstractString="", f
Gadfly.Scale.ContinuousColorScale(Gadfly.Scale.lab_gradient(Base.parse(Colors.Colorant, "green"), Base.parse(Colors.Colorant, "yellow"), Base.parse(Colors.Colorant, "red")), minvalue = -mscale, maxvalue = mscale))
filename = "$(rootname)-jacobian" * ext
plotfileformat(jacmat, filename, 3Gadfly.inch+0.25Gadfly.inch*nP, 3Gadfly.inch+0.25Gadfly.inch*nO; format=format, dpi=imagedpi)
Mads.madsinfo("Jacobian matrix plot saved in $filename")
madsinfo("Jacobian matrix plot saved in $filename")
end
end
filename = "$(filenameroot)-covariance.dat"
Expand Down Expand Up @@ -1416,15 +1416,15 @@ function plotlocalsa(filenameroot::AbstractString; keyword::AbstractString="", f
# eigenval = plot(x=eachindex(sortedeigenv), y=sortedeigenv, Scale.x_discrete, Scale.y_log10, Geom.bar, Guide.YLabel("Eigenvalues"), Guide.XLabel("Eigenvectors"))
filename = "$(rootname)-eigenmatrix" * ext
plotfileformat(eigenmat, filename, 4Gadfly.inch+0.25Gadfly.inch*nP, 4Gadfly.inch+0.25Gadfly.inch*nP; format=format, dpi=imagedpi)
Mads.madsinfo("Eigen matrix plot saved in $filename")
madsinfo("Eigen matrix plot saved in $filename")
if sizeof(sortedeigenv) > 0
eigenval = Gadfly.plot(x=eachindex(sortedeigenv), y=sortedeigenv, Gadfly.Scale.x_discrete, Gadfly.Scale.y_log10,
Gadfly.Geom.bar,
Gadfly.Theme(point_size=20Gadfly.pt, major_label_font_size=14Gadfly.pt, minor_label_font_size=12Gadfly.pt, key_title_font_size=16Gadfly.pt, key_label_font_size=12Gadfly.pt),
Gadfly.Guide.YLabel("Eigenvalues"), Gadfly.Guide.XLabel("Eigenvectors"))
filename = "$(rootname)-eigenvalues" * ext
plotfileformat(eigenval, filename, 4Gadfly.inch+0.25Gadfly.inch*nP, 4Gadfly.inch; format=format, dpi=imagedpi)
Mads.madsinfo("Eigen values plot saved in $filename")
madsinfo("Eigen values plot saved in $filename")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/MadsSensitivityAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function localsa(madsdata::AbstractDict; sinspace::Bool=true, keyword::AbstractS
Gadfly.Scale.ContinuousColorScale(Gadfly.Scale.lab_gradient(Base.parse(Colors.Colorant, "green"), Base.parse(Colors.Colorant, "yellow"), Base.parse(Colors.Colorant, "red")), minvalue = -mscale, maxvalue = mscale))
filename = "$(rootname)-jacobian" * ext
plotfileformat(jacmat, filename, 3Gadfly.inch+0.25Gadfly.inch*nP, 3Gadfly.inch+0.25Gadfly.inch*nO; format=format, dpi=imagedpi)
Mads.madsinfo("Jacobian matrix plot saved in $filename")
madsinfo("Jacobian matrix plot saved in $filename")
end
if sum(bad_params) == 0
JpJ = J' * J
Expand Down Expand Up @@ -254,14 +254,14 @@ function localsa(madsdata::AbstractDict; sinspace::Bool=true, keyword::AbstractS
# eigenval = plot(x=eachindex(sortedeigenv), y=sortedeigenv, Scale.x_discrete, Scale.y_log10, Geom.bar, Guide.YLabel("Eigenvalues"), Guide.XLabel("Eigenvectors"))
filename = "$(rootname)-eigenmatrix" * ext
plotfileformat(eigenmat, filename, 4Gadfly.inch+0.25Gadfly.inch*nP, 4Gadfly.inch+0.25Gadfly.inch*nP; format=format, dpi=imagedpi)
Mads.madsinfo("Eigen matrix plot saved in $filename")
madsinfo("Eigen matrix plot saved in $filename")
eigenval = Gadfly.plot(x=eachindex(sortedeigenv), y=sortedeigenv, Gadfly.Scale.x_discrete, Gadfly.Scale.y_log10,
Gadfly.Geom.line(),
Gadfly.Theme(line_width=4Gadfly.pt, major_label_font_size=14Gadfly.pt, minor_label_font_size=12Gadfly.pt, key_title_font_size=16Gadfly.pt, key_label_font_size=12Gadfly.pt),
Gadfly.Guide.YLabel("Eigenvalues"), Gadfly.Guide.XLabel("Eigenvectors"))
filename = "$(rootname)-eigenvalues" * ext
plotfileformat(eigenval, filename, 4Gadfly.inch+0.25Gadfly.inch*nP, 4Gadfly.inch; format=format, dpi=imagedpi)
Mads.madsinfo("Eigen values plot saved in $filename")
madsinfo("Eigen values plot saved in $filename")
end
Dict("of"=>ofval, "jacobian"=>J, "covar"=>covar, "stddev"=>stddev_full, "eigenmatrix"=>sortedeigenm, "eigenvalues"=>sortedeigenv)
end
Expand Down
2 changes: 1 addition & 1 deletion test/miscellaneous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Mads.stdouterrcaptureon()
Mads.printerrormsg("a")
madsoutput("a")
Mads.madsdebug("a")
Mads.madsinfo("Testing ...")
madsinfo("Testing ...")
Mads.help()
Mads.copyright()
if length(ARGS) < 1
Expand Down

0 comments on commit 2672688

Please sign in to comment.