Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pogudingleb committed Nov 22, 2023
1 parent 53aaf29 commit 37d72f4
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 49 deletions.
5 changes: 4 additions & 1 deletion src/RationalFunctionFields/RationalFunctionField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ Output:
function check_algebraicity(field, ratfuncs, p)
fgens = generators(field)
base_vars = gens(poly_ring(field))
maxdeg = maximum([max(total_degree(numerator(f)), total_degree(denominator(f))) for f in vcat(ratfuncs, fgens)])
maxdeg = maximum([
max(total_degree(numerator(f)), total_degree(denominator(f))) for
f in vcat(ratfuncs, fgens)
])
# degree of the polynomial whose nonvanishing will be needed for correct result
D = Int(ceil(2 * maxdeg * (length(fgens) + 1)^3 * length(ratfuncs) / (1 - p)))
eval_point = [Nemo.QQ(rand(1:D)) for x in base_vars]
Expand Down
14 changes: 7 additions & 7 deletions src/known_ic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This functions takes the following optional arguments:
"""
function find_identifiable_functions_kic(
ode::ODE{T},
known_ic::Vector{<: Union{T, Generic.Frac{T}}};
known_ic::Vector{<:Union{T, Generic.Frac{T}}};
p::Float64 = 0.99,
seed = 42,
simplify = :standard,
Expand All @@ -51,7 +51,7 @@ end

function _find_identifiable_functions_kic(
ode::ODE{T},
known_ic::Vector{<: Union{T, Generic.Frac{T}}};
known_ic::Vector{<:Union{T, Generic.Frac{T}}};
p::Float64 = 0.99,
seed = 42,
simplify = :standard,
Expand All @@ -71,7 +71,9 @@ function _find_identifiable_functions_kic(
)

id_funcs = simplified_generating_set(
RationalFunctionField(vcat(id_funcs_general, [f // one(parent(ode)) for f in known_ic])),
RationalFunctionField(
vcat(id_funcs_general, [f // one(parent(ode)) for f in known_ic]),
),
p = half_p,
seed = seed,
simplify = simplify,
Expand Down Expand Up @@ -101,7 +103,7 @@ The function returns an (ordered) dictionary from the functions to check to thei
"""
function assess_identifiability_kic(
ode::ODE{P},
known_ic::Vector{<: Union{P, Generic.Frac{P}}};
known_ic::Vector{<:Union{P, Generic.Frac{P}}};
funcs_to_check = Vector(),
p::Float64 = 0.99,
loglevel = Logging.Info,
Expand All @@ -120,7 +122,7 @@ end

function _assess_identifiability_kic(
ode::ODE{P},
known_ic::Vector{<: Union{P, Generic.Frac{P}}};
known_ic::Vector{<:Union{P, Generic.Frac{P}}};
funcs_to_check = Vector(),
p::Float64 = 0.99,
) where {P <: MPolyElem{fmpq}}
Expand Down Expand Up @@ -154,5 +156,3 @@ function _assess_identifiability_kic(
@info "Assessing identifiability with known initial conditions concluded in $((time_ns() - runtime_start) / 1e9) seconds"
return result
end


3 changes: 2 additions & 1 deletion src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ function replace_with_ic(ode, funcs)
end
end
R0, vars0 = PolynomialRing(base_ring(ode.poly_ring), [p[2] for p in varnames])
eval_dict = Dict(str_to_var(p[1], ode.poly_ring) => str_to_var(p[2], R0) for p in varnames)
eval_dict =
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]
end
26 changes: 16 additions & 10 deletions test/check_algebraicity.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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([[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],
))
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
Expand Down
75 changes: 45 additions & 30 deletions test/known_ic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,62 @@ ode = @ODEmodel(
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]),
))
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)
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 => [],
: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),
))
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]])
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
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

0 comments on commit 37d72f4

Please sign in to comment.