Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
riskfactor_adjustment_types.h
Go to the documentation of this file.
1 #pragma once
4 
5 #include "map2d.h"
6 #include <vector>
7 
8 namespace hgps {
9 
12 
14 struct BaselineAdjustment final {
16  BaselineAdjustment() = default;
17 
22  : values{std::move(adjustment_table)} {
23  if (values.empty()) {
24  throw std::invalid_argument("The risk factors adjustment table must not be empty.");
25  } else if (values.rows() != 2) {
26  throw std::out_of_range(
27  "The risk factors adjustment definition must contain two tables.");
28  }
29 
31  throw std::invalid_argument("Missing the required adjustment table for male.");
32  } else if (!values.contains(core::Gender::female)) {
33  throw std::invalid_argument("Missing the required adjustment table for female.");
34  }
35  }
36 
39 };
40 
42 struct FirstMoment {
45  bool empty() const noexcept { return count_ < 1; }
48  int count() const noexcept { return count_; }
51  double sum() const noexcept { return sum_; }
52 
55  double mean() const noexcept {
56  if (count_ > 0) {
57  return sum_ / count_;
58  }
59 
60  return 0.0;
61  }
62 
65  void append(double value) noexcept {
66  count_++;
67  sum_ += value;
68  }
69 
71  void clear() noexcept {
72  count_ = 0;
73  sum_ = 0.0;
74  }
75 
79  auto operator<=>(const FirstMoment &other) const = default;
80 
81  private:
82  int count_{};
83  double sum_{};
84 };
85 } // namespace hgps
bool contains(const TROW &row_key) const
Determines whether the container contains a row.
Definition: map2d.h:52
bool empty() const noexcept
Determine whether the container is empty.
Definition: map2d.h:27
std::size_t rows() const noexcept
Gets the number of rows.
Definition: map2d.h:35
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
Global namespace.
Definition: jsonparser.h:88
Defines the risk factor baseline adjustment data type.
Definition: riskfactor_adjustment_types.h:14
BaselineAdjustment()=default
Initialises a new instance of the BaselineAdjustment structure.
FactorAdjustmentTable values
The risk factors adjustment table values.
Definition: riskfactor_adjustment_types.h:38
BaselineAdjustment(FactorAdjustmentTable &&adjustment_table)
Initialises a new instance of the BaselineAdjustment structure.
Definition: riskfactor_adjustment_types.h:21
Defines the first statistical moment type.
Definition: riskfactor_adjustment_types.h:42
auto operator<=>(const FirstMoment &other) const =default
Compare FirstMoment instances.
void append(double value) noexcept
Appends a value to the moment.
Definition: riskfactor_adjustment_types.h:65
double mean() const noexcept
Gets the values mean.
Definition: riskfactor_adjustment_types.h:55
double sum() const noexcept
Gets the values sum.
Definition: riskfactor_adjustment_types.h:51
void clear() noexcept
Clear the moment.
Definition: riskfactor_adjustment_types.h:71
bool empty() const noexcept
Determine whether the moment is empty.
Definition: riskfactor_adjustment_types.h:45
int count() const noexcept
Gets the number of values added to the moment.
Definition: riskfactor_adjustment_types.h:48