Skip to content

Commit

Permalink
use sample_person in contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
confunguido committed Dec 19, 2024
1 parent 0fdebe2 commit ea70d35
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/contact.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Context, IxaError> {
let mut context = run_with_custom_args(|context, args, custom_args: Option<CustomArgs>| {
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.
Expand Down
8 changes: 5 additions & 3 deletions src/transmission_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea70d35

Please sign in to comment.