From ea70d35af2471dfbedf908dc1c980a55f9220fd3 Mon Sep 17 00:00:00 2001 From: Guido Espana Date: Thu, 19 Dec 2024 23:04:19 +0000 Subject: [PATCH] use sample_person in contacts --- README.md | 2 +- src/contact.rs | 8 +++----- src/main.rs | 3 +-- src/transmission_manager.rs | 8 +++++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 12eadb9..5c3fbc9 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This project presents a general transmission model developed in [ixa](https://github.com/CDCgov/ixa), the Center for Forecasting and Outbreak Analytics' agent-based modeling framework. The transmission model goal is to possess time-varying infectioussness, immunity, interventions, and multiple co-circulating pathogens. ## How to run the model -As of 11/29/24, `cargo run -- -i ./input/input.json -o ./output`. There is an optional `-f` or `--force-overwrite` flag that can be +As of 11/29/24, `cargo run -- -c ./input/input.json -o ./output`. There is an optional `-f` or `--force-overwrite` flag that can be passed to force overwriting of reports while in development/testing modes. ## Project Admin diff --git a/src/contact.rs b/src/contact.rs index 9bec65f..6ba3498 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1,4 +1,4 @@ -use ixa::{define_rng, Context, ContextPeopleExt, ContextRandomExt, IxaError, PersonId}; +use ixa::{define_rng, Context, ContextPeopleExt, IxaError, PersonId}; use crate::population_loader::Alive; @@ -26,15 +26,13 @@ impl ContextContactExt for Context { // Get list of eligible people (for now, all alive people). May be expanded in the future // to instead be list of alive people in the transmitter's contact setting or household. // We sample a random person from this list. - let eligible_contacts = self.query_people((Alive, true)); - if eligible_contacts.len() > 1 { + if self.query_people((Alive, true)).len() > 1 { let mut contact_id = transmitter_id; while contact_id == transmitter_id { // In the future, we might like to sample people from the list by weights according // to some contact matrix. We would use sample_weighted instead. We would calculate // the weights _before_ the loop and then sample from the list of people like here. - contact_id = - eligible_contacts[self.sample_range(ContactRng, 0..eligible_contacts.len())]; + contact_id = self.sample_person(ContactRng, (Alive, true))?; } Ok(Some(contact_id)) } else { diff --git a/src/main.rs b/src/main.rs index 2d72629..55bf1c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,14 +17,13 @@ use crate::population_loader::{Age, CensusTract}; #[derive(Args, Debug)] struct CustomArgs { - /// whether force overwrite of output files if they already exist + ///Whether force overwrite of output files if they already exist #[arg(short = 'f', long)] force_overwrite: bool, } fn initialize() -> Result { let mut context = run_with_custom_args(|context, args, custom_args: Option| { - println!("Setting Overwrite parameter"); // Read the global properties. let custom_args = custom_args.unwrap(); // Set the output directory and whether to overwrite the existing file. diff --git a/src/transmission_manager.rs b/src/transmission_manager.rs index d0d0629..f5074f2 100644 --- a/src/transmission_manager.rs +++ b/src/transmission_manager.rs @@ -5,9 +5,11 @@ use ixa::{ }; use statrs::distribution::{ContinuousCDF, Exp, Poisson}; -use crate::contact::ContextContactExt; -use crate::parameters::Parameters; -use crate::population_loader::Alive; +use crate::{ + contact::ContextContactExt, + parameters::Parameters, + population_loader::Alive +}; // Define the possible infectious statuses for a person. // These states refer to the person's infectiousness at a given time