Skip to content

Commit

Permalink
Reflect test fix in docs, update images after Makie update, and up Sc…
Browse files Browse the repository at this point in the history
…iML compat (#92)
  • Loading branch information
DanielVandH committed Dec 5, 2023
1 parent fc54552 commit 42d6403
Show file tree
Hide file tree
Showing 25 changed files with 539 additions and 390 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ProfileLikelihood"
uuid = "3fca794e-44fa-49a6-b6a0-8cd45572ba0a"
authors = ["Daniel VandenHeuvel <danj.vandenheuvel@gmail.com>"]
version = "0.3.2"
version = "0.3.3"

[deps]
ChunkSplitters = "ae650224-84b6-46f8-82ea-d812ca08434e"
Expand Down Expand Up @@ -36,7 +36,7 @@ OffsetArrays = "1.12"
PolygonInbounds = "0.2"
PreallocationTools = "0.4"
Requires = "1.3"
SciMLBase = "1.77, 1.91, 1.94"
SciMLBase = "=2.9.1"
SimpleNonlinearSolve = "0.1"
StatsFuns = "1.1, 1.3"
julia = "1"
Expand Down
Binary file modified docs/src/figures/linear_exponential_example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/logistic_example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/logistic_example_prediction.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/lokta_example_bivariate_predictions.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/lokta_example_profiles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/lokta_example_univariate_predictions.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/noisy_pde_data.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/pde_prediction_intervals.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/pde_profiles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/figures/regression_profiles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions docs/src/heat.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ using CairoMakie, LaTeXStrings
fig = plot_profiles(prof; nrow=1, ncol=3,
latex_names=[L"k", L"c", L"u_0"],
true_vals=[k[1], c, u₀],
fig_kwargs=(fontsize=38, resolution=(2109.644f0, 444.242f0)),
fig_kwargs=(fontsize=38, size=(2109.644f0, 444.242f0)),
axis_kwargs=(width=600, height=300))
scatter!(fig.content[1], get_parameter_values(prof, :k), get_profile_values(prof, :k), color=:black, markersize=9)
scatter!(fig.content[2], get_parameter_values(prof, :c), get_profile_values(prof, :c), color=:black, markersize=9)
Expand Down Expand Up @@ -358,7 +358,7 @@ The confidence intervals contain the true values. We can now visualise.
fig = plot_profiles(prof; nrow=1, ncol=3,
latex_names=[L"k", L"u_0"],
true_vals=[k[1], u₀],
fig_kwargs=(fontsize=38, resolution=(1441.9216f0, 470.17322f0)),
fig_kwargs=(fontsize=38, size=(1441.9216f0, 470.17322f0)),
axis_kwargs=(width=600, height=300))
scatter!(fig.content[1], get_parameter_values(prof, :k), get_profile_values(prof, :k), color=:black, markersize=9)
scatter!(fig.content[2], get_parameter_values(prof, :u₀), get_profile_values(prof, :u₀), color=:black, markersize=9)
Expand Down Expand Up @@ -452,7 +452,7 @@ Now we can visualise the curves. We will also show the mass curve from the exact
```julia
exact_soln = compute_mass_function([k[1], u₀], prediction_data)
mle_soln = compute_mass_function(get_mle(mle_sol), prediction_data)
fig = Figure(fontsize=38, resolution=(1360.512f0, 848.64404f0))
fig = Figure(fontsize=38, size=(1360.512f0, 848.64404f0))
alp = join('a':'z')
latex_names = [L"k", L"u_0"]
for i in 1:2
Expand Down Expand Up @@ -619,7 +619,7 @@ using CairoMakie, LaTeXStrings
fig = plot_profiles(prof; nrow=1, ncol=3,
latex_names=[L"k", L"c", L"u_0"],
true_vals=[k[1], c, u₀],
fig_kwargs=(fontsize=38, resolution=(2109.644f0, 444.242f0)),
fig_kwargs=(fontsize=38, size=(2109.644f0, 444.242f0)),
axis_kwargs=(width=600, height=300))
scatter!(fig.content[1], get_parameter_values(prof, :k), get_profile_values(prof, :k), color=:black, markersize=9)
scatter!(fig.content[2], get_parameter_values(prof, :c), get_profile_values(prof, :c), color=:black, markersize=9)
Expand Down Expand Up @@ -674,7 +674,7 @@ prof = profile(likprob_2, mle_sol; ftol_abs=1e-4, ftol_rel=1e-4, xtol_abs=1e-4,
fig = plot_profiles(prof; nrow=1, ncol=3,
latex_names=[L"k", L"u_0"],
true_vals=[k[1], u₀],
fig_kwargs=(fontsize=38, resolution=(1441.9216f0, 470.17322f0)),
fig_kwargs=(fontsize=38, size=(1441.9216f0, 470.17322f0)),
axis_kwargs=(width=600, height=300))
scatter!(fig.content[1], get_parameter_values(prof, :k), get_profile_values(prof, :k), color=:black, markersize=9)
scatter!(fig.content[2], get_parameter_values(prof, :u₀), get_profile_values(prof, :u₀), color=:black, markersize=9)
Expand Down Expand Up @@ -705,7 +705,7 @@ parameter_wise, union_intervals, all_curves, param_range =
exact_soln = compute_mass_function([k[1], u₀], prediction_data)
mle_soln = compute_mass_function(get_mle(mle_sol), prediction_data)

fig = Figure(fontsize=38, resolution=(1360.512f0, 848.64404f0))
fig = Figure(fontsize=38, size=(1360.512f0, 848.64404f0))
alp = join('a':'z')
latex_names = [L"k", L"u_0"]
for i in 1:2
Expand Down
1 change: 1 addition & 0 deletions docs/src/logistic.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ prob = LikelihoodProblem(
data=(uᵒ, σ),
ode_parameters=[1.0, 1.0], # temp values for [λ, K]
ode_kwargs=(verbose=false, saveat=t),
f_kwargs=(adtype=Optimization.AutoFiniteDiff(),),
prob_kwargs=(lb=lb, ub=ub),
ode_alg=Rosenbrock23()
)
Expand Down
8 changes: 4 additions & 4 deletions docs/src/lotka.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fig_2 = plot_profiles(prof_2, param_pairs; # param_pairs not needed, but this en
true_vals=[α, β, a₀, b₀],
xlim_tuples=[(0.5, 1.5), (0.5, 1.5), (0.5, 1.5), (0.7, 1.3), (0.7, 1.3), (0.5, 1.1)],
ylim_tuples=[(0.5, 1.5), (0.5, 1.05), (0.1, 0.5), (0.5, 1.05), (0.1, 0.5), (0.1, 0.5)],
fig_kwargs=(fontsize=24,))
fig_kwargs=(fontsize=17,))
```

```@raw html
Expand All @@ -226,7 +226,7 @@ fig_3 = plot_profiles(prof_2, param_pairs;
interpolation=true,
xlim_tuples=[(0.5, 1.5), (0.5, 1.5), (0.5, 1.5), (0.7, 1.3), (0.7, 1.3), (0.5, 1.1)],
ylim_tuples=[(0.5, 1.5), (0.5, 1.05), (0.1, 0.5), (0.5, 1.05), (0.1, 0.5), (0.1, 0.5)],
fig_kwargs=(fontsize=24,))
fig_kwargs=(fontsize=17,))
```

```@raw html
Expand Down Expand Up @@ -269,7 +269,7 @@ prediction_function!(exact_soln, [α, β, a₀, b₀], pred_data)
prediction_function!(mle_soln, get_mle(sol), pred_data)

# Plot the parameter-wise intervals
fig = Figure(fontsize=38, resolution=(2935.488f0, 1392.64404f0))
fig = Figure(fontsize=38, size=(2935.488f0, 1392.64404f0))
alp = [['a', 'b', 'e', 'f'], ['c', 'd', 'g', 'h']]
latex_names = [L"\alpha", L"\beta", L"a_0", L"b_0"]
for (k, idx) in enumerate((a_idx, b_idx))
Expand Down Expand Up @@ -338,7 +338,7 @@ individual_intervals, union_intervals, q_vals, param_ranges =
q_prototype)

# Plot the intervals
fig = Figure(fontsize=38, resolution=(2935.488f0, 1854.64404f0))
fig = Figure(fontsize=38, size=(2935.488f0, 1854.64404f0))
integer_param_pairs = ProfileLikelihood.convert_symbol_tuples(param_pairs, prof_2) # converts to the integer representation
alp = [['a', 'b', 'e', 'f', 'i', 'j'], ['c', 'd', 'g', 'h', 'k', 'l']]
for (k, idx) in enumerate((a_idx, b_idx))
Expand Down
45 changes: 34 additions & 11 deletions src/problem_updates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,40 @@ update_initial_estimate(prob::OptimizationProblem, θ) = remake(prob; u0=θ)
update_initial_estimate(prob::OptimizationProblem, sol::SciMLBase.OptimizationSolution) = update_initial_estimate(prob, sol.u)

# replace obj with a new obj
function replace_objective_function(prob::OptimizationProblem{iip,FF,uType,P,B,LC,UC,Sns,K}, obj::F) where {F,iip,AD,G,H,HV,C,CJ,CH,LH,HP,CJP,CHP,LHP,S,S2,O,HCV,CJCV,CHCV,LHCV,EX,CEX,SYS,FF2,FF<:OptimizationFunction{iip,AD,FF2,G,H,HV,C,CJ,CH,LH,HP,CJP,CHP,LHP,S,S2,O,HCV,CJCV,CHCV,LHCV,EX,CEX,SYS},uType,P,B,LC,UC,Sns,K}
f = OptimizationFunction{iip,AD,F,G,H,HV,C,CJ,CH,LH,HP,CJP,CHP,LHP,S,S2,O,HCV,CJCV,CHCV,LHCV,EX,CEX,SYS
}(obj,
prob.f.adtype, prob.f.grad,
prob.f.hess, prob.f.hv,
prob.f.cons, prob.f.cons_j, prob.f.cons_h, prob.f.lag_h,
prob.f.hess_prototype, prob.f.cons_jac_prototype, prob.f.cons_hess_prototype, prob.f.lag_hess_prototype,
prob.f.syms, prob.f.paramsyms, prob.f.observed,
prob.f.hess_colorvec, prob.f.cons_jac_colorvec, prob.f.cons_hess_colorvec, prob.f.lag_hess_colorvec,
prob.f.expr, prob.f.cons_expr, prob.f.sys)
return remake(prob; f=f)
@inline function replace_objective_function(f::OF, new_f::FF) where {iip,AD,F,G,H,HV,C,CJ,CH,HP,CJP,CHP,S,S2,O,EX,CEX,SYS,LH,LHP,HCV,CJCV,CHCV,LHCV,OF<:OptimizationFunction{iip,AD,F,G,H,HV,C,CJ,CH,HP,CJP,CHP,S,S2,O,EX,CEX,SYS,LH,LHP,HCV,CJCV,CHCV,LHCV},FF}
# scimlbase needs to add a constructorof method for OptimizationFunction before we can just do @set with accessors.jl.
# g = @set f.f = new_f
# return g
return OptimizationFunction{iip,AD,FF,G,H,HV,C,CJ,CH,HP,CJP,CHP,S,S2,O,EX,CEX,SYS,LH,LHP,HCV,CJCV,CHCV,LHCV}(
new_f,
f.adtype,
f.grad,
f.hess,
f.hv,
f.cons,
f.cons_j,
f.cons_h,
f.hess_prototype,
f.cons_jac_prototype,
f.cons_hess_prototype,
f.syms,
f.paramsyms,
f.observed,
f.expr,
f.cons_expr,
f.sys,
f.lag_h,
f.lag_hess_prototype,
f.hess_colorvec,
f.cons_jac_colorvec,
f.cons_hess_colorvec,
f.lag_hess_colorvec,
)
end

@inline function replace_objective_function(prob::F, obj::FF) where {F<:OptimizationProblem,FF}
g = replace_objective_function(prob.f, obj)
return remake(prob; f=g)
end

# fix the objective function's nth parameter at θₙ
Expand Down

2 comments on commit 42d6403

@DanielVandH
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96496

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.3 -m "<description of version>" 42d6403e52c5b3a72c50e0dfe8ba5038407ee41f
git push origin v0.3.3

Please sign in to comment.