Skip to content

Commit 62255e0

Browse files
Merge pull request #431 from SciML/qqy/tunable_parameters
Change fit_parameters to tune_parameters
2 parents cca22cc + 212c27f commit 62255e0

13 files changed

Lines changed: 118 additions & 118 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Random = "1.10"
5959
RecursiveArrayTools = "3.31.2"
6060
ReTestItems = "1.29"
6161
Reexport = "1.2"
62-
SciMLBase = "2.130.0"
62+
SciMLBase = "2.138.0"
6363
Sparspak = "0.3.11"
6464
StaticArrays = "1.9.8"
6565
Test = "1.10"

docs/src/tutorials/unknown_parameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ y_2(0)=0,\ y_2(\pi)=0
3131

3232
It is worthnoting that in this system, while we have two differetial equations, it isn't enough to estimate the unknown parameters and guarantee a unique numerical solution with only two given boundary conditions. While under the hood, the parameters are estimated simultaneously with the numerical solution, it makes the boundary value problem an underconstrained BVP if the number of constraints are equal to the number of states, which may result in more than one solution. So we should provide additional constraint $y(0)=1$ from the original equation to make sure unique numerical solution and the estimated parameters are we actually wanted.
3333

34-
With BoundaryValueDiffEq.jl, it's easy to solve boundary value problems with unknown parameters, we can just specify `fit_parameters=true` when constructing the BVP and provide the guess of the unknown parameters in `prob.p`, for example, to estimate the unknown parameters in the above BVP system:
34+
With BoundaryValueDiffEq.jl, it's easy to solve boundary value problems with unknown parameters, we can just specify `tune_parameters=true` when constructing the BVP and provide the guess of the unknown parameters in `prob.p`, for example, to estimate the unknown parameters in the above BVP system:
3535

3636
```@example unknown
3737
using BoundaryValueDiffEq, Plots
@@ -49,7 +49,7 @@ function bcb!(res, u, p)
4949
end
5050
guess(p, t) = [cos(4t); -4sin(4t)]
5151
bvp = TwoPointBVProblem(f!, (bca!, bcb!), guess, tspan, [15.0],
52-
bcresid_prototype = (zeros(2), zeros(1)), fit_parameters = true)
52+
bcresid_prototype = (zeros(2), zeros(1)), tune_parameters = true)
5353
sol = solve(bvp, MIRK4(), dt = 0.05)
5454
plot(sol)
5555
```

lib/BoundaryValueDiffEqCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ OptimizationBase = "3.2.0, 4"
4545
PreallocationTools = "0.4.24"
4646
RecursiveArrayTools = "3.27.0"
4747
Reexport = "1.2"
48-
SciMLBase = "2.130.0"
48+
SciMLBase = "2.138.0"
4949
SciMLStructures = "1.7.0"
5050
Setfield = "1"
5151
SparseArrays = "1.10"

lib/BoundaryValueDiffEqCore/src/internal_problems.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@inline __default_cost(::Nothing) = (x, p) -> 0.0
22
@inline __default_cost(f) = f
33
@inline __build_cost(::Nothing, cache, mesh, M; kwargs...) = (x, p) -> 0.0
4-
@inline function __build_cost(fun, cache, mesh, M; fit_parameters = false, p = nothing)
5-
if fit_parameters && SciMLStructures.isscimlstructure(p)
6-
# When fit_parameters=true, the state vector is augmented with tunable params
4+
@inline function __build_cost(fun, cache, mesh, M; tune_parameters = false, p = nothing)
5+
if tune_parameters && SciMLStructures.isscimlstructure(p)
6+
# When tune_parameters=true, the state vector is augmented with tunable params
77
# Extract them and use SciMLStructures.replace to update p for the cost function
88
tunable_part, _ = SciMLStructures.canonicalize(SciMLStructures.Tunable(), p)
99
l_params = length(tunable_part)
@@ -16,10 +16,10 @@
1616
eval_sol = EvalSol(newy, mesh, cache)
1717
return fun(eval_sol, new_p)
1818
end
19-
elseif fit_parameters && !isnothing(p)
19+
elseif tune_parameters && !isnothing(p)
2020
length_u = M - length(p)
2121
cost_fun = @views function (u, p)
22-
# When fit_parameters=true, the state vector is augmented with tunable params
22+
# When tune_parameters=true, the state vector is augmented with tunable params
2323
newy = eachcol(reshape(u, M, :))
2424
params_from_u = u[(length_u + 1):M]
2525
eval_sol = EvalSol(newy, mesh, cache)

