13#ifndef RESPOND_COSTEFFECTIVENESS_HPP_
14#define RESPOND_COSTEFFECTIVENESS_HPP_
18#include <respond/history.hpp>
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) {
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);
43CwiseProduct(
const Eigen::Ref<const Eigen::VectorXd> &state,
44 const Eigen::Ref<const Eigen::VectorXd> &multiplier) {
45 return state.cwiseProduct(multiplier);
53CwiseMin(
const Eigen::Ref<const Eigen::VectorXd> &state,
54 const Eigen::Ref<const Eigen::VectorXd> &multiplier) {
55 return state.cwiseMin(multiplier);
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()) {
71 auto history = h.GetStateAsVector();
73 if (history.size() != total_weeks || total_weeks <= 0) {
78 Eigen::VectorXd running_total = Eigen::VectorXd::Zero(history[0].size());
80 for (
int t = 0; t < history.size(); ++t) {
81 auto state = history[t];
83 ((discount) ? Discount(state, discount_rate, t,
true, total_weeks)
86 auto result = running_total.sum();