Skip to content

Commit

Permalink
fix(AutoCache): ignore normalisation in check
Browse files Browse the repository at this point in the history
The normalisation constant is applied outside of the model, so if the
model is additive the normalisation parameter does not need to be
checked to see if the model needs re-evaluation. This makes a big
performance difference if fitting simultaneous datasets on the same with
bound parameters domain but with different normalisations.
  • Loading branch information
fjebaker committed Jun 26, 2024
1 parent c511239 commit 402b3a2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/meta-models/caching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function _reinterpret_dual(
reinterpret(DualType, view(v, 1:n_elems)), needs_resize
end

function invoke!(output, domain, model::AutoCache{M,T}) where {M,T}
function invoke!(output, domain, model::AutoCache{M,T,K}) where {M,T,K}
D = promote_type(eltype(domain), T)

_new_params = parameter_tuple(model.model)
Expand All @@ -65,8 +65,14 @@ function invoke!(output, domain, model::AutoCache{M,T}) where {M,T}

# if the parameter size has changed, need to rerun the model
if (!out_resized) && (model.cache.size_of_element == sizeof(D)) && (same_domain)
# ignore the normalisation, since that's applied later
_pc, _np = @views if K === Additive
param_cache[2:end], _new_params[2:end]
else
param_cache, _new_params
end
# if all parameters within some tolerance, then just return the cache
within_tolerance = all(zip(param_cache, _new_params)) do I
within_tolerance = all(zip(_pc, _np)) do I
p, pm = I
abs((get_value(p) - get_value(pm)) / p) < model.abstol
end
Expand Down

0 comments on commit 402b3a2

Please sign in to comment.