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

Add comparison function #12

Merged
merged 21 commits into from
Sep 18, 2024
Merged

Add comparison function #12

merged 21 commits into from
Sep 18, 2024

Conversation

richfitz
Copy link
Member

@richfitz richfitz commented Aug 23, 2024

#Actual Model
pkgload::load_all()

data <- process_data(readRDS("tests/testthat/weekly.rds"))

pars <- cowflu_inputs(alpha = 0.05, beta = 0.35, gamma = 0.2, sigma = 0.5, asc_rate = 1,
                      dispersion = 1,
                      cowflu_fixed_inputs(p_region_export = movement$p_region_export,
                                          p_cow_export = movement$p_cow_export,
                                          movement_matrix = movement$movement_matrix,
                                          time_test = 136,
                                          n_herds_per_region = usda_data$n_herds_per_region,
                                          n_cows_per_herd = usda_data$n_cows_per_herd,
                                          start_herd = 26940, #26804 is where Texas starts.
                                          start_count = 5,
                                          condition_on_export = TRUE
                                          ))
#pars$time_test <- 136
#pars$n_test <- 0

#Texas starts at herd: usda_data$region_start[41] + 1  = 26804,
#this is with 4 cows in it.
#Currently, if you try and put more start cows in than there exists, it'll do it anyway and have negative in the S.
##TODO: Make a check to catch this.
set.seed(1)
n_particles <- 2
sys <- dust2::dust_system_create(cows(), pars, n_particles = n_particles, dt = 1) # n_threads for parallelism
dust2::dust_system_set_state_initial(sys)

## Check on doing comparison to data; this is just for debugging really.
## Here assuming that you are working with days:
dust2::dust_system_run_to_time(sys, data$day[[1]])
dust2::dust_system_compare_data(sys, list(positive_tests = data$positive_tests[[1]]))

## Run a particle filter
data_day <- dust2::dust_filter_data(data, time = "day")
filter <- dust2::dust_filter_create(cows(), 0, data_day, n_particles = 20, n_threads = 8)
ll <- dust2::dust_likelihood_run(filter, pars)

## or equivalently:
data$time <- data$week
filter <- dust2::dust_filter_create(cows(), 0, data, n_particles = 20, n_threads = 8)
ll <- dust2::dust_likelihood_run(filter, pars)

@richfitz
Copy link
Member Author

richfitz commented Aug 30, 2024

#Actual Model
pkgload::load_all()

data <- process_data(readRDS("tests/testthat/weekly.rds"))

## WEEKLY RATES EVERYWHERE!
pars <- cowflu_inputs(alpha = 0.35,
                      beta = 2.45,
                      gamma = 1.4,
                      sigma = 3.5,
                      asc_rate = 1,
                      dispersion = 1,
                      cowflu_fixed_inputs(p_region_export = movement$p_region_export,
                                          p_cow_export = movement$p_cow_export,
                                          movement_matrix = movement$movement_matrix,
                                          time_test = 136,
                                          n_herds_per_region = usda_data$n_herds_per_region,
                                          n_cows_per_herd = usda_data$n_cows_per_herd,
                                          start_herd = 26940, #26804 is where Texas starts.
                                          start_count = 5,
                                          condition_on_export = TRUE
                                          ))
#pars$time_test <- 136
#pars$n_test <- 0

#Texas starts at herd: usda_data$region_start[41] + 1  = 26804,
#this is with 4 cows in it.
#Currently, if you try and put more start cows in than there exists, it'll do it anyway and have negative in the S.
##TODO: Make a check to catch this.
set.seed(1)
n_particles <- 2
sys <- dust2::dust_system_create(cows(), pars, n_particles = n_particles, dt = 1) # n_threads for parallelism
dust2::dust_system_set_state_initial(sys)

## Check on doing comparison to data; this is just for debugging really.
## Here assuming that you are working with weeks:
dust2::dust_system_run_to_time(sys, data$week[[1]])
dust2::dust_system_compare_data(sys, list(positive_tests = data$positive_tests[[1]]))

data_week <- dust2::dust_filter_data(data, time = "week")
filter <- dust2::dust_filter_create(cows(), 0, data_week,
                                    dt = 0.1, n_particles = 20, n_threads = 8)
ll <- dust2::dust_filter_run(filter, pars)

@richfitz richfitz marked this pull request as ready for review September 18, 2024 13:07
@richfitz richfitz merged commit 61acec9 into main Sep 18, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants