RESPOND 2.4.0
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-02-06 //
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 <iostream>
17
18#include <Eigen/Dense>
19
20#include <respond/history.hpp>
21
22namespace respond {
23
30inline Eigen::VectorXd Discount(const Eigen::VectorXd &data,
31 double discount_rate, int week,
32 bool is_discrete = true,
33 double total_weeks = 52.0) {
34 double discount =
35 (is_discrete) ? (1 / pow((1.0 + (discount_rate) / total_weeks), week))
36 : (exp(-discount_rate * (week / total_weeks)));
37 return data - Eigen::VectorXd::Constant(data.size(), discount);
38}
39
44inline Eigen::VectorXd CwiseProduct(const Eigen::VectorXd &state,
45 const Eigen::VectorXd &multiplier) {
46 return state.cwiseProduct(multiplier);
47}
48
53inline Eigen::VectorXd CwiseMin(const Eigen::VectorXd &state,
54 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_