Skip to content

Commit

Permalink
Merge pull request #192 from imperialCHEPI/remove_proxy_name
Browse files Browse the repository at this point in the history
Remove 'proxy' risk factor key mechanism
  • Loading branch information
jamesturner246 authored Jul 31, 2023
2 parents aa71c14 + 011d599 commit 8cdb171
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 125 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,6 @@ FodyWeavers.xsd

# Compile commands for clangd language server
compile_commands.json

# Python venv
.venv
26 changes: 15 additions & 11 deletions example/France.Config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,52 +36,56 @@
{
"name": "Gender",
"level": 0,
"proxy": "gender",
"range": [0, 1]
},
{ "name": "Age", "level": 0, "proxy": "age", "range": [1, 87] },
{ "name": "Age2", "level": 0, "proxy": "", "range": [1, 7569] },
{ "name": "Age3", "level": 0, "proxy": "", "range": [1, 658503] },
{
"name": "Age",
"level": 0,
"range": [1, 87]
},
{
"name": "Age2",
"level": 0,
"range": [1, 7569]
},
{
"name": "Age3",
"level": 0,
"range": [1, 658503]
},
{
"name": "SES",
"level": 0,
"proxy": "ses",
"range": [-2.316299, 2.296689]
},
{
"name": "Sodium",
"level": 1,
"proxy": "",
"range": [1.127384, 8.656519]
},
{
"name": "Protein",
"level": 1,
"proxy": "",
"range": [43.50682, 238.4145]
},
{
"name": "Fat",
"level": 1,
"proxy": "",
"range": [45.04756, 382.664098658922]
},
{
"name": "PA",
"level": 2,
"proxy": "",
"range": [22.22314, 9765.512]
},
{
"name": "Energy",
"level": 2,
"proxy": "",
"range": [1326.14051277588, 7522.496]
},
{
"name": "BMI",
"level": 3,
"proxy": "",
"range": [13.88, 39.48983]
}
],
Expand Down
11 changes: 0 additions & 11 deletions example/France.EBHLM.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,56 @@
{
"Name": "Gender",
"Level": 0,
"Proxy": "gender",
"Range": [0, 1]
},
{
"Name": "Age",
"Level": 0,
"Proxy": "age",
"Range": [1, 87]
},
{
"Name": "Age2",
"Level": 0,
"Proxy": "",
"Range": [1, 7569]
},
{
"Name": "Age3",
"Level": 0,
"Proxy": "",
"Range": [1, 658503]
},
{
"Name": "SES",
"Level": 0,
"Proxy": "ses",
"Range": [-2.316299, 2.296689]
},
{
"Name": "Sodium",
"Level": 1,
"Proxy": "",
"Range": [1.127384, 8.656519]
},
{
"Name": "Protein",
"Level": 1,
"Proxy": "",
"Range": [43.50682, 238.4145]
},
{
"Name": "Fat",
"Level": 1,
"Proxy": "",
"Range": [45.04756, 382.664098658922]
},
{
"Name": "PA",
"Level": 2,
"Proxy": "",
"Range": [22.22314, 9765.512]
},
{
"Name": "Energy",
"Level": 2,
"Proxy": "",
"Range": [1326.14051277588, 7522.496]
},
{
"Name": "BMI",
"Level": 3,
"Proxy": "",
"Range": [13.88, 39.48983]
}
],
Expand Down
6 changes: 3 additions & 3 deletions src/HealthGPS.Console/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ ModelInput create_model_input(core::DataTable &input_table, core::Country countr
auto mapping = std::vector<MappingEntry>();
for (auto &item : config.modelling.risk_factors) {
if (item.range.empty()) {
mapping.emplace_back(item.name, item.level, item.proxy);
mapping.emplace_back(item.name, item.level);
} else {
auto boundary = FactorRange{item.range[0], item.range[1]};
mapping.emplace_back(item.name, item.level, item.proxy, boundary);
auto boundary = hgps::OptionalRange{{item.range[0], item.range[1]}};
mapping.emplace_back(item.name, item.level, boundary);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/HealthGPS.Console/jsonparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ void from_json(const json &j, BaselineInfo &p) {

// Risk Factor Modelling
void to_json(json &j, const RiskFactorInfo &p) {
j = json{{"name", p.name}, {"level", p.level}, {"proxy", p.proxy}, {"range", p.range}};
j = json{{"name", p.name}, {"level", p.level}, {"range", p.range}};
}

void from_json(const json &j, RiskFactorInfo &p) {
j.at("name").get_to(p.name);
j.at("level").get_to(p.level);
j.at("proxy").get_to(p.proxy);
j.at("range").get_to(p.range);
}

Expand Down
1 change: 0 additions & 1 deletion src/HealthGPS.Console/poco.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ struct BaselineInfo {
struct RiskFactorInfo {
std::string name;
int level{};
std::string proxy;
std::vector<double> range;
};

Expand Down
11 changes: 2 additions & 9 deletions src/HealthGPS.Tests/HealthGPS.Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
namespace fs = std::filesystem;

static std::vector<hgps::MappingEntry> create_mapping_entries() {
using namespace hgps;
return {MappingEntry("Gender", 0, core::Identifier{"gender"}),
MappingEntry("Age", 0, core::Identifier{"age"}), MappingEntry("SmokingStatus", 1),
MappingEntry("AlcoholConsumption", 1), MappingEntry("BMI", 2)};
return {{"Gender", 0}, {"Age", 0}, {"SmokingStatus", 1}, {"AlcoholConsumption", 1}, {"BMI", 2}};
}

void create_test_datatable(hgps::core::DataTable &data) {
Expand Down Expand Up @@ -291,11 +288,7 @@ TEST(TestHealthGPS, ModuleFactoryRegistry) {
auto ses_mapping = std::map<std::string, std::string>{{"test", builder.name()}};
auto ses = SESDefinition{.fuction_name = "normal", .parameters = std::vector<double>{0.0, 1.0}};

auto mapping = HierarchicalMapping(std::vector<MappingEntry>{
MappingEntry("Year", 0),
MappingEntry("Gender", 0, core::Identifier{"gender"}),
MappingEntry("Age", 0, core::Identifier{"age"}),
});
auto mapping = HierarchicalMapping({{"Year", 0}, {"Gender", 0}, {"Age", 0}});

auto diseases = std::vector<core::DiseaseInfo>{DiseaseInfo{.group = DiseaseGroup::other,
.code = core::Identifier{"angina"},
Expand Down
11 changes: 1 addition & 10 deletions src/HealthGPS.Tests/HierarchicalMapping.Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
#include "HealthGPS/mapping.h"

static std::vector<hgps::MappingEntry> create_mapping_entries() {
using namespace hgps;
return {MappingEntry("Gender", 0, core::Identifier{"gender"}),
MappingEntry("Age", 0, core::Identifier{"age"}), MappingEntry("SmokingStatus", 1),
MappingEntry("AlcoholConsumption", 1), MappingEntry("BMI", 2)};
return {{"Gender", 0}, {"Age", 0}, {"SmokingStatus", 1}, {"AlcoholConsumption", 1}, {"BMI", 2}};
}

TEST(TestHealthGPS_Mapping, CreateEmpty) {
Expand Down Expand Up @@ -48,9 +45,6 @@ TEST(TestHealthGPS_Mapping, AccessByInterator) {
ASSERT_EQ(exp_size, mapping.size());
for (auto &entry : mapping) {
ASSERT_GE(entry.level(), 0);
if (!entry.is_entity()) {
EXPECT_EQ(entry.key(), entry.entity_key());
}
}
}

Expand All @@ -64,9 +58,6 @@ TEST(TestHealthGPS_Mapping, AccessByConstInterator) {
ASSERT_EQ(exp_size, mapping.size());
for (const auto &entry : mapping) {
ASSERT_GE(entry.level(), 0);
if (!entry.is_entity()) {
EXPECT_EQ(entry.key(), entry.entity_key());
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/HealthGPS/healthgps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void hgps::HealthGPS::print_initial_population_statistics() {

for (const auto &entity : context_.population()) {
for (const auto &entry : context_.mapping()) {
sim8_summary[entry.name()].append(entity.get_risk_factor_value(entry.entity_key()));
sim8_summary[entry.name()].append(entity.get_risk_factor_value(entry.key()));
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/HealthGPS/hierarchical_model_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ void StaticHierarchicalLinearModel::generate_for_entity(RuntimeContext &context,
determ_risk_factors.emplace(InterceptKey, entity.get_risk_factor_value(InterceptKey));
for (const auto &item : context.mapping()) {
if (item.level() < level) {
determ_risk_factors.emplace(item.key(),
entity.get_risk_factor_value(item.entity_key()));
determ_risk_factors.emplace(item.key(), entity.get_risk_factor_value(item.key()));
}
}

Expand Down
29 changes: 7 additions & 22 deletions src/HealthGPS/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,22 @@

namespace hgps {

MappingEntry::MappingEntry(std::string name, int level, core::Identifier entity_key,
FactorRange range)
: name_{name}, name_key_{core::Identifier{name}}, level_{level},
entity_key_{std::move(entity_key)}, range_{range} {}

MappingEntry::MappingEntry(std::string name, int level, core::Identifier entity_key)
: MappingEntry(name, level, entity_key, FactorRange{}) {}

MappingEntry::MappingEntry(std::string name, int level)
: MappingEntry(name, level, core::Identifier::empty(), FactorRange{}) {}
MappingEntry::MappingEntry(std::string name, int level, OptionalRange range)
: name_{std::move(name)}, name_key_{name_}, level_{level}, range_{std::move(range)} {}

const std::string &MappingEntry::name() const noexcept { return name_; }

int MappingEntry::level() const noexcept { return level_; }

const core::Identifier &MappingEntry::entity_key() const noexcept {
return is_entity() ? entity_key_ : name_key_;
}

bool MappingEntry::is_entity() const noexcept { return !entity_key_.is_empty(); }

const core::Identifier &MappingEntry::key() const noexcept { return name_key_; }

const FactorRange &MappingEntry::range() const noexcept { return range_; }
const OptionalRange &MappingEntry::range() const noexcept { return range_; }

double MappingEntry::get_bounded_value(const double &value) const noexcept {
if (range_.empty) {
return value;
if (range_.has_value()) {
return std::min(std::max(value, range_->first), range_->second);
}

return std::min(std::max(value, range_.minimum), range_.maximum);
return value;
}

inline bool operator>(const MappingEntry &lhs, const MappingEntry &rhs) {
Expand Down Expand Up @@ -88,4 +73,4 @@ std::vector<MappingEntry> HierarchicalMapping::at_level(int level) const noexcep
return result;
}

} // namespace hgps
} // namespace hgps
Loading

0 comments on commit 8cdb171

Please sign in to comment.