Skip to content

Commit

Permalink
Hodge podge commit
Browse files Browse the repository at this point in the history
- tidy main loop #5
- more grammar and style #4
- fill in more framework of demonstration model #6
  • Loading branch information
aaronsheldon committed May 5, 2020
1 parent 13f6d2a commit 5597deb
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 46 deletions.
8 changes: 4 additions & 4 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[FillArrays]]
deps = ["LinearAlgebra", "Random", "SparseArrays"]
git-tree-sha1 = "51cc2f9bc4eb9c6c0e81ec2f779d1085583cc956"
git-tree-sha1 = "5322d34d7600d3429665b37bcf7628dc602a28cc"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.8.7"
version = "0.8.8"

[[FixedPointNumbers]]
git-tree-sha1 = "3ba9ea634d4c8b289d590403b4a06f8e227a6238"
Expand Down Expand Up @@ -487,9 +487,9 @@ version = "0.8.0"

[[StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "4118cba3529e99af61aea9a83f7bfd3cff5ffb28"
git-tree-sha1 = "5c06c0aeb81bef54aed4b3f446847905eb6cbda0"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "0.12.2"
version = "0.12.3"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
Expand Down
Binary file modified docs/GompertzProcesses.pdf
Binary file not shown.
26 changes: 13 additions & 13 deletions docs/GompertzProcesses.tex
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
\section{Preliminaries}
Basic science experiments in biology have ubiquitously observed that organisms respond to
environmental stresses, including communicable diseases and exposures to toxins, with an
acceleration $a$ in their failure time $a h\left(a t\right)$, where $h$ is the unperturbed
hazard rate of the failure event. Outside of the controlled setting of a laboratory the
environmental stresses occur stochastically, resulting in a stochastic sequence of
accelerations $a_n$ of the organism's metabolic time. The stochastic accelerations can
either increase the rate of failure $a_n > 1$, an exacerbation of the stresses, or
decrease the rate of failure $a_n < 1$, an alleviation from the stresses. However, even in
the controlled setting of a laboratory it is experimentally challenging to directly
measure the stochastically accelerated metabolic time of the organism, instead we only
have access to the failure events measured at bare time units. Thus a theory of ageing
must study the subordination of the failure time by a stochastically accelerated metabolic
time.
acceleration $a$ in their failure time $a h\left(a t\right)$, where $h\left(t\right)$ is
the unperturbed hazard rate of the failure event. Outside of the controlled setting of a
laboratory the environmental stresses occur stochastically, resulting in a stochastic
sequence of accelerations $a_n$ of the organism's metabolic time. The stochastic
accelerations can either increase the rate of failure $a_n > 1$, an exacerbation of the
stresses, or decrease the rate of failure $a_n < 1$, an alleviation from the stresses.
However, even in the controlled setting of a laboratory it is experimentally challenging
to directly measure the stochastically accelerated metabolic time of the organism, instead
we only have access to the failure events measured at bare time units. Thus a theory of
ageing must study the subordination of the failure time by a stochastically accelerated
metabolic time.

Over the course of an organism's lifetime it will encounter exacerbations and alleviations
that stochastically accelerate $a_n,\dots,a_0=1$ metabolic time at times
Expand Down Expand Up @@ -576,8 +576,8 @@
function.

\section{Hazard Rate}
Consider the first passage stopping time $T_1$ of the Gompertz process $G_t$, its
cumulative distribution is the characteristic function of $Y_t$:
Consider the first passage stopping time $T_1$ of the Gompertz process $G_t$, its tail
distribution is the characteristic function of $Y_t$:
\begin{IEEEeqnarray}{rCl}
\operatorname{\mathbb{P}}\left[ T_1 \ge t\right]
& = &
Expand Down
55 changes: 49 additions & 6 deletions src/CommunicableDisease.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ const parameterontology = ( head = [ "Decomposition" "Process" "Met
"Endogenous" "Infection" "Acceleration" "Dimensionless";
"Exogenous" "Infection" "Contact Rate" "Contacts per Person Day";
"Exogenous" "Infection" "Supression Ratio" "Dimensionless";
"Endogenous" "Acute Bed" "Refraction Rate" "Availabilities per Bed Day"; ] )
"Endogenous" "Acute Bed" "Refraction Rate" "Availabilities per Bed Day" ] )

const parameterestimates = ( head = [ "Value" ],
const parameterestimates = ( head = [ "Value" ],
body = [ 1.0/32000.0;
7.0;
1.0/320.0;
Expand All @@ -73,7 +73,18 @@ const parameterestimates = ( head = [ "Value" ],
1.3;
1.0/10.0;
1.0/3.0;
2.0; ] )
2.0 ] )