lib/BoundaryValueDiffEqCore/src/utils.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,52 +290,52 @@ function __extract_problem_details(prob, u0::AbstractVectorOfArray; kwargs...)
290290
end
291291
function __extract_problem_details(
292292
prob, u0::AbstractArray; dt = 0.0,
293-
check_positive_dt::Bool = false, fit_parameters::Bool = false
293+
check_positive_dt::Bool = false, tune_parameters::Bool = false
294294
)
295295
# Problem does not have Initial Guess
296296
check_positive_dt && dt 0 && throw(ArgumentError("dt must be positive"))
297297
t₀, t₁ = prob.tspan
298-
if fit_parameters
298+
if tune_parameters
299299
prob.p isa SciMLBase.NullParameters &&
300-
throw(ArgumentError("`fit_parameters` is true but `prob.p` is not set."))
300+
throw(ArgumentError("`tune_parameters` is true but `prob.p` is not set."))
301301
new_u = vcat(u0, __tunable_part(prob.p))
302302
return Val(false), eltype(new_u), length(new_u), Int(cld(t₁ - t₀, dt)), new_u
303303
end
304304
return Val(false), eltype(u0), length(u0), Int(cld(t₁ - t₀, dt)), prob.u0
305305
end
306306
function __extract_problem_details(
307307
prob, f::F; dt = 0.0, check_positive_dt::Bool = false,
308-
fit_parameters::Bool = false
308+
tune_parameters::Bool = false
309309
) where {F <: Function}
310310
# Problem passes in a initial guess function
311311
check_positive_dt && dt 0 && throw(ArgumentError("dt must be positive"))
312312

313-
u0 = __initial_guess(f, prob.p, prob.tspan[1]; fit_parameters = fit_parameters)
313+
u0 = __initial_guess(f, prob.p, prob.tspan[1]; tune_parameters = tune_parameters)
314314
t₀, t₁ = prob.tspan
315315
return Val(true), eltype(u0), length(u0), Int(cld(t₁ - t₀, dt)), u0
316316
end
317317

318318
function __extract_problem_details(
319319
prob, u0::SciMLBase.ODESolution; dt = 0.0,
320-
check_positive_dt::Bool = false, fit_parameters::Bool = false
320+
check_positive_dt::Bool = false, tune_parameters::Bool = false
321321
)
322322
# Problem passes in a initial guess function
323323
_u0 = first(u0.u)
324324
_t = u0.t
325-
if fit_parameters
325+
if tune_parameters
326326
prob.p isa SciMLBase.NullParameters &&
327-
throw(ArgumentError("`fit_parameters` is true but `prob.p` is not set."))
327+
throw(ArgumentError("`tune_parameters` is true but `prob.p` is not set."))
328328
new_u = vcat(_u0, __tunable_part(prob.p))
329329
return Val(false), eltype(new_u), length(new_u), Int(cld(t₁ - t₀, dt)), new_u
330330
end
331331
return Val(true), eltype(_u0), length(_u0), (length(_t) - 1), _u0
332332
end
333333

334-
function __initial_guess(f::F, p::P, t::T; fit_parameters = false) where {F, P, T}
334+
function __initial_guess(f::F, p::P, t::T; tune_parameters = false) where {F, P, T}
335335
if hasmethod(f, Tuple{P, T})
336-
if fit_parameters
336+
if tune_parameters
337337
p isa SciMLBase.NullParameters &&
338-
throw(ArgumentError("`fit_parameters` is true but `prob.p` is not set."))
338+
throw(ArgumentError("`tune_parameters` is true but `prob.p` is not set."))
339339
return vcat(f(p, t), __tunable_part(p))
340340
end
341341
return f(p, t)
@@ -346,9 +346,9 @@ function __initial_guess(f::F, p::P, t::T; fit_parameters = false) where {F, P,
346346
removed in the next major release of SciMLBase.",
347347
:__initial_guess
348348
)
349-
if fit_parameters
349+
if tune_parameters
350350
p isa SciMLBase.NullParameters &&
351-
throw(ArgumentError("`fit_parameters` is true but `prob.p` is not set."))
351+
throw(ArgumentError("`tune_parameters` is true but `prob.p` is not set."))
352352
return vcat(f(t), __tunable_part(p))
353353
end
354354
return f(t)

lib/BoundaryValueDiffEqFIRK/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Random = "1.10"
5454
ReTestItems = "1.23.1"
5555
RecursiveArrayTools = "3.27.0"
5656
Reexport = "1.2"
57-
SciMLBase = "2.130.0"
57+
SciMLBase = "2.138.0"
5858
SciMLStructures = "1.7.0"
5959
Setfield = "1.1.1"
6060
SparseArrays = "1.10"

0 commit comments

Comments
 (0)