Skip to content

Commit 90684a6

Browse files
authored
Merge pull request #79 from DanielVandH/refine
Refinement methods
2 parents 4e02214 + 887a932 commit 90684a6

File tree

10 files changed

+793
-155
lines changed

10 files changed

+793
-155
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ProfileLikelihood"
22
uuid = "3fca794e-44fa-49a6-b6a0-8cd45572ba0a"
33
authors = ["Daniel VandenHeuvel <[email protected]>"]
4-
version = "0.2.0"
4+
version = "0.2.1"
55

66
[deps]
77
ChunkSplitters = "ae650224-84b6-46f8-82ea-d812ca08434e"

docs/src/docstrings.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ ProfileLikelihood.ProfileLikelihoodSolution
2424
ProfileLikelihood.ConfidenceInterval
2525
profile
2626
replace_profile!
27+
refine_profile!
2728
ProfileLikelihood.set_next_initial_estimate!(::Any, ::Any, ::Any, ::Any, ::Any)
29+
ProfileLikelihood.get_confidence_intervals!
30+
ProfileLikelihood.reach_min_steps!
2831
```
2932

3033
## BivariateProfileLikelihoodSolution

src/ProfileLikelihood.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export get_range
5454
export replace_profile!
5555
export construct_profile_grids
5656
export bivariate_profile
57+
export refine_profile!
5758

5859
function __init__()
5960
@require CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" begin

src/bivariate.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ function bivariate_profile(prob::LikelihoodProblem, sol::LikelihoodSolution, n::
5555
parallel=Val(false),
5656
next_initial_estimate_method=Val(:nearest),
5757
kwargs...) where {M,F}
58-
parallel = Val(SciMLBase._unwrap_val(parallel))
59-
normalise = Val(SciMLBase._unwrap_val(normalise))
60-
confidence_region_method = Val(SciMLBase._unwrap_val(confidence_region_method))
61-
next_initial_estimate_method = Val(SciMLBase._unwrap_val(next_initial_estimate_method))
58+
parallel = _Val(parallel)
59+
normalise = _Val(normalise)
60+
confidence_region_method = _Val(confidence_region_method)
61+
next_initial_estimate_method = _Val(next_initial_estimate_method)
6262

6363
## Extract the problem and solution
6464
opt_prob, mles, ℓmax = extract_problem_and_solution(prob, sol)
@@ -173,7 +173,7 @@ end
173173
@inline function prepare_cache_vectors(n, mles::AbstractVector{T}, res, num_params, normalise, ℓmax; parallel=Val(false)) where {T}
174174
profile_vals = OffsetArray(zeros(T, 2res + 1, 2res + 1), -res:res, -res:res)
175175
other_mles = OffsetArray([zeros(T, num_params - 2) for _ in 1:(2res+1), _ in 1:(2res+1)], -res:res, -res:res)
176-
normalise = SciMLBase._unwrap_val(normalise)
176+
normalise = take_val(normalise)
177177
profile_vals[0, 0] = normalise ? zero(T) : ℓmax
178178
other_mles[0, 0] .= mles[Not(n[1], n[2])]
179179
if parallel == Val(false)
@@ -264,7 +264,7 @@ end
264264
fixed_prob = setup_layer_node_problem!(fixed_vals, grid, I, sub_cache, other_mle, layer, restricted_prob,
265265
next_initial_estimate_method, cache, n)
266266
soln = solve(fixed_prob, alg; kwargs...)
267-
normalise = SciMLBase._unwrap_val(normalise)
267+
normalise = take_val(normalise)
268268
@inbounds profile_vals[I] = -soln.objective - ℓmax * !normalise
269269
@inbounds other_mle[I] = soln.u
270270
return compare_to_threshold(any_above_threshold, profile_vals, threshold, I)

src/plotting.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const ALPHABET = join('a':'z')
1010
shade_ci=true,
1111
fig_kwargs=nothing,
1212
axis_kwargs=nothing,
13+
show_points=false,
14+
markersize=9,
1315
latex_names = Dict(vars .=> [LaTeXStrings.L"\theta_{i}" for i in SciMLBase.sym_to_index.(vars, Ref(prof))]))
1416
1517
Plot results from a profile likelihood solution `prof`.
@@ -27,6 +29,8 @@ Plot results from a profile likelihood solution `prof`.
2729
- `shade_ci=true`: Whether to shade the area under the profile between the confidence interval.
2830
- `fig_kwargs=nothing`: Extra keyword arguments for `Figure` (see the Makie docs).
2931
- `axis_kwargs=nothing`: Extra keyword arguments for `Axis` (see the Makie docs).
32+
- `show_points=false`: Whether to show the profile data.
33+
- `markersize=9`: The marker size used for `show_points`.
3034
- `latex_names = Dict(vars .=> [LaTeXStrings.L"\theta_{i}" for i in SciMLBase.sym_to_index.(vars, Ref(prof))]))`: LaTeX names to use for the parameters. Defaults to `θᵢ`, where `i` is the index of the parameter.
3135
3236
# Output
@@ -41,6 +45,8 @@ function plot_profiles(prof::ProfileLikelihoodSolution, vars=profiled_parameters
4145
shade_ci=true,
4246
fig_kwargs=nothing,
4347
axis_kwargs=nothing,
48+
show_points=false,
49+
markersize=9,
4450
latex_names=Dict(vars .=> [LaTeXStrings.L"\theta_{%$i}" for i in SciMLBase.sym_to_index.(vars, Ref(prof))]))
4551
num_plots = vars isa Symbol ? 1 : length(vars)
4652
_, _, plot_positions = choose_grid_layout(num_plots, ncol, nrow)
@@ -53,9 +59,9 @@ function plot_profiles(prof::ProfileLikelihoodSolution, vars=profiled_parameters
5359
for (ℓ, k) in itr
5460
i, j = plot_positions[ℓ]
5561
if axis_kwargs !== nothing
56-
plot_profile!(prof[k], fig, ℓ, k, i, j, spline, true_vals[k], show_mles ? get_likelihood_solution(prof)[k] : nothing, shade_ci, latex_names[k]; axis_kwargs)
62+
plot_profile!(prof[k], fig, ℓ, k, i, j, spline, true_vals[k], show_mles ? get_likelihood_solution(prof)[k] : nothing, shade_ci, latex_names[k], show_points, markersize; axis_kwargs)
5763
else
58-
plot_profile!(prof[k], fig, ℓ, k, i, j, spline, true_vals[k], show_mles ? get_likelihood_solution(prof)[k] : nothing, shade_ci, latex_names[k])
64+
plot_profile!(prof[k], fig, ℓ, k, i, j, spline, true_vals[k], show_mles ? get_likelihood_solution(prof)[k] : nothing, shade_ci, latex_names[k], show_points, markersize)
5965
end
6066
end
6167
return fig
@@ -150,7 +156,8 @@ function choose_grid_layout(num_plots, cols, rows)
150156
end
151157

152158
function plot_profile!(prof::ProfileLikelihoodSolutionView, fig, ℓ, k, i, j,
153-
spline, true_vals, mle_val=nothing, shade_ci=true, param_name=LaTeXStrings.L"\theta_{%$ℓ}"; axis_kwargs=nothing)
159+
spline, true_vals, mle_val=nothing, shade_ci=true, param_name=LaTeXStrings.L"\theta_{%$ℓ}",
160+
show_points=false, markersize=9; axis_kwargs=nothing)
154161
lower_ci, upper_ci = get_confidence_intervals(prof)
155162
θ_vals = get_parameter_values(prof)
156163
ℓ_vals = get_profile_values(prof)
@@ -196,6 +203,9 @@ function plot_profile!(prof::ProfileLikelihoodSolutionView, fig, ℓ, k, i, j,
196203
if !isnothing(mle_val)
197204
CairoMakie.vlines!(ax, [mle_val], color=:red, linetype=:dashed)
198205
end
206+
if show_points
207+
CairoMakie.scatter!(ax, θ_vals, ℓ_vals, color=:black, markersize=markersize)
208+
end
199209
return nothing
200210
end
201211
function plot_profile!(prof::BivariateProfileLikelihoodSolutionView, fig, ℓ, (k, r), i, j,

src/prediction_intervals.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,25 @@ end
173173
return build_q_prototype(q, get_parent(prof), data)
174174
end
175175

176+
@inline function spline_other_mles(parameter_values, other_mles)
177+
spline = interpolate((parameter_values,), other_mles, Gridded(Linear()))
178+
return spline
179+
end
180+
@inline function spline_other_mles(parameter_values_1, parameter_values_2, other_mles)
181+
spline = interpolate((parameter_values_1, parameter_values_2), other_mles, Gridded(Linear()))
182+
return spline
183+
end
176184
@inline function spline_other_mles(prof::ProfileLikelihoodSolutionView)
177185
data = get_parameter_values(prof)
178186
other_mles = get_other_mles(prof)
179-
spline = interpolate((data,), other_mles, Gridded(Linear()))
187+
spline = spline_other_mles(data, other_mles)
180188
return spline
181189
end
182190
@inline function spline_other_mles(prof::BivariateProfileLikelihoodSolutionView)
183191
grid_1 = get_parameter_values(prof, 1)
184192
grid_2 = get_parameter_values(prof, 2)
185193
other_mles = get_other_mles(prof)
186-
spline = interpolate((grid_1, grid_2), other_mles, Gridded(Linear()))
194+
spline = spline_other_mles(grid_1, grid_2, other_mles)
187195
return spline
188196
end
189197
@inline function spline_other_mles(prof::Union{ProfileLikelihoodSolution,BivariateProfileLikelihoodSolution})

0 commit comments

Comments
 (0)