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

932 Get_default of Parameter HighViralLoadProtectionFactor doesn't work as expected #1068

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1211176
Ensure any instance of HighViralLoadProtectionFactor is always initia…
khoanguyen-dev Jul 11, 2024
55076af
Add test for set_space_per_member()
khoanguyen-dev Jul 12, 2024
93846dc
Add test for getPersonalProtectiveFactor
khoanguyen-dev Jul 17, 2024
8443b9b
Merge branch 'main' into 932-get_default-of-parameter-highviralloadpr…
khoanguyen-dev Jul 25, 2024
e0b76ab
Add ExposureType to HighViralLoadProtectionFactor
khoanguyen-dev Jul 25, 2024
e9e0171
Merge branch 'main' into 932-get_default-of-parameter-highviralloadpr…
khoanguyen-dev Aug 5, 2024
5746957
Add data from studies
khoanguyen-dev Aug 5, 2024
0e27395
Add data for abm_braunschweig.cpp
khoanguyen-dev Aug 5, 2024
bd61acf
Remove setting for HighViralLoadProtectionFactor in abm_braunschweig.cpp
khoanguyen-dev Aug 6, 2024
d161958
merge main and fix parameter (de)serialize
DavidKerkmann Aug 7, 2024
f82016d
Fix python bindings
DavidKerkmann Aug 7, 2024
2b4ef0f
Fix python bindings
DavidKerkmann Aug 7, 2024
a39c936
Fix python bindings v3
DavidKerkmann Aug 7, 2024
b9c3ffa
Fix pybinds finally
DavidKerkmann Aug 8, 2024
c178137
Merge branch 'main' into 932-get_default-of-parameter-highviralloadpr…
khoanguyen-dev Oct 11, 2024
3549688
Fix error with merge
khoanguyen-dev Oct 11, 2024
adc1215
Fix error with merge
khoanguyen-dev Oct 11, 2024
a2418d0
Add back correct python bindings of the TestParameters
khoanguyen-dev Oct 17, 2024
ed31f25
Small updates for a commenting error and pycode
khoanguyen-dev Oct 18, 2024
31e1a14
Apply suggestions from code review
DavidKerkmann Nov 14, 2024
e65e51c
merge with main
DavidKerkmann Nov 14, 2024
6a1f99d
Fix test
DavidKerkmann Nov 14, 2024
383ec18
Changed Vaccine to ExposureEvent
DavidKerkmann Nov 15, 2024
536bd2b
Fix import
DavidKerkmann Nov 15, 2024
77072b4
Fix naming
DavidKerkmann Nov 15, 2024
37a12ea
Fix errors
DavidKerkmann Nov 15, 2024
b3ea77d
Yet another fix
DavidKerkmann Nov 15, 2024
6839184
Changes according to discussion
DavidKerkmann Nov 15, 2024
600ab95
Fix error
DavidKerkmann Nov 15, 2024
02e6884
Fix pybinds
DavidKerkmann Nov 15, 2024
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
50 changes: 32 additions & 18 deletions cpp/models/abm/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace abm
* @brief Time that a Person is infected but not yet infectious.
*/
struct IncubationPeriod {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -55,7 +55,7 @@ struct IncubationPeriod {
};

struct InfectedNoSymptomsToSymptoms {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -67,7 +67,7 @@ struct InfectedNoSymptomsToSymptoms {
};

struct InfectedNoSymptomsToRecovered {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -79,7 +79,7 @@ struct InfectedNoSymptomsToRecovered {
};

struct InfectedSymptomsToRecovered {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -91,7 +91,7 @@ struct InfectedSymptomsToRecovered {
};

struct InfectedSymptomsToSevere {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -103,7 +103,7 @@ struct InfectedSymptomsToSevere {
};

struct SevereToCritical {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -115,7 +115,7 @@ struct SevereToCritical {
};

struct SevereToRecovered {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -127,7 +127,7 @@ struct SevereToRecovered {
};

struct CriticalToRecovered {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -139,7 +139,7 @@ struct CriticalToRecovered {
};

struct CriticalToDead {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -151,7 +151,7 @@ struct CriticalToDead {
};

struct RecoveredToSusceptible {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand Down Expand Up @@ -212,7 +212,7 @@ struct InfectivityDistributions {
* @brief Probability that an Infection is detected.
*/
struct DetectInfection {
using Type = CustomIndexArray< UncertainValue<>, VirusVariant, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, VirusVariant, AgeGroup>;
static Type get_default(AgeGroup size)
{
return Type({VirusVariant::Count, size}, 1.);
Expand All @@ -227,7 +227,7 @@ struct DetectInfection {
* @brief Effectiveness of a Mask of a certain MaskType% against an Infection%.
*/
struct MaskProtection {
using Type = CustomIndexArray< UncertainValue<>, MaskType>;
using Type = CustomIndexArray<UncertainValue<>, MaskType>;
static Type get_default(AgeGroup /*size*/)
{
return Type({MaskType::Count}, 1.);
Expand Down Expand Up @@ -296,24 +296,38 @@ struct SeverityProtectionFactor {
*/
struct HighViralLoadProtectionFactor {
using Type = InputFunctionForProtectionLevel;
static auto get_default()

HighViralLoadProtectionFactor()
: function(get_default(0))
{
}

static Type get_default(AgeGroup /*size*/)
{
return Type([](ScalarType /*days*/) -> ScalarType {
return [](ScalarType /*days*/) -> ScalarType {
return 0;
});
};
}

ScalarType operator()(ScalarType days) const
{
return function(days);
}

static std::string name()
{
return "HighViralLoadProtectionFactor";
}

Type function;
};

/**
* @brief Parameters that describe the reliability of a test.
*/
struct TestParameters {
UncertainValue<> sensitivity;
UncertainValue<> specificity;
UncertainValue<> sensitivity;
UncertainValue<> specificity;
};

struct GenericTest {
Expand Down Expand Up @@ -392,7 +406,7 @@ struct QuarantineDuration {
* @brief Parameter for the exponential distribution to decide if a Person goes shopping.
*/
struct BasicShoppingRate {
using Type = CustomIndexArray< UncertainValue<>, AgeGroup>;
using Type = CustomIndexArray<UncertainValue<>, AgeGroup>;
static auto get_default(AgeGroup size)
{
return Type({size}, 1.0);
Expand Down
3 changes: 3 additions & 0 deletions cpp/tests/test_abm_household.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ TEST(TestHouseholds, test_add_household_to_world)
auto household = mio::abm::Household();
household.add_members(member1, 2);
household.add_members(member2, 2);
household.set_space_per_member(10);

auto world = mio::abm::World(num_age_groups);

add_household_to_world(world, household);
auto persons = world.get_persons();

EXPECT_EQ(household.get_space_per_member(), 10);

// Test size
EXPECT_EQ(persons.size(), 4);

Expand Down
34 changes: 18 additions & 16 deletions cpp/tests/test_abm_infection.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2020-2024 MEmilio
*
* Authors: David Kerkmann
* Authors: David Kerkmann, Khoa Nguyen
*
* Contact: Martin J. Kuehn <[email protected]>
*
Expand Down Expand Up @@ -176,8 +176,10 @@ TEST(TestInfection, getPersonalProtectiveFactor)
mio::abm::ExposureType::GenericVaccine, mio::AgeGroup(0), mio::abm::VirusVariant::Wildtype}](0);
auto defaut_severity_protection = params.get<mio::abm::SeverityProtectionFactor>()[{
mio::abm::ExposureType::GenericVaccine, mio::AgeGroup(0), mio::abm::VirusVariant::Wildtype}](0);
ASSERT_NEAR(defaut_infection_protection, 0, 0.0001);
ASSERT_NEAR(defaut_severity_protection, 0, 0.0001);
auto defaut_high_viral_load_protection = params.get<mio::abm::HighViralLoadProtectionFactor>()(0);
EXPECT_NEAR(defaut_infection_protection, 0, 0.0001);
EXPECT_NEAR(defaut_severity_protection, 0, 0.0001);
EXPECT_NEAR(defaut_high_viral_load_protection, 0, 0.0001);

// Test linear interpolation with one node
mio::set_log_level(mio::LogLevel::critical); //this throws an error either way
Expand All @@ -187,7 +189,7 @@ TEST(TestInfection, getPersonalProtectiveFactor)
return mio::linear_interpolation_of_data_set<ScalarType, ScalarType>({{2, 0.91}}, days);
};
auto t = mio::abm::TimePoint(6 * 24 * 60 * 60);
ASSERT_NEAR(person.get_protection_factor(t, mio::abm::VirusVariant::Wildtype, params), 0, 0.001);
EXPECT_NEAR(person.get_protection_factor(t, mio::abm::VirusVariant::Wildtype, params), 0, 0.001);
mio::set_log_level(mio::LogLevel::warn); //this throws an error either way
params.get<mio::abm::InfectionProtectionFactor>()[{mio::abm::ExposureType::GenericVaccine, person.get_age(),
mio::abm::VirusVariant::Wildtype}] =
Expand All @@ -208,47 +210,47 @@ TEST(TestInfection, getPersonalProtectiveFactor)
auto infection_protection_factor = params.get<mio::abm::InfectionProtectionFactor>()[{
latest_protection.first, age_group_15_to_34, mio::abm::VirusVariant::Wildtype}](
t.days() - latest_protection.second.days());
ASSERT_NEAR(infection_protection_factor, 0.91, 0.0001);
ASSERT_NEAR(person.get_protection_factor(t, mio::abm::VirusVariant::Wildtype, params), 0.91, 0.0001);
EXPECT_NEAR(infection_protection_factor, 0.91, 0.0001);
EXPECT_NEAR(person.get_protection_factor(t, mio::abm::VirusVariant::Wildtype, params), 0.91, 0.0001);

t = mio::abm::TimePoint(0) + mio::abm::days(15);
infection_protection_factor = params.get<mio::abm::InfectionProtectionFactor>()[{
latest_protection.first, age_group_15_to_34, mio::abm::VirusVariant::Wildtype}](
t.days() - latest_protection.second.days());
ASSERT_NEAR(infection_protection_factor, 0.8635, 0.0001);
ASSERT_NEAR(person.get_protection_factor(t, mio::abm::VirusVariant::Wildtype, params), 0.8635, 0.0001);
EXPECT_NEAR(infection_protection_factor, 0.8635, 0.0001);
EXPECT_NEAR(person.get_protection_factor(t, mio::abm::VirusVariant::Wildtype, params), 0.8635, 0.0001);

t = mio::abm::TimePoint(0) + mio::abm::days(40);
infection_protection_factor = params.get<mio::abm::InfectionProtectionFactor>()[{
latest_protection.first, age_group_15_to_34, mio::abm::VirusVariant::Wildtype}](
t.days() - latest_protection.second.days());
ASSERT_NEAR(infection_protection_factor, 0, 0.0001);
ASSERT_NEAR(person.get_protection_factor(t, mio::abm::VirusVariant::Wildtype, params), 0, 0.0001);
EXPECT_NEAR(infection_protection_factor, 0, 0.0001);
EXPECT_NEAR(person.get_protection_factor(t, mio::abm::VirusVariant::Wildtype, params), 0, 0.0001);

// Test Parameter SeverityProtectionFactor
t = mio::abm::TimePoint(0) + mio::abm::days(2);
auto severity_protection_factor = params.get<mio::abm::SeverityProtectionFactor>()[{
latest_protection.first, age_group_15_to_34, mio::abm::VirusVariant::Wildtype}](
t.days() - latest_protection.second.days());
ASSERT_NEAR(severity_protection_factor, 0.91, 0.0001);
EXPECT_NEAR(severity_protection_factor, 0.91, 0.0001);

t = mio::abm::TimePoint(0) + mio::abm::days(15);
severity_protection_factor = params.get<mio::abm::SeverityProtectionFactor>()[{
latest_protection.first, age_group_15_to_34, mio::abm::VirusVariant::Wildtype}](
t.days() - latest_protection.second.days());
ASSERT_NEAR(severity_protection_factor, 0.8635, 0.0001);
EXPECT_NEAR(severity_protection_factor, 0.8635, 0.0001);

t = mio::abm::TimePoint(0) + mio::abm::days(40);
severity_protection_factor = params.get<mio::abm::SeverityProtectionFactor>()[{
latest_protection.first, age_group_15_to_34, mio::abm::VirusVariant::Wildtype}](
t.days() - latest_protection.second.days());
ASSERT_NEAR(severity_protection_factor, 0, 0.0001);
EXPECT_NEAR(severity_protection_factor, 0, 0.0001);

// Test Parameter HighViralLoadProtectionFactor
t = mio::abm::TimePoint(0) + mio::abm::days(2);
ASSERT_NEAR(params.get<mio::abm::HighViralLoadProtectionFactor>()(t.days()), 0.91, 0.0001);
EXPECT_NEAR(params.get<mio::abm::HighViralLoadProtectionFactor>()(t.days()), 0.91, 0.0001);
t = mio::abm::TimePoint(0) + mio::abm::days(15);
ASSERT_NEAR(params.get<mio::abm::HighViralLoadProtectionFactor>()(t.days()), 0.8635, 0.0001);
EXPECT_NEAR(params.get<mio::abm::HighViralLoadProtectionFactor>()(t.days()), 0.8635, 0.0001);
t = mio::abm::TimePoint(0) + mio::abm::days(40);
ASSERT_NEAR(params.get<mio::abm::HighViralLoadProtectionFactor>()(t.days()), 0, 0.0001);
EXPECT_NEAR(params.get<mio::abm::HighViralLoadProtectionFactor>()(t.days()), 0, 0.0001);
}
Loading