Skip to content

Commit

Permalink
Merge pull request #62 from CDCgov/issue58
Browse files Browse the repository at this point in the history
Issue 58: Add new GitHub Actions
  • Loading branch information
seabbs authored Feb 21, 2024
2 parents 11606de + 41e5f52 commit d672c2c
Show file tree
Hide file tree
Showing 23 changed files with 239 additions and 220 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style="sciml"
40 changes: 0 additions & 40 deletions .github/actions/install-julia/action.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/CompatHelper-EpiAware.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Compatibility Helper

on:
schedule:
- cron: '00 * * * *'
issues:
types: [opened, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
compatibility:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: EpiAware
sparse-checkout-cone-mode: false
- name: Move EpiAware to root
run: mv EpiAware/* .
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/cache@v1
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
34 changes: 34 additions & 0 deletions .github/workflows/codecoverage-EpiAware.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Code coverage

on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: EpiAware
sparse-checkout-cone-mode: false
- name: Move EpiAware to root
run: mv EpiAware/* .
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
annotate: true
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
5 changes: 2 additions & 3 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: ./.github/actions/install-julia
with:
version: '1.10.0'
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/cache@v1
- run: julia -e 'using Pkg; Pkg.add("JuliaFormatter")'
- uses: ./.github/actions/pre-commit
36 changes: 26 additions & 10 deletions .github/workflows/test-EpiAware.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
name: Test EpiAware

on:
pull_request:
push:
branches: [main]
branches:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test-EpiAware:
runs-on: ubuntu-latest
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
julia-version: ['1']
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/install-julia
with:
version: '1.10.0'
- name: Run unit tests for EpiAware
run: julia --project=EpiAware -e 'using Pkg; Pkg.test(coverage = true)'
- uses: actions/checkout@v4
with:
sparse-checkout: EpiAware
sparse-checkout-cone-mode: false
- name: Move EpiAware to root
run: mv EpiAware/* .
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
1 change: 1 addition & 0 deletions EpiAware/.JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style="sciml"
3 changes: 3 additions & 0 deletions EpiAware/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# EpiAware

[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
[![Test EpiAware](https://github.com/CDCgov/Rt-without-renewal/actions/workflows/test-EpiAware.yaml/badge.svg)](https://github.com/CDCgov/Rt-without-renewal/actions/workflows/test-EpiAware.yaml)
[![codecov](https://codecov.io/gh/CDCgov/Rt-without-renewal/graph/badge.svg?token=IX4GIA8F0H)](https://codecov.io/gh/CDCgov/Rt-without-renewal)

## Model Diagram

Expand Down
20 changes: 10 additions & 10 deletions EpiAware/src/EpiAware.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ This module provides functionality for calculating Rt (effective reproduction nu
module EpiAware

using Distributions,
Turing,
LogExpFunctions,
LinearAlgebra,
SparseArrays,
Random,
ReverseDiff,
Optim,
Parameters,
QuadGK,
DataFramesMeta
Turing,
LogExpFunctions,
LinearAlgebra,
SparseArrays,
Random,
ReverseDiff,
Optim,
Parameters,
QuadGK,
DataFramesMeta

# Exported utilities
export create_discrete_pmf, default_rw_priors, default_delay_obs_priors, spread_draws
Expand Down
47 changes: 23 additions & 24 deletions EpiAware/src/epimodel.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
abstract type AbstractEpiModel end

struct EpiData{T<:Real,F<:Function}
struct EpiData{T <: Real, F <: Function}
gen_int::Vector{T}
delay_int::Vector{T}
delay_kernel::SparseMatrixCSC{T,Integer}
delay_kernel::SparseMatrixCSC{T, Integer}
cluster_coeff::T
len_gen_int::Integer
len_delay_int::Integer
Expand All @@ -12,44 +12,43 @@ struct EpiData{T<:Real,F<:Function}

#Inner constructors for EpiData object
function EpiData(
gen_int,
delay_int,
cluster_coeff,
time_horizon::Integer,
transformation::Function,
gen_int,
delay_int,
cluster_coeff,
time_horizon::Integer,
transformation::Function
)
@assert all(gen_int .>= 0) "Generation interval must be non-negative"
@assert all(delay_int .>= 0) "Delay interval must be non-negative"
@assert sum(gen_int) 1 "Generation interval must sum to 1"
@assert sum(delay_int) 1 "Delay interval must sum to 1"
@assert sum(gen_int)1 "Generation interval must sum to 1"
@assert sum(delay_int)1 "Delay interval must sum to 1"

K = generate_observation_kernel(delay_int, time_horizon)

new{eltype(gen_int),typeof(transformation)}(
new{eltype(gen_int), typeof(transformation)}(
gen_int,
delay_int,
K,
cluster_coeff,
length(gen_int),
length(delay_int),
time_horizon,
transformation,
transformation
)
end

function EpiData(
gen_distribution::ContinuousDistribution,
delay_distribution::ContinuousDistribution,
cluster_coeff,
time_horizon::Integer;
D_gen,
D_delay,
Δd = 1.0,
transformation::Function = exp,
gen_distribution::ContinuousDistribution,
delay_distribution::ContinuousDistribution,
cluster_coeff,
time_horizon::Integer;
D_gen,
D_delay,
Δd = 1.0,
transformation::Function = exp
)
gen_int =
create_discrete_pmf(gen_distribution, Δd = Δd, D = D_gen) |>
p -> p[2:end] ./ sum(p[2:end])
gen_int = create_discrete_pmf(gen_distribution, Δd = Δd, D = D_gen) |>
p -> p[2:end] ./ sum(p[2:end])
delay_int = create_discrete_pmf(delay_distribution, Δd = Δd, D = D_delay)

return EpiData(gen_int, delay_int, cluster_coeff, time_horizon, transformation)
Expand Down Expand Up @@ -81,11 +80,11 @@ function (epimodel::Renewal)(_Rt, init)
Rt = epimodel.data.transformation.(_Rt)

r_approx = R_to_r(Rt[1], epimodel)
init = I₀ * [exp(-r_approx * t) for t = 0:(epimodel.data.len_gen_int-1)]
init = I₀ * [exp(-r_approx * t) for t in 0:(epimodel.data.len_gen_int - 1)]

function generate_infs(recent_incidence, Rt)
new_incidence = Rt * dot(recent_incidence, epimodel.data.gen_int)
[new_incidence; recent_incidence[1:(epimodel.data.len_gen_int-1)]], new_incidence
[new_incidence; recent_incidence[1:(epimodel.data.len_gen_int - 1)]], new_incidence
end

I_t, _ = scan(generate_infs, init, Rt)
Expand Down
6 changes: 3 additions & 3 deletions EpiAware/src/latent-processes.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function default_rw_priors()
return (
var_RW_dist = truncated(Normal(0.0, 0.05), 0.0, Inf),
init_rw_value_dist = Normal(),
init_rw_value_dist = Normal()
)
end

Expand All @@ -13,8 +13,8 @@ end
rw = Vector{eltype(ϵ_t)}(undef, n)

rw[1] = σ_RW * ϵ_t[1]
for t = 2:n
rw[t] = rw[t-1] + σ_RW * ϵ_t[t]
for t in 2:n
rw[t] = rw[t - 1] + σ_RW * ϵ_t[t]
end
return rw, init, (; σ_RW,)
end
20 changes: 10 additions & 10 deletions EpiAware/src/models.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@model function make_epi_inference_model(
y_t,
epimodel::AbstractEpiModel,
latent_process,
observation_process;
process_priors,
pos_shift = 1e-6,
y_t,
epimodel::AbstractEpiModel,
latent_process,
observation_process;
process_priors,
pos_shift = 1e-6
)
#Latent process
time_steps = epimodel.data.time_horizon
@submodel latent_process, init, latent_process_aux =
latent_process(time_steps; latent_process_priors = process_priors)
@submodel latent_process, init, latent_process_aux = latent_process(
time_steps; latent_process_priors = process_priors)

#Transform into infections
I_t = epimodel(latent_process, init)
Expand All @@ -20,14 +20,14 @@
I_t,
epimodel::AbstractEpiModel;
observation_process_priors = process_priors,
pos_shift = pos_shift,
pos_shift = pos_shift
)

#Generate quantities
return (;
generated_y_t,
I_t,
latent_process,
process_aux = merge(latent_process_aux, generated_y_t_aux),
process_aux = merge(latent_process_aux, generated_y_t_aux)
)
end
15 changes: 7 additions & 8 deletions EpiAware/src/observation-processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ function default_delay_obs_priors()
end

@model function delay_observations(
y_t,
I_t,
epimodel::AbstractEpiModel;
observation_process_priors = default_delay_obs_priors(),
pos_shift = 1e-6,
y_t,
I_t,
epimodel::AbstractEpiModel;
observation_process_priors = default_delay_obs_priors(),
pos_shift = 1e-6
)
#Parameters
neg_bin_cluster_factor ~ observation_process_priors.neg_bin_cluster_factor_prior

#Predictive distribution
case_pred_dists =
(epimodel.data.delay_kernel * I_t) .+ pos_shift .|>
μ -> mean_cc_neg_bin(μ, neg_bin_cluster_factor)
case_pred_dists = (epimodel.data.delay_kernel * I_t) .+ pos_shift .|>
μ -> mean_cc_neg_bin(μ, neg_bin_cluster_factor)

#Likelihood
y_t ~ arraydist(case_pred_dists)
Expand Down
Loading

0 comments on commit d672c2c

Please sign in to comment.