Skip to content

Commit e7b1a5d

Browse files
authored
Merge pull request #4 from DanielVandH/extrapolation
Allow for extrapolation to be enabled
2 parents 417f002 + 1e798fb commit e7b1a5d

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "EpithelialDynamics1D"
22
uuid = "ace8a2d7-7779-48a6-a8a4-cf6831a7e55b"
33
authors = ["Daniel VandenHeuvel <danj.vandenheuvel@gmail.com>"]
4-
version = "1.7.2"
4+
version = "1.8.0"
55

66
[deps]
77
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"

src/statistics.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ end
127127
interp_fnc=(u, t) -> LinearInterpolation{true}(u, t),
128128
smooth_boundary=true)
129129
130-
Computes summary statistics for the node densities from an `EnsembleSolution` to a [`CellProblem`](@ref).
130+
Computes summary statistics for the node densities from an `EnsembleSolution` to a [`CellProblem`](@ref). Any
131+
negative values are set to zero.
131132
132133
# Arguments
133134
- `sol::EnsembleSolution`: The ensemble solution to a `CellProblem`.
@@ -140,6 +141,7 @@ Computes summary statistics for the node densities from an `EnsembleSolution` to
140141
- `alpha::Float64 = 0.05`: The significance level for the confidence intervals.
141142
- `interp_fnc = (u, t) -> LinearInterpolation{true}(u, t)`: The function to use for constructing the interpolant.
142143
- `smooth_boundary::Bool = true`: Whether to use the smooth boundary node densities.
144+
- `extrapolate = false`: Whether to allow for extrapolation when considering evaluating outside the range of cells for a given time and a given simulation.
143145
144146
# Outputs
145147
- `q::Vector{Vector{Vector{Float64}}}`: The node densities for each cell simulation.
@@ -156,7 +158,8 @@ function node_densities(sol::EnsembleSolution;
156158
knots=get_knots(sol, num_knots; indices, stat),
157159
alpha=0.05,
158160
interp_fnc=(u, t) -> LinearInterpolation{true}(u, t),
159-
smooth_boundary=true)
161+
smooth_boundary=true,
162+
extrapolate=false)
160163
q = Vector{Vector{Vector{Float64}}}(undef, length(indices))
161164
r = Vector{Vector{Vector{Float64}}}(undef, length(indices))
162165
Base.Threads.@threads for i in eachindex(indices)
@@ -175,7 +178,7 @@ function node_densities(sol::EnsembleSolution;
175178
cell_positions = r[k][j]
176179
interp = interp_fnc(densities, cell_positions)
177180
for i in eachindex(knots[j])
178-
if knots[j][i] > r[k][j][end]
181+
if !extrapolate && knots[j][i] > r[k][j][end]
179182
q_splines[i, j, k] = 0.0
180183
else
181184
q_splines[i, j, k] = max(0.0, interp(knots[j][i]))

test/step_function.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,42 @@ end
613613
@test quantile(all_q, 0.975) uppers[j][i] rtol = 1e-3
614614
end
615615
end
616+
617+
# Using the average leading edge and allowing extrapolation
618+
L = leading_edges(sol).L
619+
_L = stack(L)
620+
_indices = rand(eachindex(sol), 20)
621+
_L = _L[:, _indices]
622+
_mL = mean.(eachrow(_L))
623+
q, r, means, lowers, uppers, knots = node_densities(sol; indices=_indices, stat=mean, extrapolate=true)
624+
@inferred node_densities(sol; indices=_indices, stat=mean,extrapolate=true)
625+
for j in eachindex(knots)
626+
a = mean(sol[k][j][begin] for k in _indices)
627+
b = mean(sol[k][j][end] for k in _indices)
628+
@test knots[j] LinRange(a, b, 500)
629+
@test knots[j][end] _mL[j]
630+
end
631+
for (enum_k, k) in enumerate(_indices)
632+
for j in rand(1:length(sol[k]), 40)
633+
for i in 1:length(sol[k][j])
634+
if i == 1
635+
@test q[enum_k][j][1] LinearInterpolation([1 / (r[enum_k][j][2] - r[enum_k][j][1]), 2 / (r[enum_k][j][3] - r[enum_k][j][1])], [(r[enum_k][j][1] + r[enum_k][j][2]) / 2, r[enum_k][j][2]])(r[enum_k][j][1])
636+
elseif i == length(sol[k][j])
637+
n = length(sol[k][j])
638+
@test q[enum_k][j][n] LinearInterpolation([2 / (r[enum_k][j][end] - r[enum_k][j][end-2]), 1 / (r[enum_k][j][end] - r[enum_k][j][end-1])], [r[enum_k][j][end-1], (r[enum_k][j][end-1] + r[enum_k][j][end]) / 2])(r[enum_k][j][end])
639+
else
640+
@test q[enum_k][j][i] 2 / (r[enum_k][j][i+1] - r[enum_k][j][i-1])
641+
end
642+
@test r[enum_k][j][i] == sol[k][j][i]
643+
end
644+
end
645+
end
646+
for j in rand(eachindex(mb_sol), 40)
647+
for i in eachindex(knots[j])
648+
all_q = max.(0.0, [LinearInterpolation(q[k][j], r[k][j])(knots[j][i]) for k in eachindex(_indices)])
649+
@test mean(all_q) means[j][i] rtol = 1e-3
650+
@test quantile(all_q, 0.025) lowers[j][i] rtol = 1e-3
651+
@test quantile(all_q, 0.975) uppers[j][i] rtol = 1e-3
652+
end
653+
end
616654
end

0 commit comments

Comments
 (0)