-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.cpp
More file actions
47 lines (42 loc) · 1.98 KB
/
background.cpp
File metadata and controls
47 lines (42 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
////////////////////////////////////////////////////////////////////////////////
// File: background.cpp //
// Project: respond //
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-12 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
////////////////////////////////////////////////////////////////////////////////
#include "internals/background.hpp"
#include <memory>
#include <string>
namespace respond {
Eigen::VectorXd
BackgroundDeath::Execute(const Eigen::VectorXd &state,
std::map<std::string, History> &h) const {
if (GetTransitionMatrices().size() != 1) {
throw std::runtime_error(
"Mortality Transitions must have 1 Transition Matrix.");
}
auto deaths =
state.cwiseProduct(GetTransitionMatrices()[0]); // calculate the deaths
if (h.find("background_death") != h.end()) {
h["background_death"].AddState(deaths);
}
if (!(state.array() >= deaths.array()).all()) {
std::runtime_error(
"The state is not larger than the estimated background deaths!");
}
auto new_state = state - deaths; // remove deaths from state
if (h.find("background_death") != h.end()) {
h["state"].AddState(new_state);
}
return new_state;
}
std::unique_ptr<Transition>
BackgroundDeath::Create(const std::string &name, const std::string &log_name) {
return std::make_unique<BackgroundDeath>(name, log_name);
}
} // namespace respond