Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions include/respond/cost_effectiveness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2025-08-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2025-2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -27,7 +27,7 @@ namespace respond {
/// @param N Number of weeks to discount over.
/// @param isDiscrete Whether the discount is a discrete or continuous discount.
/// @return A matrix with the discounted data.
inline Eigen::VectorXd Discount(const Eigen::VectorXd &data,
inline Eigen::VectorXd Discount(const Eigen::Ref<const Eigen::VectorXd> &data,
double discount_rate, int week,
bool is_discrete = true,
double total_weeks = 52.0) {
Expand All @@ -41,17 +41,19 @@ inline Eigen::VectorXd Discount(const Eigen::VectorXd &data,
/// @param state The state matrix.
/// @param multiplier The multiplying matrix.
/// @return state cwise multiplied by the multiplying matrix.
inline Eigen::VectorXd CwiseProduct(const Eigen::VectorXd &state,
const Eigen::VectorXd &multiplier) {
inline Eigen::VectorXd
CwiseProduct(const Eigen::Ref<const Eigen::VectorXd> &state,
const Eigen::Ref<const Eigen::VectorXd> &multiplier) {
return state.cwiseProduct(multiplier);
}

/// @brief A cwise minimizer. This is used for min utility.
/// @param state The state matrix.
/// @param multiplier The multiplying matrix.
/// @return state cwise multiplied by the multiplying matrix.
inline Eigen::VectorXd CwiseMin(const Eigen::VectorXd &state,
const Eigen::VectorXd &multiplier) {
inline Eigen::VectorXd
CwiseMin(const Eigen::Ref<const Eigen::VectorXd> &state,
const Eigen::Ref<const Eigen::VectorXd> &multiplier) {
return state.cwiseMin(multiplier);
}

Expand Down
10 changes: 6 additions & 4 deletions include/respond/history.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-05-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand Down Expand Up @@ -206,7 +206,8 @@ class History {
/// automatic next timestep). If timestep is negative, the next sequential
/// timestep is used automatically. If timestep already exists, it is
/// considered invalid but is currently overwritten.
void AddState(const Eigen::VectorXd &state, int timestep = -1) {
void AddState(const Eigen::Ref<const Eigen::VectorXd> &state,
int timestep = -1) {
if (timestep < 0) {
timestep = GetNextTimestep();
}
Expand All @@ -227,13 +228,14 @@ class History {
/// @brief Records a snapshot value at a concrete timestep.
/// @param state The snapshot value to record.
/// @param timestep The simulation timestep for this snapshot.
void RecordSnapshot(const Eigen::VectorXd &state, int timestep) {
void RecordSnapshot(const Eigen::Ref<const Eigen::VectorXd> &state,
int timestep) {
AddState(state, timestep);
}

/// @brief Adds a contribution to an accumulated history.
/// @param state The per-step contribution to accumulate.
void AccumulateState(const Eigen::VectorXd &state) {
void AccumulateState(const Eigen::Ref<const Eigen::VectorXd> &state) {
if (_mode != HistoryMode::Accumulated) {
AddState(state);
return;
Expand Down
4 changes: 2 additions & 2 deletions include/respond/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-12 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand Down Expand Up @@ -33,7 +33,7 @@ class Model {

/// @brief Sets the current state of the model.
/// @param state The state vector to set. A copy is made internally.
virtual void SetState(const Eigen::VectorXd &state) = 0;
virtual void SetState(const Eigen::Ref<const Eigen::VectorXd> &state) = 0;

/// @brief Retrieves the current state of the model.
/// @return A copy of the current state vector (limited to observation).
Expand Down
7 changes: 4 additions & 3 deletions include/respond/transition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-02 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-09 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand Down Expand Up @@ -40,13 +40,14 @@ class Transition {
/// transition).
/// @return The resulting state vector after applying this transition.
virtual Eigen::VectorXd
Execute(const Eigen::VectorXd &s,
Execute(const Eigen::Ref<const Eigen::VectorXd> &s,
std::map<std::string, History> &h) const = 0;

/// @brief Adds a transformation matrix to this transition.
/// The matrix is stored for use during Execute() calls.
/// @param m The transition matrix to add (not modified by this transition).
virtual void AddTransitionMatrix(const Eigen::MatrixXd &m) = 0;
virtual void
AddTransitionMatrix(const Eigen::Ref<const Eigen::MatrixXd> &m) = 0;

/// @brief Retrieves the name/type of this transition.
/// @return The transition's identifier as a string.
Expand Down
4 changes: 2 additions & 2 deletions src/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-12 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -20,7 +20,7 @@

namespace respond {
Eigen::VectorXd
BackgroundDeath::Execute(const Eigen::VectorXd &state,
BackgroundDeath::Execute(const Eigen::Ref<const Eigen::VectorXd> &state,
std::map<std::string, History> &h) const {
if (GetTransitionMatrices().size() != 1) {
std::string error_msg =
Expand Down
7 changes: 4 additions & 3 deletions src/behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-05 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -19,8 +19,9 @@
#include <spdlog/spdlog.h>

namespace respond {
Eigen::VectorXd Behavior::Execute(const Eigen::VectorXd &state,
std::map<std::string, History> &h) const {
Eigen::VectorXd
Behavior::Execute(const Eigen::Ref<const Eigen::VectorXd> &state,
std::map<std::string, History> &h) const {
if (GetTransitionMatrices().size() != 1) {
std::string error_msg =
"Behavior error: Expected 1 transition matrix, got " +
Expand Down
4 changes: 2 additions & 2 deletions src/internals/background.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -25,7 +25,7 @@ class BackgroundDeath : public virtual TransitionBase {
// Run the execute function and return the final state. Do not edit the
// parameter state, but do edit the history provided. Nothing in the
// Transition object should change.
Eigen::VectorXd Execute(const Eigen::VectorXd &s,
Eigen::VectorXd Execute(const Eigen::Ref<const Eigen::VectorXd> &s,
std::map<std::string, History> &h) const override;

// Clone
Expand Down
4 changes: 2 additions & 2 deletions src/internals/behavior.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -25,7 +25,7 @@ class Behavior : public virtual TransitionBase {
// Run the execute function and return the final state. Do not edit the
// parameter state, but do edit the history provided. Nothing in the
// Transition object should change.
Eigen::VectorXd Execute(const Eigen::VectorXd &s,
Eigen::VectorXd Execute(const Eigen::Ref<const Eigen::VectorXd> &s,
std::map<std::string, History> &h) const override;

// Clone
Expand Down
4 changes: 2 additions & 2 deletions src/internals/intervention.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -25,7 +25,7 @@ class Intervention : public virtual TransitionBase {
// Run the execute function and return the final state. Do not edit the
// parameter state, but do edit the history provided. Nothing in the
// Transition object should change.
Eigen::VectorXd Execute(const Eigen::VectorXd &s,
Eigen::VectorXd Execute(const Eigen::Ref<const Eigen::VectorXd> &s,
std::map<std::string, History> &h) const override;

// Clone
Expand Down
6 changes: 4 additions & 2 deletions src/internals/markov.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-05-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand Down Expand Up @@ -78,7 +78,9 @@ class Markov : public virtual Model {
}

// anticipate making a copy of the vector
void SetState(const Eigen::VectorXd &s) override { _state = s; }
void SetState(const Eigen::Ref<const Eigen::VectorXd> &s) override {
_state = s;
}
// return const & to limit to observation of the state
Eigen::VectorXd GetState() const override { return _state; }
// return the transitions
Expand Down
4 changes: 2 additions & 2 deletions src/internals/migration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -25,7 +25,7 @@ class Migration : public virtual TransitionBase {
// Run the execute function and return the final state. Do not edit the
// parameter state, but do edit the history provided. Nothing in the
// Transition object should change.
Eigen::VectorXd Execute(const Eigen::VectorXd &s,
Eigen::VectorXd Execute(const Eigen::Ref<const Eigen::VectorXd> &s,
std::map<std::string, History> &h) const override;

// Clone
Expand Down
4 changes: 2 additions & 2 deletions src/internals/overdose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -25,7 +25,7 @@ class Overdose : public virtual TransitionBase {
// Run the execute function and return the final state. Do not edit the
// parameter state, but do edit the history provided. Nothing in the
// Transition object should change.
Eigen::VectorXd Execute(const Eigen::VectorXd &s,
Eigen::VectorXd Execute(const Eigen::Ref<const Eigen::VectorXd> &s,
std::map<std::string, History> &h) const override;

// Clone
Expand Down
5 changes: 3 additions & 2 deletions src/internals/transition_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-06 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -24,7 +24,8 @@ class TransitionBase : public virtual Transition {
// Add a Transition Matrix to the set. We have no need to edit it once it's
// been added, just use it. Thus, we don't need full ownership (reference)
// and can accept the const type.
void AddTransitionMatrix(const Eigen::MatrixXd &m) override {
void
AddTransitionMatrix(const Eigen::Ref<const Eigen::MatrixXd> &m) override {
_transition_matrices.push_back(m);
}
// Get the name of the Transition. No need to edit the object and do not
Expand Down
7 changes: 4 additions & 3 deletions src/intervention.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-05 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -19,8 +19,9 @@
#include <spdlog/spdlog.h>

namespace respond {
Eigen::VectorXd Intervention::Execute(const Eigen::VectorXd &state,
std::map<std::string, History> &h) const {
Eigen::VectorXd
Intervention::Execute(const Eigen::Ref<const Eigen::VectorXd> &state,
std::map<std::string, History> &h) const {
if (GetTransitionMatrices().size() != 1) {
std::string error_msg =
"Intervention error: Expected 1 transition matrix, got " +
Expand Down
7 changes: 4 additions & 3 deletions src/migration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created Date: 2026-02-05 //
// Author: Matthew Carroll //
// ----- //
// Last Modified: 2026-02-12 //
// Last Modified: 2026-06-25 //
// Modified By: Matthew Carroll //
// ----- //
// Copyright (c) 2026 Syndemics Lab at Boston Medical Center //
Expand All @@ -19,8 +19,9 @@
#include <spdlog/spdlog.h>

namespace respond {
Eigen::VectorXd Migration::Execute(const Eigen::VectorXd &state,
std::map<std::string, History> &h) const {
Eigen::VectorXd
Migration::Execute(const Eigen::Ref<const Eigen::VectorXd> &state,
std::map<std::string, History> &h) const {
if (GetTransitionMatrices().size() != 1) {
std::string error_msg =
"Migration error: Expected 1 transition matrix, got " +
Expand Down
Loading