-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Identifiability with known generic initial conditions #249
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d6f7927
first version of find_identifiable_functions_kic
32022c2
tests fixed
pogudingleb 5572d00
Algebraicity check implemented
pogudingleb e720f37
assess_identifiability_kic but no tests yet
pogudingleb d786858
tests
pogudingleb 53aaf29
returning in the form x(0)
pogudingleb 37d72f4
formatting
pogudingleb b0fc443
using dennums_to_fracs
pogudingleb f452f75
Merge branch 'master' into known_ic_generic
pogudingleb dab25d5
fixing the tests
pogudingleb 762c568
refactoring the dispatch
bf930bb
adding docs for known_ic
3b4d971
fixing typos
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
""" | ||
find_identifiable_functions_kic(ode::ODE, known_ic; options...) | ||
|
||
Finds all functions of parameters/initial conditions that are identifiable in the given ODE | ||
system under assumptions that the initial conditions for functions in the list | ||
`known_ic` are known and generic. | ||
|
||
## Options | ||
|
||
This functions takes the following optional arguments: | ||
- `simplify`: The extent to which the output functions are simplified. Stronger | ||
simplification may require more time. Possible options are: | ||
- `:standard`: Default simplification. | ||
- `:weak`: Weak simplification. This option is the fastest, but the output | ||
functions can be quite complex. | ||
- `:strong`: Strong simplification. This option is the slowest, but the output | ||
functions are nice and simple. | ||
- `:absent`: No simplification. | ||
- `p`: A float in the range from 0 to 1, the probability of correctness. Default | ||
is `0.99`. | ||
- `seed`: The rng seed. Default value is `42`. | ||
- `loglevel` - the minimal level of log messages to display (`Logging.Info` by default) | ||
|
||
**This is experimental functionality** | ||
|
||
``` | ||
|
||
""" | ||
function find_identifiable_functions_kic( | ||
ode::ODE{T}, | ||
known_ic::Vector{<:Union{T, Generic.Frac{T}}}; | ||
p::Float64 = 0.99, | ||
seed = 42, | ||
simplify = :standard, | ||
rational_interpolator = :VanDerHoevenLecerf, | ||
loglevel = Logging.Info, | ||
) where {T <: MPolyElem{fmpq}} | ||
restart_logging(loglevel = loglevel) | ||
reset_timings() | ||
with_logger(_si_logger[]) do | ||
return _find_identifiable_functions_kic( | ||
ode, | ||
known_ic, | ||
p = p, | ||
seed = seed, | ||
simplify = simplify, | ||
rational_interpolator = rational_interpolator, | ||
) | ||
end | ||
end | ||
|
||
function _find_identifiable_functions_kic( | ||
ode::ODE{T}, | ||
known_ic::Vector{<:Union{T, Generic.Frac{T}}}; | ||
p::Float64 = 0.99, | ||
seed = 42, | ||
simplify = :standard, | ||
rational_interpolator = :VanDerHoevenLecerf, | ||
) where {T <: MPolyElem{fmpq}} | ||
Random.seed!(seed) | ||
@assert simplify in (:standard, :weak, :strong, :absent) | ||
half_p = 0.5 + p / 2 | ||
runtime_start = time_ns() | ||
id_funcs_general = find_identifiable_functions( | ||
ode, | ||
p = half_p, | ||
with_states = true, | ||
simplify = simplify, | ||
rational_interpolator = rational_interpolator, | ||
seed = seed, | ||
) | ||
|
||
id_funcs = simplified_generating_set( | ||
RationalFunctionField( | ||
vcat(id_funcs_general, [f // one(parent(ode)) for f in known_ic]), | ||
), | ||
p = half_p, | ||
seed = seed, | ||
simplify = simplify, | ||
rational_interpolator = rational_interpolator, | ||
) | ||
|
||
@info "The search for identifiable functions with known initial conditions concluded in $((time_ns() - runtime_start) / 1e9) seconds" | ||
|
||
return replace_with_ic(ode, id_funcs) | ||
end | ||
|
||
""" | ||
assess_identifiability_kic(ode, known_ic; funcs_to_check = [], p=0.99, loglevel=Logging.Info) | ||
|
||
Input: | ||
- `ode` - the ODE model | ||
- `known_ic` - a list of functions for which initial conditions are assumed to be known and generic | ||
- `funcs_to_check` - list of functions to check identifiability for; if empty, all parameters | ||
and states are taken | ||
- `p` - probability of correctness. | ||
- `loglevel` - the minimal level of log messages to display (`Logging.Info` by default) | ||
|
||
Assesses identifiability of parameters and initial conditions of a given ODE model. | ||
The result is guaranteed to be correct with the probability at least `p`. | ||
The function returns an (ordered) dictionary from the functions to check to their identifiability properties | ||
(one of `:nonidentifiable`, `:locally`, `:globally`). | ||
""" | ||
function assess_identifiability_kic( | ||
ode::ODE{P}, | ||
known_ic::Vector{<:Union{P, Generic.Frac{P}}}; | ||
funcs_to_check = Vector(), | ||
p::Float64 = 0.99, | ||
loglevel = Logging.Info, | ||
) where {P <: MPolyElem{fmpq}} | ||
restart_logging(loglevel = loglevel) | ||
reset_timings() | ||
with_logger(_si_logger[]) do | ||
return _assess_identifiability_kic( | ||
ode, | ||
known_ic, | ||
p = p, | ||
funcs_to_check = funcs_to_check, | ||
) | ||
end | ||
end | ||
|
||
function _assess_identifiability_kic( | ||
ode::ODE{P}, | ||
known_ic::Vector{<:Union{P, Generic.Frac{P}}}; | ||
funcs_to_check = Vector(), | ||
p::Float64 = 0.99, | ||
) where {P <: MPolyElem{fmpq}} | ||
runtime_start = time_ns() | ||
if length(funcs_to_check) == 0 | ||
funcs_to_check = vcat(ode.x_vars, ode.parameters) | ||
end | ||
half_p = 0.5 + p / 2 | ||
id_funcs = _find_identifiable_functions_kic(ode, known_ic, p = half_p) | ||
funcs_to_check = replace_with_ic(ode, funcs_to_check) | ||
result = OrderedDict(f => :globally for f in funcs_to_check) | ||
|
||
half_p = 0.5 + p / 2 | ||
local_result = check_algebraicity( | ||
RationalFunctionField([[denominator(f), numerator(f)] for f in id_funcs]), | ||
[f // one(parent(f)) for f in funcs_to_check], | ||
half_p, | ||
) | ||
global_result = field_contains( | ||
RationalFunctionField([[denominator(f), numerator(f)] for f in id_funcs]), | ||
[f // one(parent(f)) for f in funcs_to_check], | ||
half_p, | ||
) | ||
for (i, f) in enumerate(funcs_to_check) | ||
if !local_result[i] | ||
result[f] = :nonidentifiable | ||
elseif !global_result[i] | ||
result[f] = :locally | ||
end | ||
end | ||
@info "Assessing identifiability with known initial conditions concluded in $((time_ns() - runtime_start) / 1e9) seconds" | ||
return result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
cases = [] | ||
|
||
R, (x, y, z) = PolynomialRing(QQ, ["x", "y", "z"]) | ||
push!( | ||
cases, | ||
Dict( | ||
:F => RationalFunctionField([[one(R), x + y, x * y]]), | ||
:funcs => [x // one(R), z // one(R), x^3 - y^3 // one(R), x + z // one(R)], | ||
:correct => [true, false, true, false], | ||
), | ||
) | ||
|
||
push!( | ||
cases, | ||
Dict( | ||
:F => RationalFunctionField([[x, y], [y, z]]), | ||
:funcs => [x // z, (x + y) // z, x // one(R), y // one(R), z // one(R)], | ||
:correct => [true, true, false, false, false], | ||
), | ||
) | ||
|
||
@testset "Algebraicity over a field" begin | ||
for case in cases | ||
@test check_algebraicity(case[:F], case[:funcs], 0.99) == case[:correct] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
cases = [] | ||
|
||
ode = @ODEmodel( | ||
x1'(t) = a * x1(t) - b * x1(t) * x2(t), | ||
x2'(t) = -c * x2(t) + d * x1(t) * x2(t), | ||
y(t) = x1(t) | ||
) | ||
|
||
push!( | ||
cases, | ||
Dict( | ||
:ode => ode, | ||
:known => [x2], | ||
:to_check => [], | ||
:correct_funcs => [a, b, c, d, x1, x2], | ||
:correct_ident => OrderedDict(x => :globally for x in [x1, x2, a, b, c, d]), | ||
), | ||
) | ||
|
||
ode = @ODEmodel(x1'(t) = a + x2(t) + x3(t), x2'(t) = b^2 + c, x3'(t) = -c, y(t) = x1(t)) | ||
|
||
push!( | ||
cases, | ||
Dict( | ||
:ode => ode, | ||
:known => [x2, x3], | ||
:to_check => [], | ||
:correct_funcs => [a, b^2, x1, x2, x3], | ||
:correct_ident => OrderedDict( | ||
x1 => :globally, | ||
x2 => :globally, | ||
x3 => :globally, | ||
a => :globally, | ||
b => :locally, | ||
c => :nonidentifiable, | ||
), | ||
), | ||
) | ||
|
||
push!( | ||
cases, | ||
Dict( | ||
:ode => ode, | ||
:known => [x2, x3], | ||
:to_check => [b^2, x2 * c], | ||
:correct_funcs => [a, b^2, x1, x2, x3], | ||
:correct_ident => OrderedDict(b^2 => :globally, x2 * c => :nonidentifiable), | ||
), | ||
) | ||
|
||
@testset "Identifiable functions with known generic initial conditions" begin | ||
for case in cases | ||
ode = case[:ode] | ||
known = case[:known] | ||
|
||
result_funcs = find_identifiable_functions_kic(ode, known) | ||
correct_funcs = | ||
replace_with_ic(ode, [f // one(parent(ode)) for f in case[:correct_funcs]]) | ||
@test Set(result_funcs) == Set(correct_funcs) | ||
|
||
result_ident = | ||
assess_identifiability_kic(ode, known, funcs_to_check = case[:to_check]) | ||
@test OrderedDict( | ||
replace_with_ic(ode, [k])[1] => v for (k, v) in case[:correct_ident] | ||
) == result_ident | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
dennums_to_fractions