Skip to content

Commit

Permalink
assert
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Feb 2, 2024
1 parent ca5b4ce commit 79385e6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/MadsMisc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ function makearrayfunction_dictionary(madsdata::AbstractDict, f::Function=makema
optparamkeys = getoptparamkeys(madsdata)
initparams = Mads.getparamdict(madsdata)
function arrayfunction_merge(arrayparameters::AbstractVector)
@assert length(arrayparameters) == length(optparamkeys)
return f(merge(initparams, OrderedCollections.OrderedDict{String,Float64}(zip(optparamkeys, arrayparameters))))
end
function arrayfunction(arrayparameters::AbstractVector)
@assert length(arrayparameters) == length(optparamkeys)
return f(OrderedCollections.OrderedDict{String,Float64}(zip(optparamkeys, arrayparameters)))
end
if length(initparams) == length(optparamkeys)
Expand Down Expand Up @@ -106,6 +108,7 @@ function makearrayconditionalloglikelihood(madsdata::AbstractDict, conditionallo
optparamkeys = getoptparamkeys(madsdata)
initparams = Mads.getparamdict(madsdata)
function arrayconditionalloglikelihood(arrayparameters::AbstractVector)
@assert length(arrayparameters) == length(optparamkeys)
predictions = f(merge(initparams, OrderedCollections.OrderedDict{String,Float64}(zip(optparamkeys, arrayparameters))))
cll = conditionalloglikelihood(predictions, madsdata["Observations"])
return cll
Expand All @@ -130,12 +133,14 @@ function makearrayloglikelihood(madsdata::AbstractDict, loglikelihood)
initparams = Mads.getparamdict(madsdata)
function arrayloglikelihood(arrayparameters::AbstractVector)
predictions = OrderedCollections.OrderedDict()
@assert length(arrayparameters) == length(optparamkeys)
d = OrderedCollections.OrderedDict{String,Float64}(zip(optparamkeys, arrayparameters))
try
predictions = f(merge(initparams, OrderedCollections.OrderedDict{String,Float64}(zip(optparamkeys, arrayparameters))))
predictions = f(merge(initparams, d))
catch
return -Inf
end
loglikelihood(OrderedCollections.OrderedDict{String,Float64}(zip(optparamkeys, arrayparameters)), predictions, madsdata["Observations"])
loglikelihood(d, predictions, madsdata["Observations"])
end
return arrayloglikelihood
end
Expand Down

0 comments on commit 79385e6

Please sign in to comment.