Skip to content

Commit

Permalink
fixing the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pogudingleb committed Feb 4, 2024
1 parent f452f75 commit dab25d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
32 changes: 16 additions & 16 deletions src/known_ic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This functions takes the following optional arguments:
- `: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
- `prob_threshold`: 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)
Expand All @@ -29,7 +29,7 @@ This functions takes the following optional arguments:
function find_identifiable_functions_kic(

Check warning on line 29 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L29

Added line #L29 was not covered by tests
ode::ODE{T},
known_ic::Vector{<:Union{T, Generic.Frac{T}}};
p::Float64 = 0.99,
prob_threshold::Float64 = 0.99,
seed = 42,
simplify = :standard,
rational_interpolator = :VanDerHoevenLecerf,
Expand All @@ -41,7 +41,7 @@ function find_identifiable_functions_kic(
return _find_identifiable_functions_kic(

Check warning on line 41 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L38-L41

Added lines #L38 - L41 were not covered by tests
ode,
known_ic,
p = p,
prob_threshold = prob_threshold,
seed = seed,
simplify = simplify,
rational_interpolator = rational_interpolator,
Expand All @@ -52,18 +52,18 @@ end
function _find_identifiable_functions_kic(

Check warning on line 52 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L52

Added line #L52 was not covered by tests
ode::ODE{T},
known_ic::Vector{<:Union{T, Generic.Frac{T}}};
p::Float64 = 0.99,
prob_threshold::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
half_p = 0.5 + prob_threshold / 2
runtime_start = time_ns()
id_funcs_general = find_identifiable_functions(

Check warning on line 64 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L60-L64

Added lines #L60 - L64 were not covered by tests
ode,
p = half_p,
prob_threshold = half_p,
with_states = true,
simplify = simplify,
rational_interpolator = rational_interpolator,
Expand All @@ -74,7 +74,7 @@ function _find_identifiable_functions_kic(
RationalFunctionField(
vcat(id_funcs_general, [f // one(parent(ode)) for f in known_ic]),
),
p = half_p,
prob_threshold = half_p,
seed = seed,
simplify = simplify,
rational_interpolator = rational_interpolator,
Expand All @@ -86,26 +86,26 @@ function _find_identifiable_functions_kic(
end

"""
assess_identifiability_kic(ode, known_ic; funcs_to_check = [], p=0.99, loglevel=Logging.Info)
assess_identifiability_kic(ode, known_ic; funcs_to_check = [], prob_threshold=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.
- `prob_threshold` - 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 result is guaranteed to be correct with the probability at least `prob_threshold`.
The function returns an (ordered) dictionary from the functions to check to their identifiability properties
(one of `:nonidentifiable`, `:locally`, `:globally`).
"""
function assess_identifiability_kic(

Check warning on line 104 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L104

Added line #L104 was not covered by tests
ode::ODE{P},
known_ic::Vector{<:Union{P, Generic.Frac{P}}};
funcs_to_check = Vector(),
p::Float64 = 0.99,
prob_threshold::Float64 = 0.99,
loglevel = Logging.Info,
) where {P <: MPolyElem{fmpq}}
restart_logging(loglevel = loglevel)
Expand All @@ -114,7 +114,7 @@ function assess_identifiability_kic(
return _assess_identifiability_kic(

Check warning on line 114 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L111-L114

Added lines #L111 - L114 were not covered by tests
ode,
known_ic,
p = p,
prob_threshold = prob_threshold,
funcs_to_check = funcs_to_check,
)
end
Expand All @@ -124,18 +124,18 @@ function _assess_identifiability_kic(
ode::ODE{P},
known_ic::Vector{<:Union{P, Generic.Frac{P}}};
funcs_to_check = Vector(),
p::Float64 = 0.99,
prob_threshold::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)

Check warning on line 131 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L129-L131

Added lines #L129 - L131 were not covered by tests
end
half_p = 0.5 + p / 2
id_funcs = _find_identifiable_functions_kic(ode, known_ic, p = half_p)
half_p = 0.5 + prob_threshold / 2
id_funcs = _find_identifiable_functions_kic(ode, known_ic, prob_threshold = half_p)
funcs_to_check = replace_with_ic(ode, funcs_to_check)
result = OrderedDict(f => :globally for f in funcs_to_check)

Check warning on line 136 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L133-L136

Added lines #L133 - L136 were not covered by tests

half_p = 0.5 + p / 2
half_p = 0.5 + half_p / 2
local_result = check_algebraicity(

Check warning on line 139 in src/known_ic.jl

View check run for this annotation

Codecov / codecov/patch

src/known_ic.jl#L138-L139

Added lines #L138 - L139 were not covered by tests
RationalFunctionField([[denominator(f), numerator(f)] for f in id_funcs]),
[f // one(parent(f)) for f in funcs_to_check],
Expand Down
17 changes: 0 additions & 17 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -518,22 +518,6 @@ function difforder(diffpoly::MPolyRingElem, prefix::String)
return max(orders...)
end

function get_measured_quantities(ode::ModelingToolkit.ODESystem)
if any(ModelingToolkit.isoutput(eq.lhs) for eq in ModelingToolkit.equations(ode))
@info "Measured quantities are not provided, trying to find the outputs in input ODE."
return filter(
eq -> (ModelingToolkit.isoutput(eq.lhs)),
ModelingToolkit.equations(ode),
)
else
throw(
error(
"Measured quantities (output functions) were not provided and no outputs were found.",
),
)
end
end

# -----------------------------------------------------------------------------

"""
Expand All @@ -557,4 +541,3 @@ function replace_with_ic(ode, funcs)
Dict(str_to_var(p[1], ode.poly_ring) => str_to_var(p[2], R0) for p in varnames)
return [eval_at_dict(f, eval_dict) for f in funcs]

Check warning on line 542 in src/util.jl

View check run for this annotation

Codecov / codecov/patch

src/util.jl#L542

Added line #L542 was not covered by tests
end

0 comments on commit dab25d5

Please sign in to comment.