-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '198-test-for-to_epiweekly_quantile_table' of https://gi…
…thub.com/CDCgov/pyrenew-hew into 198-test-for-to_epiweekly_quantile_table
- Loading branch information
Showing
20 changed files
with
788 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Pipeline Run Check | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
run-pipeline: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
- name: "Set up R" | ||
uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: "release" | ||
use-public-rspm: true | ||
- name: "Install poetry" | ||
run: pip install poetry | ||
- name: "Install pyrenew-hew" | ||
run: poetry install | ||
- name: "Set up Quarto" | ||
uses: quarto-dev/quarto-actions/setup@v2 | ||
- name: "Set up dependencies for hewr" | ||
uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
working-directory: hewr | ||
- name: "Install extra pkgs" | ||
run: | | ||
pak::local_install("hewr", ask = FALSE) | ||
pak::pkg_install("cmu-delphi/epipredict@main", ask = FALSE) | ||
pak::pkg_install("cmu-delphi/epiprocess@main", ask = FALSE) | ||
shell: Rscript {0} | ||
- name: "Run pipeline" | ||
run: poetry run bash pipelines/tests/test_forecast_state.sh pipelines/tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' Generate Exponential Growth Process with Poisson Noise | ||
#' | ||
#' This function generates a sequence of samples from an exponential growth | ||
#' process through Poisson sampling: | ||
#' ```math | ||
#' \begin{aligned} | ||
#' \( \lambda_t &= I_0 \exp(\sum_{t=1}^{t} r_t) \) \\ | ||
#' I_t &\sim \text{Poisson}(\lambda_t). | ||
#' ``` | ||
#' @param rt A numeric vector of exponential growth rates. | ||
#' @param initial A numeric value representing the initial value of the process. | ||
#' | ||
#' @return An integer vector of Poisson samples generated from the exponential | ||
#' growth process. | ||
#' | ||
#' @examples | ||
#' rt <- c(0.1, 0.2, 0.15) | ||
#' initial <- 10 | ||
#' generate_exp_growth_pois(rt, initial) | ||
#' | ||
#' @export | ||
generate_exp_growth_pois <- function(rt, initial) { | ||
means <- initial * exp(cumsum(rt)) | ||
samples <- stats::rpois(length(means), lambda = means) | ||
return(samples) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
test_that("generate_exp_growth_pois generates correct number of samples", { | ||
rt <- c(0.1, 0.2, 0.15) | ||
initial <- 10 | ||
samples <- generate_exp_growth_pois(rt, initial) | ||
expect_length(samples, length(rt)) | ||
}) | ||
|
||
test_that("generate_exp_growth_pois returns a vector of integers", { | ||
rt <- c(0.1, 0.2, 0.15) | ||
initial <- 10 | ||
samples <- generate_exp_growth_pois(rt, initial) | ||
expect_type(samples, "integer") | ||
}) | ||
|
||
test_that("generate_exp_growth_pois does not return implausible values", { | ||
rt <- c(0.1, 0.2, 0.15) | ||
initial <- 10 | ||
analytic_av <- initial * exp(cumsum(rt)) | ||
analytic_std <- sqrt(analytic_av) | ||
samples <- generate_exp_growth_pois(rt, initial) | ||
expect_true(all(samples <= initial + 10 * analytic_std)) | ||
expect_true(all(samples >= initial - 10 * analytic_std)) | ||
}) | ||
|
||
test_that("generate_exp_growth_pois handles empty growth rates", { | ||
rt <- numeric(0) | ||
initial <- 10 | ||
samples <- generate_exp_growth_pois(rt, initial) | ||
expect_equal(samples, numeric(0)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.