Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multihost API with single host #186

Merged
merged 12 commits into from
Dec 18, 2023
9 changes: 9 additions & 0 deletions R/calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,13 @@ calibrate <- function(infected_years_file,
random_seeds <- create_random_seeds(1)
if (config$use_initial_condition_uncertainty) {
config$infected <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
while (any(config$infected < 0)) {
config$infected <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
}
exposed2 <- matrix_norm_distribution(config$exposed_mean, config$exposed_sd)
while (any(exposed2 < 0)) {
exposed2 <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
}
exposed <- config$exposed
exposed[[config$latency_period + 1]] <- exposed2
config$exposed <- exposed
Expand All @@ -341,6 +347,9 @@ calibrate <- function(infected_years_file,

if (config$use_host_uncertainty) {
config$host <- matrix_norm_distribution(config$host_mean, config$host_sd)
while (any(config$host > config$total_populations)) {
config$host <- matrix_norm_distribution(config$host_mean, config$host_sd)
}
} else {
config$host <- config$host_mean
}
Expand Down
2 changes: 1 addition & 1 deletion R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ create_random_seeds <- function(n) {
matrix_norm_distribution <- function(mean_matrix, sd_matrix) {
new_matrix <-
round(matrix(mapply(function(x, y) {rnorm(x, y, n = 1)}, x = mean_matrix, y = sd_matrix),
nrow(mean_matrix), ncol(mean_matrix)))
nrow(mean_matrix), ncol(mean_matrix)), digits = 0)
new_matrix[is.na(new_matrix)] <- 0
new_matrix[new_matrix < 0] <- 0
return(new_matrix)
Expand Down
9 changes: 9 additions & 0 deletions R/pops.r
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,13 @@ pops <- function(infected_file,

if (config$use_initial_condition_uncertainty) {
config$infected <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
while (any(config$infected < 0)) {
config$infected <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
}
exposed2 <- matrix_norm_distribution(config$exposed_mean, config$exposed_sd)
while (any(exposed2 < 0)) {
exposed2 <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
}
exposed <- config$exposed
exposed[[config$latency_period + 1]] <- exposed2
config$exposed <- exposed
Expand All @@ -384,6 +390,9 @@ pops <- function(infected_file,

if (config$use_host_uncertainty) {
config$host <- matrix_norm_distribution(config$host_mean, config$host_sd)
while (any(config$host > config$total_populations)) {
config$host <- matrix_norm_distribution(config$host_mean, config$host_sd)
}
} else {
config$host <- config$host_mean
}
Expand Down
9 changes: 9 additions & 0 deletions R/pops_multirun.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ pops_multirun <- function(infected_file,

if (config$use_initial_condition_uncertainty) {
config$infected <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
while (any(config$infected < 0)) {
config$infected <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
}
exposed2 <- matrix_norm_distribution(config$exposed_mean, config$exposed_sd)
while (any(exposed2 < 0)) {
exposed2 <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
}
exposed <- config$exposed
exposed[[config$latency_period + 1]] <- exposed2
config$exposed <- exposed
Expand All @@ -239,6 +245,9 @@ pops_multirun <- function(infected_file,

if (config$use_host_uncertainty) {
config$host <- matrix_norm_distribution(config$host_mean, config$host_sd)
while (any(config$host > config$total_populations)) {
config$host <- matrix_norm_distribution(config$host_mean, config$host_sd)
}
} else {
config$host <- config$host_mean
}
Expand Down
9 changes: 9 additions & 0 deletions R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ validate <- function(infected_years_file,

if (config$use_initial_condition_uncertainty) {
config$infected <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
while (any(config$infected < 0)) {
config$infected <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
}
exposed2 <- matrix_norm_distribution(config$exposed_mean, config$exposed_sd)
while (any(exposed2 < 0)) {
exposed2 <- matrix_norm_distribution(config$infected_mean, config$infected_sd)
}
exposed <- config$exposed
exposed[[config$latency_period + 1]] <- exposed2
config$exposed <- exposed
Expand All @@ -258,6 +264,9 @@ validate <- function(infected_years_file,

if (config$use_host_uncertainty) {
config$host <- matrix_norm_distribution(config$host_mean, config$host_sd)
while (any(config$host > config$total_populations)) {
config$host <- matrix_norm_distribution(config$host_mean, config$host_sd)
}
} else {
config$host <- config$host_mean
}
Expand Down
2 changes: 1 addition & 1 deletion inst/cpp/pops-core
Submodule pops-core updated 47 files
+1 −1 .cppcheck_suppressions_cpp.txt
+11 −0 .cppcheck_suppressions_hpp.txt
+4 −3 .github/workflows/cppcheck.yml
+13 −0 .github/workflows/valgrind.yml
+11 −2 CMakeLists.txt
+4 −4 Doxyfile
+532 −0 include/pops/actions.hpp
+2 −0 include/pops/anthropogenic_kernel.hpp
+186 −0 include/pops/competency_table.hpp
+202 −1 include/pops/config.hpp
+4 −3 include/pops/date.hpp
+127 −6 include/pops/environment.hpp
+73 −0 include/pops/environment_interface.hpp
+0 −1 include/pops/gamma_kernel.hpp
+53 −31 include/pops/generator_provider.hpp
+1,171 −0 include/pops/host_pool.hpp
+52 −0 include/pops/host_pool_interface.hpp
+195 −125 include/pops/model.hpp
+63 −0 include/pops/model_type.hpp
+473 −0 include/pops/multi_host_pool.hpp
+2 −0 include/pops/natural_kernel.hpp
+0 −1 include/pops/network.hpp
+121 −0 include/pops/pest_host_table.hpp
+145 −0 include/pops/pest_pool.hpp
+14 −13 include/pops/quarantine.hpp
+436 −573 include/pops/simulation.hpp
+10 −4 include/pops/soils.hpp
+88 −92 include/pops/spread_rate.hpp
+84 −163 include/pops/treatments.hpp
+36 −2 include/pops/utils.hpp
+12 −6 tests/CMakeLists.txt
+151 −0 tests/test_competency_table.cpp
+28 −7 tests/test_environment.cpp
+3 −2 tests/test_generator_provider.cpp
+90 −102 tests/test_model.cpp
+76 −73 tests/test_movements.cpp
+1,571 −0 tests/test_multi_host_model.cpp
+2 −1 tests/test_network.cpp
+3 −6 tests/test_network_kernel.cpp
+5 −8 tests/test_overpopulation_movements.cpp
+44 −8 tests/test_quarantine.cpp
+71 −56 tests/test_simulation.cpp
+4 −14 tests/test_simulation_kernels.cpp
+92 −17 tests/test_soils.cpp
+40 −5 tests/test_spread_rate.cpp
+13 −12 tests/test_survival_rate.cpp
+307 −128 tests/test_treatments.cpp
Loading
Loading