RESPOND 2.5.1
Researching Effective Strategies to Prevent Opioid Death
Loading...
Searching...
No Matches
cost_effectiveness.hpp
1
2// File: cost_effectiveness.hpp //
3// Project: respond //
4// Created Date: 2025-08-05 //
5// Author: Matthew Carroll //
6// ----- //
7// Last Modified: 2026-07-09 //
8// Modified By: Matthew Carroll //
9// ----- //
10// Copyright (c) 2025-2026 Syndemics Lab at Boston Medical Center //
12
13#ifndef RESPOND_COSTEFFECTIVENESS_HPP_
14#define RESPOND_COSTEFFECTIVENESS_HPP_
15
16#include <Eigen/Dense>
17
18#include <respond/history.hpp>
19
20namespace respond {
21
28inline Eigen::VectorXd Discount(const Eigen::Ref<const Eigen::VectorXd> &data,
29 double discount_rate, int week,
30 bool is_discrete = true,
31 double total_weeks = 52.0) {
32 double discount =
33 (is_discrete) ? (1 / pow((1.0 + (discount_rate) / total_weeks), week))
34 : (exp(-discount_rate * (week / total_weeks)));
35 return data - Eigen::VectorXd::Constant(data.size(), discount);
36}
37
42inline Eigen::VectorXd
43CwiseProduct(const Eigen::Ref<const Eigen::VectorXd> &state,
44 const Eigen::Ref<const Eigen::VectorXd> &multiplier) {
45 return state.cwiseProduct(multiplier);
46}
47
52inline Eigen::VectorXd
53CwiseMin(const Eigen::Ref<const Eigen::VectorXd> &state,
54 const Eigen::Ref<const Eigen::VectorXd> &multiplier) {
55 return state.cwiseMin(multiplier);
56}
57
63inline double CalculateLifeYears(const History &h, bool discount = false,
64 double discount_rate = 0.0,
65 double total_weeks = 52.0) {
66 if (h.GetStateMap().empty()) {
67 // log no state vector
68 return 0.0;
69 }
70
71 auto history = h.GetStateAsVector();
72
73 if (history.size() != total_weeks || total_weeks <= 0) {
74 // warn that history does not have 52 weeks
75 return 0.0;
76 }
77
78 Eigen::VectorXd running_total = Eigen::VectorXd::Zero(history[0].size());
79
80 for (int t = 0; t < history.size(); ++t) {
81 auto state = history[t];
82 running_total +=
83 ((discount) ? Discount(state, discount_rate, t, true, total_weeks)
84 : state);
85 }
86 auto result = running_total.sum();
87
88 // dividing by 52 to switch from life weeks to life years
89 return result / 52.0;
90}
91} // namespace respond
92
93#endif // RESPOND_COSTEFFECTIVENESS_HPP_