Skip to content

1274 Normalizing of exposure rate #1283

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/benchmarks/abm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ void abm_benchmark(benchmark::State& state, size_t num_persons, std::initializer
std::cout << "num_persons = " << num_persons << "\n";
for (auto inf_state = 0; inf_state < (int)mio::abm::InfectionState::Count; inf_state++) {
std::cout << "inf_state = " << inf_state << ", sum = "
<< sim.get_model().get_subpopulation_combined(sim.get_time(),
mio::abm::InfectionState(inf_state))
<< sim.get_model().get_subpopulation_inf_state_combined(sim.get_time(),
mio::abm::InfectionState(inf_state))
<< "\n";
}
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/graph_abm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct Logger : mio::LogAlways {
for (size_t i = 0; i < static_cast<size_t>(mio::abm::InfectionState::Count); ++i) {
auto inf_state = mio::abm::InfectionState(i);
persons_per_infection_state.insert(
{inf_state, sim.get_model().get_subpopulation(loc.get_id(), t, inf_state)});
{inf_state, sim.get_model().get_subpopulation_inf_state(loc.get_id(), t, inf_state)});
}
location_information.push_back(std::make_tuple(loc.get_model_id(), loc.get_type(), loc.get_id(),
sim.get_model().get_number_persons(loc.get_id()),
Expand Down
4 changes: 2 additions & 2 deletions cpp/models/abm/common_abm_loggers.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ struct LogInfectionState : mio::LogAlways {
PRAGMA_OMP(for)
for (auto& location : sim.get_model().get_locations()) {
for (uint32_t inf_state = 0; inf_state < (int)mio::abm::InfectionState::Count; inf_state++) {
sum[inf_state] += sim.get_model().get_subpopulation(location.get_id(), curr_time,
mio::abm::InfectionState(inf_state));
sum[inf_state] += sim.get_model().get_subpopulation_inf_state(location.get_id(), curr_time,
mio::abm::InfectionState(inf_state));
}
}
return std::make_pair(curr_time, sum);
Expand Down
15 changes: 11 additions & 4 deletions cpp/models/abm/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ void Model::compute_exposure_caches(TimePoint t, TimeSpan dt)
get_location(person.get_location()), t, dt);
}
} // implicit taskloop barrier

// 3) normalize the exposure caches
PRAGMA_OMP(taskloop)
for (size_t i = 0; i < num_locations; ++i) {
}

} // implicit single barrier
}

Expand Down Expand Up @@ -341,19 +347,20 @@ LocationId Model::find_location(LocationType type, const PersonId person) const
return find_location(type, get_person(person));
}

size_t Model::get_subpopulation_combined(TimePoint t, InfectionState s) const
size_t Model::get_subpopulation_inf_state_combined(TimePoint t, InfectionState s) const
{
return std::accumulate(m_locations.begin(), m_locations.end(), (size_t)0,
[t, s, this](size_t running_sum, const Location& loc) {
return running_sum + get_subpopulation(loc.get_id(), t, s);
return running_sum + get_subpopulation_inf_state(loc.get_id(), t, s);
});
}

size_t Model::get_subpopulation_combined_per_location_type(TimePoint t, InfectionState s, LocationType type) const
size_t Model::get_subpopulation_inf_state_combined_per_location_type(TimePoint t, InfectionState s,
LocationType type) const
{
return std::accumulate(
m_locations.begin(), m_locations.end(), (size_t)0, [t, s, type, this](size_t running_sum, const Location& loc) {
return loc.get_type() == type ? running_sum + get_subpopulation(loc.get_id(), t, s) : running_sum;
return loc.get_type() == type ? running_sum + get_subpopulation_inf_state(loc.get_id(), t, s) : running_sum;
});
}

Expand Down
21 changes: 18 additions & 3 deletions cpp/models/abm/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,16 @@ class Model
* @param[in] t Specified #TimePoint.
* @param[in] s Specified #InfectionState.
*/
size_t get_subpopulation_combined(TimePoint t, InfectionState s) const;
size_t get_subpopulation_inf_state_combined(TimePoint t, InfectionState s) const;

/**
* @brief Get the number of Persons in one #InfectionState at all Location%s of a type.
* @param[in] t Specified #TimePoint.
* @param[in] s Specified #InfectionState.
* @param[in] type Specified #LocationType.
*/
size_t get_subpopulation_combined_per_location_type(TimePoint t, InfectionState s, LocationType type) const;
size_t get_subpopulation_inf_state_combined_per_location_type(TimePoint t, InfectionState s,
LocationType type) const;

/**
* @brief Get the mobility data.
Expand Down Expand Up @@ -379,14 +380,28 @@ class Model
* @param[in] state #InfectionState of interest.
* @return Amount of Person%s of the #InfectionState in all Cell%s of the Location.
*/
size_t get_subpopulation(LocationId location, TimePoint t, InfectionState state) const
size_t get_subpopulation_inf_state(LocationId location, TimePoint t, InfectionState state) const
{
return std::count_if(m_persons.begin(), m_persons.end(), [&](auto&& p) {
return p.get_location_model_id() == m_id && p.get_location() == location &&
p.get_infection_state(t) == state;
});
}

/**
* @brief Get the number of Person%s of a particular #AgeGrou for all Cell%s.
* @param[in] location A LocationId from the Model.
* @param[in] t TimePoint of querry.
* @param[in] agegroup #AgeGroup of interest.
* @return Amount of Person%s of the #InfectionState in all Cell%s of the Location.
*/
size_t get_subpopulation_age(LocationId location, AgeGroup age) const
{
return std::count_if(m_persons.begin(), m_persons.end(), [&](auto&& p) {
return p.get_location_model_id() == m_id && p.get_location() == location && p.get_age() == age;
});
}

/**
* @brief Get the total number of Person%s at the Location.
* @param[in] location A LocationId from the Model.
Expand Down
1 change: 0 additions & 1 deletion cpp/models/abm/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class Simulation
}

private:
void store_result_at(TimePoint t);
void evolve_model(TimePoint tmax)
{
auto dt = std::min(m_dt, tmax - m_t);
Expand Down
10 changes: 5 additions & 5 deletions cpp/tests/test_abm_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ TEST_F(TestModel, getSubpopulationCombined)
add_test_person(model, home1, age_group_15_to_34, mio::abm::InfectionState::InfectedNoSymptoms);

// Verify the count of susceptible persons across all School locations.
EXPECT_EQ(model.get_subpopulation_combined_per_location_type(t, mio::abm::InfectionState::Susceptible,
mio::abm::LocationType::School),
EXPECT_EQ(model.get_subpopulation_inf_state_combined_per_location_type(t, mio::abm::InfectionState::Susceptible,
mio::abm::LocationType::School),
3);
// Verify the count of persons with no symptoms across all School locations.
EXPECT_EQ(model.get_subpopulation_combined_per_location_type(t, mio::abm::InfectionState::InfectedNoSymptoms,
mio::abm::LocationType::School),
EXPECT_EQ(model.get_subpopulation_inf_state_combined_per_location_type(
t, mio::abm::InfectionState::InfectedNoSymptoms, mio::abm::LocationType::School),
2);
// Verify the total count of persons with no symptoms across all locations.
EXPECT_EQ(model.get_subpopulation_combined(t, mio::abm::InfectionState::InfectedNoSymptoms), 3);
EXPECT_EQ(model.get_subpopulation_inf_state_combined(t, mio::abm::InfectionState::InfectedNoSymptoms), 3);
}

/**
Expand Down