11#include <unordered_map>
40 double max_value = std::numeric_limits<double>::max();
48 std::pair<std::string, std::shared_ptr<RiskFactorSexAgeTable>>;
90 std::shared_ptr<RiskFactorSexAgeTable> expected,
91 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_trend,
92 std::shared_ptr<std::unordered_map<core::Identifier, int>> trend_steps,
93 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_trend_boxcox,
94 const std::vector<core::Identifier> &names,
const std::vector<LinearModelParams> &models,
95 const std::vector<core::DoubleInterval> &ranges,
const std::vector<double> &lambda,
96 const std::vector<double> &stddev,
const Eigen::MatrixXd &cholesky,
97 const std::vector<LinearModelParams> &policy_models,
98 const std::vector<core::DoubleInterval> &policy_ranges,
99 const Eigen::MatrixXd &policy_cholesky,
100 std::shared_ptr<std::vector<LinearModelParams>> trend_models,
101 std::shared_ptr<std::vector<core::DoubleInterval>> trend_ranges,
102 std::shared_ptr<std::vector<double>> trend_lambda,
double info_speed,
103 const std::unordered_map<
core::Identifier, std::unordered_map<core::Gender, double>>
105 const std::unordered_map<core::Income, LinearModelParams> &income_models,
106 double physical_activity_stddev,
TrendType trend_type,
107 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_income_trend =
109 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_income_trend_boxcox =
111 std::shared_ptr<std::unordered_map<core::Identifier, int>> income_trend_steps =
nullptr,
112 std::shared_ptr<std::vector<LinearModelParams>> income_trend_models =
nullptr,
113 std::shared_ptr<std::vector<core::DoubleInterval>> income_trend_ranges =
nullptr,
114 std::shared_ptr<std::vector<double>> income_trend_lambda =
nullptr,
115 std::shared_ptr<std::unordered_map<core::Identifier, double>> income_trend_decay_factors =
122 const std::unordered_map<core::Identifier, PhysicalActivityModel>
123 &physical_activity_models = {},
126 const std::vector<IncomeStratumExpectedTableEntry> &income_stratum_expected_tables = {},
129 bool income_stratum_adjustment_enabled =
false,
131 std::size_t adjustment_income_stratum_count = 0u,
bool has_active_policies =
true,
134 const std::vector<LinearModelParams> &logistic_models = {},
139 std::string
name()
const noexcept override;
150 static double inverse_box_cox(
double factor,
double lambda);
191 bool intervene)
const;
195 void apply_policies(
Person &person,
bool intervene)
const;
198 const std::vector<LinearModelParams> &models)
const;
200 std::vector<double> compute_residuals(
Random &random,
const Eigen::MatrixXd &cholesky)
const;
206 double calculate_zero_probability(
Person &person,
size_t risk_factor_index)
const;
211 void initialise_sector(
Person &person,
Random &random)
const;
216 void update_sector(
Person &person,
Random &random)
const;
219 bool is_continuous_income_model_;
227 double calculate_continuous_income(
Person &person,
Random &random);
234 core::Income convert_income_continuous_to_category(
double continuous_income,
243 core::Income convert_income_to_category(
double continuous_income,
244 const std::vector<double> &quartile_thresholds)
const;
249 static std::vector<double> calculate_income_quartiles(
const Population &population);
254 static std::vector<double> calculate_income_tertiles(
const Population &population);
257 static std::vector<double> calculate_income_percentile_thresholds(
const Population &population,
258 std::size_t bucket_count);
263 void initialise_categorical_income(
Person &person,
Random &random);
284 std::pair<std::vector<core::Identifier>, std::vector<core::DoubleInterval>>
286 const std::vector<core::Identifier> &base_factors,
287 const std::vector<core::DoubleInterval> &base_ranges,
288 bool for_trended_adjustment =
false)
const;
312 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_trend_;
313 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_trend_boxcox_;
314 std::shared_ptr<std::vector<LinearModelParams>> trend_models_;
315 std::shared_ptr<std::vector<core::DoubleInterval>> trend_ranges_;
316 std::shared_ptr<std::vector<double>> trend_lambda_;
320 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_income_trend_;
321 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_income_trend_boxcox_;
322 std::shared_ptr<std::unordered_map<core::Identifier, int>> income_trend_steps_;
323 std::shared_ptr<std::vector<LinearModelParams>> income_trend_models_;
324 std::shared_ptr<std::vector<core::DoubleInterval>> income_trend_ranges_;
325 std::shared_ptr<std::vector<double>> income_trend_lambda_;
326 std::shared_ptr<std::unordered_map<core::Identifier, double>> income_trend_decay_factors_;
329 const std::vector<core::Identifier> &names_;
330 const std::vector<LinearModelParams> &models_;
331 const std::vector<core::DoubleInterval> &ranges_;
332 const std::vector<double> &lambda_;
333 const std::vector<double> &stddev_;
334 const Eigen::MatrixXd &cholesky_;
335 const std::vector<LinearModelParams> &policy_models_;
336 const std::vector<core::DoubleInterval> &policy_ranges_;
337 const Eigen::MatrixXd &policy_cholesky_;
338 const double info_speed_;
339 const std::unordered_map<core::Identifier, std::unordered_map<core::Gender, double>>
341 const std::unordered_map<core::Income, LinearModelParams> &income_models_;
342 const double physical_activity_stddev_;
345 std::unordered_map<core::Identifier, PhysicalActivityModel> physical_activity_models_;
346 bool has_physical_activity_models_ =
false;
348 std::vector<IncomeStratumExpectedTableEntry> income_stratum_expected_tables_;
349 bool income_stratum_adjustment_enabled_{
false};
350 std::size_t adjustment_income_stratum_count_{0};
352 bool has_active_policies_;
356 const std::vector<LinearModelParams> &logistic_models_;
401 std::unique_ptr<RiskFactorSexAgeTable> expected,
402 std::unique_ptr<std::unordered_map<core::Identifier, double>> expected_trend,
403 std::unique_ptr<std::unordered_map<core::Identifier, int>> trend_steps,
404 std::unique_ptr<std::unordered_map<core::Identifier, double>> expected_trend_boxcox,
405 std::vector<core::Identifier> names, std::vector<LinearModelParams> models,
406 std::vector<core::DoubleInterval> ranges, std::vector<double> lambda,
407 std::vector<double> stddev, Eigen::MatrixXd cholesky,
408 std::vector<LinearModelParams> policy_models,
409 std::vector<core::DoubleInterval> policy_ranges, Eigen::MatrixXd policy_cholesky,
410 std::unique_ptr<std::vector<LinearModelParams>> trend_models,
411 std::unique_ptr<std::vector<core::DoubleInterval>> trend_ranges,
412 std::unique_ptr<std::vector<double>> trend_lambda,
double info_speed,
413 std::unordered_map<
core::Identifier, std::unordered_map<core::Gender, double>>
415 std::unordered_map<core::Income, LinearModelParams> income_models,
417 std::unique_ptr<std::unordered_map<core::Identifier, double>> expected_income_trend =
419 std::unique_ptr<std::unordered_map<core::Identifier, double>> expected_income_trend_boxcox =
421 std::unique_ptr<std::unordered_map<core::Identifier, int>> income_trend_steps =
nullptr,
422 std::unique_ptr<std::vector<LinearModelParams>> income_trend_models =
nullptr,
423 std::unique_ptr<std::vector<core::DoubleInterval>> income_trend_ranges =
nullptr,
424 std::unique_ptr<std::vector<double>> income_trend_lambda =
nullptr,
425 std::unique_ptr<std::unordered_map<core::Identifier, double>> income_trend_decay_factors =
427 bool is_continuous_income_model =
false,
430 const std::unordered_map<core::Identifier, PhysicalActivityModel>
431 &physical_activity_models = {},
432 const std::vector<IncomeStratumExpectedTableEntry> &income_stratum_expected_tables = {},
433 bool income_stratum_adjustment_enabled =
false,
434 std::size_t adjustment_income_stratum_count = 0u,
bool has_active_policies =
true,
436 std::vector<LinearModelParams> logistic_models = {},
441 std::unique_ptr<RiskFactorModel>
create_model()
const override;
445 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_trend_;
446 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_trend_boxcox_;
447 std::shared_ptr<std::vector<LinearModelParams>> trend_models_;
448 std::shared_ptr<std::vector<core::DoubleInterval>> trend_ranges_;
449 std::shared_ptr<std::vector<double>> trend_lambda_;
453 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_income_trend_;
454 std::shared_ptr<std::unordered_map<core::Identifier, double>> expected_income_trend_boxcox_;
455 std::shared_ptr<std::unordered_map<core::Identifier, int>> income_trend_steps_;
456 std::shared_ptr<std::vector<LinearModelParams>> income_trend_models_;
457 std::shared_ptr<std::vector<core::DoubleInterval>> income_trend_ranges_;
458 std::shared_ptr<std::vector<double>> income_trend_lambda_;
459 std::shared_ptr<std::unordered_map<core::Identifier, double>> income_trend_decay_factors_;
462 std::vector<core::Identifier> names_;
463 std::vector<LinearModelParams> models_;
464 std::vector<core::DoubleInterval> ranges_;
465 std::vector<double> lambda_;
466 std::vector<double> stddev_;
467 Eigen::MatrixXd cholesky_;
468 std::vector<LinearModelParams> policy_models_;
469 std::vector<core::DoubleInterval> policy_ranges_;
470 Eigen::MatrixXd policy_cholesky_;
472 std::unordered_map<core::Identifier, std::unordered_map<core::Gender, double>>
474 std::unordered_map<core::Income, LinearModelParams> income_models_;
475 double physical_activity_stddev_;
478 std::unordered_map<core::Identifier, PhysicalActivityModel> physical_activity_models_;
479 bool has_physical_activity_models_ =
false;
481 std::vector<IncomeStratumExpectedTableEntry> income_stratum_expected_tables_;
482 bool income_stratum_adjustment_enabled_{
false};
483 std::size_t adjustment_income_stratum_count_{0};
486 std::vector<LinearModelParams> logistic_models_;
489 bool is_continuous_income_model_;
493 bool has_active_policies_;
Defines the virtual population data type.
Definition population.h:19
General purpose Random number generator algorithms.
Definition random_algorithm.h:8
RiskFactorAdjustableModelDefinition(std::unique_ptr< RiskFactorSexAgeTable > expected, std::unique_ptr< std::unordered_map< core::Identifier, double > > expected_trend, std::unique_ptr< std::unordered_map< core::Identifier, int > > trend_steps, TrendType trend_type=TrendType::Null)
Constructs a new RiskFactorAdjustableModelDefinition instance.
Definition risk_factor_adjustable_model.cpp:640
RiskFactorAdjustableModel(std::shared_ptr< RiskFactorSexAgeTable > expected, std::shared_ptr< std::unordered_map< core::Identifier, double > > expected_trend, std::shared_ptr< std::unordered_map< core::Identifier, int > > trend_steps, TrendType trend_type=TrendType::Null, std::shared_ptr< std::unordered_map< core::Identifier, double > > expected_income_trend=nullptr, std::shared_ptr< std::unordered_map< core::Identifier, double > > expected_income_trend_decay_factors=nullptr)
Constructs a new RiskFactorAdjustableModel instance.
Definition risk_factor_adjustable_model.cpp:73
Defines the Simulation runtime context data type.
Definition runtime_context.h:22
StaticLinearModelDefinition(std::unique_ptr< RiskFactorSexAgeTable > expected, std::unique_ptr< std::unordered_map< core::Identifier, double > > expected_trend, std::unique_ptr< std::unordered_map< core::Identifier, int > > trend_steps, std::unique_ptr< std::unordered_map< core::Identifier, double > > expected_trend_boxcox, std::vector< core::Identifier > names, std::vector< LinearModelParams > models, std::vector< core::DoubleInterval > ranges, std::vector< double > lambda, std::vector< double > stddev, Eigen::MatrixXd cholesky, std::vector< LinearModelParams > policy_models, std::vector< core::DoubleInterval > policy_ranges, Eigen::MatrixXd policy_cholesky, std::unique_ptr< std::vector< LinearModelParams > > trend_models, std::unique_ptr< std::vector< core::DoubleInterval > > trend_ranges, std::unique_ptr< std::vector< double > > trend_lambda, double info_speed, std::unordered_map< core::Identifier, std::unordered_map< core::Gender, double > > rural_prevalence, std::unordered_map< core::Income, LinearModelParams > income_models, double physical_activity_stddev, TrendType trend_type=TrendType::Null, std::unique_ptr< std::unordered_map< core::Identifier, double > > expected_income_trend=nullptr, std::unique_ptr< std::unordered_map< core::Identifier, double > > expected_income_trend_boxcox=nullptr, std::unique_ptr< std::unordered_map< core::Identifier, int > > income_trend_steps=nullptr, std::unique_ptr< std::vector< LinearModelParams > > income_trend_models=nullptr, std::unique_ptr< std::vector< core::DoubleInterval > > income_trend_ranges=nullptr, std::unique_ptr< std::vector< double > > income_trend_lambda=nullptr, std::unique_ptr< std::unordered_map< core::Identifier, double > > income_trend_decay_factors=nullptr, bool is_continuous_income_model=false, const LinearModelParams &continuous_income_model=LinearModelParams{}, core::IncomeCategoryLayout income_category_layout={}, const std::unordered_map< core::Identifier, PhysicalActivityModel > &physical_activity_models={}, const std::vector< IncomeStratumExpectedTableEntry > &income_stratum_expected_tables={}, bool income_stratum_adjustment_enabled=false, std::size_t adjustment_income_stratum_count=0u, bool has_active_policies=true, std::vector< LinearModelParams > logistic_models={}, core::Gender gender2_indicator=core::Gender::male)
Initialises a new instance of the StaticLinearModelDefinition class.
Definition static_linear_model.cpp:2402
std::unique_ptr< RiskFactorModel > create_model() const override
Construct a new StaticLinearModel from this definition.
Definition static_linear_model.cpp:2637
std::string name() const noexcept override
Gets the model name.
Definition static_linear_model.cpp:628
bool is_continuous_income_model() const noexcept
Check if using continuous income model (FINCH approach).
Definition static_linear_model.cpp:630
void generate_risk_factors(RuntimeContext &context) override
Generates the initial risk factors for a population and newborns.
Definition static_linear_model.cpp:635
RiskFactorModelType type() const noexcept override
Gets the model type identifier.
Definition static_linear_model.cpp:626
void update_risk_factors(RuntimeContext &context) override
Update risk factors for population.
Definition static_linear_model.cpp:1012
StaticLinearModel(std::shared_ptr< RiskFactorSexAgeTable > expected, std::shared_ptr< std::unordered_map< core::Identifier, double > > expected_trend, std::shared_ptr< std::unordered_map< core::Identifier, int > > trend_steps, std::shared_ptr< std::unordered_map< core::Identifier, double > > expected_trend_boxcox, const std::vector< core::Identifier > &names, const std::vector< LinearModelParams > &models, const std::vector< core::DoubleInterval > &ranges, const std::vector< double > &lambda, const std::vector< double > &stddev, const Eigen::MatrixXd &cholesky, const std::vector< LinearModelParams > &policy_models, const std::vector< core::DoubleInterval > &policy_ranges, const Eigen::MatrixXd &policy_cholesky, std::shared_ptr< std::vector< LinearModelParams > > trend_models, std::shared_ptr< std::vector< core::DoubleInterval > > trend_ranges, std::shared_ptr< std::vector< double > > trend_lambda, double info_speed, const std::unordered_map< core::Identifier, std::unordered_map< core::Gender, double > > &rural_prevalence, const std::unordered_map< core::Income, LinearModelParams > &income_models, double physical_activity_stddev, TrendType trend_type, std::shared_ptr< std::unordered_map< core::Identifier, double > > expected_income_trend=nullptr, std::shared_ptr< std::unordered_map< core::Identifier, double > > expected_income_trend_boxcox=nullptr, std::shared_ptr< std::unordered_map< core::Identifier, int > > income_trend_steps=nullptr, std::shared_ptr< std::vector< LinearModelParams > > income_trend_models=nullptr, std::shared_ptr< std::vector< core::DoubleInterval > > income_trend_ranges=nullptr, std::shared_ptr< std::vector< double > > income_trend_lambda=nullptr, std::shared_ptr< std::unordered_map< core::Identifier, double > > income_trend_decay_factors=nullptr, bool is_continuous_income_model=false, const LinearModelParams &continuous_income_model=LinearModelParams{}, core::IncomeCategoryLayout income_category_layout={}, const std::unordered_map< core::Identifier, PhysicalActivityModel > &physical_activity_models={}, const std::vector< IncomeStratumExpectedTableEntry > &income_stratum_expected_tables={}, bool income_stratum_adjustment_enabled=false, std::size_t adjustment_income_stratum_count=0u, bool has_active_policies=true, const std::vector< LinearModelParams > &logistic_models={}, core::Gender gender2_indicator=core::Gender::male)
Initialises a new instance of the StaticLinearModel class.
Definition static_linear_model.cpp:412
Gender
Enumerates gender types.
Definition forward_type.h:18
@ male
Male.
Definition forward_type.h:23
Income
Enumerates income categories.
Definition forward_type.h:51
Top-level namespace for Health-GPS Console host application.
Definition command_options.cpp:9
std::pair< std::string, std::shared_ptr< RiskFactorSexAgeTable > > IncomeStratumExpectedTableEntry
One expected factors-mean table mapped to a configured income stratum id.
Definition static_linear_model.h:47
RiskFactorModelType
Health GPS risk factor module types enumeration.
Definition risk_factor_model.h:12
TrendType
Defines the trend type enumeration for factors mean adjustment.
Definition risk_factor_adjustable_model.h:29
@ Null
No trends applied to factors mean adjustment.
Definition risk_factor_adjustable_model.h:30
Definition linear_model_eval_options.h:11
Defines the linear model parameters used to initialise risk factors.
Definition static_linear_model.h:18
std::unordered_map< core::Identifier, double > coefficients
Definition static_linear_model.h:20
std::unordered_map< core::Identifier, double > log_coefficients
Definition static_linear_model.h:21
double intercept
Definition static_linear_model.h:19
Defines a virtual population person data type.
Definition person.h:39
Defines the physical activity model parameters.
Definition static_linear_model.h:26
double min_value
Minimum allowed value for physical activity.
Definition static_linear_model.h:37
std::string model_type
Model type: "simple" for India approach, "continuous" for FINCH approach.
Definition static_linear_model.h:28
std::unordered_map< core::Identifier, double > coefficients
Coefficients for each factor (age, gender, region, ethnicity, etc.).
Definition static_linear_model.h:34
double max_value
Maximum allowed value for physical activity.
Definition static_linear_model.h:40
double intercept
Intercept value for the linear model.
Definition static_linear_model.h:31
double stddev
Standard deviation for simple models (India approach).
Definition static_linear_model.h:43
Entity unique identifier data type.
Definition identifier.h:20
Ordered final income buckets for project_requirements.income.categories (3, 4, or 5).
Definition income_category_layout.h:13