const configurationontology = ( head = [ "Name" "Description" "Units" ],
body = [ "Time Step" "Eapsed time of a single iteration." "Days";
"Step Count" "Total iterations to evolve." "Dimensionless";
"Cohort Gestation" "Elapsed time to add a new cohort." "Days" ] )

const configurationvalues = ( head = [ "Value" ],
body = [ 1;
730;
365 ] )

"""
markdowntable(t)
Expand All @@ -89,9 +100,41 @@ function markdowntable(t)
display("text/markdown", s)
end

function hazardrate end
function scatterrate end
function birthrate end
"""
hazardrate(p)
The hazard rate matrix is spectrally decomposed into 6 age-Eigen function matrices,
each mapping 11 states to 11 states.
"""
function hazardrate(p::population{Int64, Vector{Int64}, Matrix{Int64}, Array{Float64, 3}})
zeros(Float64, 6, 11,11)
end

"""
scatterrate(a)
The scattering rate decomposes the hazard rate into 6 age scattering cross sections.
"""
function scatterrate(a::Int64)
zeros(Float64, 6)
end

"""
birthrate(p)
The birth rate is constant and zero for all states except the first, susceptible, which
contains the daily average births.
"""
function birthrate(p::population{Int64, Vector{Int64}, Matrix{Int64}, Array{Float64, 3}})
zeros(Int64, 11)
end

"""
runengine
Run the simulation. At each step coerce the returned population into a dimensional
vector store and write to disk.
"""
function runengine end

end
45 changes: 45 additions & 0 deletions src/vonFoersterHazards.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,24 @@
"CommunicableDisease.markdowntable(CommunicableDisease.parameterestimates)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"CommunicableDisease.markdowntable(CommunicableDisease.configurationontology)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"CommunicableDisease.markdowntable(CommunicableDisease.configurationvalues)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1377,6 +1395,15 @@
"?birthrate"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"?CommunicableDisease.birthrate"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1430,6 +1457,15 @@
"?scatterrate"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"?CommunicableDisease.scatterrate"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1484,6 +1520,15 @@
"?hazardrate"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"?CommunicableDisease.hazardrate"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
50 changes: 27 additions & 23 deletions src/vonFoersterHazards.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,50 +228,54 @@ function Base.iterate(E::abstractevolve)
end
function Base.iterate(E::abstractevolve, S)
(S[1] <= E.count) || return nothing

# One time computation of the exogenous birth rate
b = birthrate(S[2])

# One time computation of the exogenous hazard rates
H = hazardrate(S[2])

# Curried transition function
function t(c)
P = exp(-E.size * sum(scatterrate(c.age) .* H, dims=1)[1, :, :])
cohort(
c.elapsed + E.size,
c.age + E.size,
conservesum!(randomtruncate.(P * c.stratum), c.stratum, c.conserving),
covariance(c.covariance, P, c.stratum)
)
end

# Compute the transitions within each cohort
S[2] .= t.(S[2])

# Youngest cohort is less than gestation time old, add births to youngest cohort
if S[1].ages[end] < E.gestation
# # # Curried transition function to update the cohort. # # # # # # # # # # # # # # #
function transitioncohort(c) #
P = exp(-E.size * sum(scatterrate(c.age) .* H, dims=1)[1, :, :]) #
cohort( #
c.elapsed + E.size, #
c.age + E.size, #
conservesum!(randomtruncate.(P * c.stratum), c.stratum, c.conserving), #
covariance(c.covariance, P, c.stratum), #
S[2].conserving #
) #
end #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# # # Main loop compute the transitions within each cohort. # # # # # # # # # # # # #
S[2] .= transitioncohort.(S[2]) #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Pass the pointers, youngest cohort is less than gestation time old, keep the cohorts
if S[2].ages[end] < E.gestation
R = population(
S[2] + E.size,
S[2].ages,
S[2].strata,
S[2].covariances,
S[2].conserving
)
R.cohorts[end, :] .= R.cohorts[end, :] .+ b'

# Youngest cohort is more than gestation time old, generate a new youngest cohort
# Pass the pointers, youngest cohort is more than gestation time old, add a cohort
else
R = population(
S[2] + E.size,
S[2].ages,
[S[2].strata; b'],
[S[2].ages; zero(eltype(S[2].ages))],
[S[2].strata; zeros(eltype(S[2].strata), 1, size(S[2].strata, 2))],
[S[2].covariances; zeros(eltype(S[2].covariances), 1, size(S[2].covariances, 2), size(S[2].covariances, 3))],
S[2].conserving
)
push!(R.ages, 0)
end


# Add births to the youngest cohort
R.strata[end, :] .= R.strata[end, :] .+ b'

# Send
(R, (1 + S[1], R))
end
Expand Down

0 comments on commit 5597deb

Please sign in to comment.