EpiNow2 Stan Functions
epinow2::internal Namespace Reference

Classes

struct  renewal_state
 

Functions

void check_convolve_len (int n, int D, int len)
 
Eigen::VectorXd convolve_forward (const Eigen::VectorXd &x, const Eigen::VectorXd &y, int len)
 
void convolve_reverse (const Eigen::VectorXd &x, const Eigen::VectorXd &y, const Eigen::VectorXd &zbar, Eigen::VectorXd *xbar, Eigen::VectorXd *ybar)
 
void R_to_r_sums (double r, const Eigen::VectorXd &g, double &s0, double &s1, Eigen::VectorXd *e=nullptr)
 
double R_to_r_newton (double R, const Eigen::VectorXd &g, double abs_tol)
 
bool renewal_depletes (int use_pop, int s, int nht)
 
template<typename State >
void renewal_forward (const Eigen::VectorXd &seed, const Eigen::VectorXd &R, const Eigen::VectorXd &g, double pop, int use_pop, double pop_floor, int nht, State &st)
 
template<typename State >
void renewal_reverse (const State &st, const Eigen::VectorXd &R, const Eigen::VectorXd &g, int use_pop, const Eigen::VectorXd &Ibar_in, Eigen::VectorXd &seedbar, Eigen::VectorXd &Rbar, Eigen::VectorXd &gbar, double &popbar)
 

Variables

constexpr int R_to_r_max_steps = 100
 

Function Documentation

◆ check_convolve_len()

void epinow2::internal::check_convolve_len ( int n,
int D,
int len )
inline

Check that len is a valid output length for the convolution.

Parameters
nLength of x.
DLength of y.
lenRequested output length.
Exceptions
std::domain_errorif len < n or len > n + D - 1.

Definition at line 51 of file convolve_with_rev_pmf.hpp.

Referenced by epinow2::convolve_with_rev_pmf().

Here is the caller graph for this function:

◆ convolve_forward()

Eigen::VectorXd epinow2::internal::convolve_forward ( const Eigen::VectorXd & x,
const Eigen::VectorXd & y,
int len )
inline

Forward pass of the convolution on doubles.

Computes z_{d+1:d+m} += w_d x_{1:m} for each lag d, with w_d = y_{D - d}.

Parameters
xInput vector of length n.
yReversed PMF of length D.
lenOutput length, n <= len <= n + D - 1.
Returns
Vector z of length len.

Definition at line 71 of file convolve_with_rev_pmf.hpp.

Referenced by epinow2::convolve_with_rev_pmf().

Here is the caller graph for this function:

◆ convolve_reverse()

void epinow2::internal::convolve_reverse ( const Eigen::VectorXd & x,
const Eigen::VectorXd & y,
const Eigen::VectorXd & zbar,
Eigen::VectorXd * xbar,
Eigen::VectorXd * ybar )
inline

Reverse pass of the convolution on doubles.

Accumulates xbar_{1:m} += w_d zbar_{d+1:d+m} and wbar_d += zbar_{d+1:d+m}^T x_{1:m}, writing wbar_d to ybar_{D - d}.

Parameters
xInput vector of length n.
yReversed PMF of length D.
zbarAdjoint of the output, of length len.
xbarAdjoint of x, of length n, accumulated into. May be null.
ybarAdjoint of y, of length D, accumulated into. May be null.

Definition at line 98 of file convolve_with_rev_pmf.hpp.

Referenced by epinow2::convolve_with_rev_pmf().

Here is the caller graph for this function:

◆ R_to_r_newton()

double epinow2::internal::R_to_r_newton ( double R,
const Eigen::VectorXd & g,
double abs_tol )
inline

Solve for the growth rate by Newton's method on doubles.

Parameters
RReproduction number.
gReversed generation time PMF.
abs_tolStop once a step is no larger than this in absolute value.
Returns
The growth rate after the last step.

Definition at line 88 of file R_to_r.hpp.

References R_to_r_max_steps, and R_to_r_sums().

Referenced by epinow2::R_to_r().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ R_to_r_sums()

void epinow2::internal::R_to_r_sums ( double r,
const Eigen::VectorXd & g,
double & s0,
double & s1,
Eigen::VectorXd * e = nullptr )
inline

Sums used by the Newton step and the gradient.

Computes S0 = sum_k p_k exp(-r k) and S1 = sum_k k p_k exp(-r k), with p_k = g[G - 1 - k].

Parameters
rGrowth rate.
gReversed generation time PMF.
s0Set to S0.
s1Set to S1.
eIf not null, set to exp(-r k) in e[G - 1 - k].

Definition at line 61 of file R_to_r.hpp.

Referenced by epinow2::R_to_r(), and R_to_r_newton().

Here is the caller graph for this function:

◆ renewal_depletes()

bool epinow2::internal::renewal_depletes ( int use_pop,
int s,
int nht )
inline

Whether susceptible depletion applies at a time step.

Parameters
use_popPopulation adjustment (0 none, 1 after nht, 2 all).
sZero-based time step after the seeds.
nhtNumber of time steps before the adjustment starts when use_pop = 1.
Returns
True if depletion applies.

Definition at line 87 of file renewal_infections.hpp.

Referenced by renewal_forward().

Here is the caller graph for this function:

◆ renewal_forward()

template<typename State >
void epinow2::internal::renewal_forward ( const Eigen::VectorXd & seed,
const Eigen::VectorXd & R,
const Eigen::VectorXd & g,
double pop,
int use_pop,
double pop_floor,
int nht,
State & st )
inline

Forward pass of the renewal equation on doubles.

Fills st with the infections and the values needed by renewal_reverse().

Parameters
seedSeeding infections.
RReproduction numbers.
gReversed generation time PMF.
popInitial susceptible population.
use_popPopulation adjustment (0 none, 1 after nht, 2 all).
pop_floorMinimum susceptible population.
nhtNumber of time steps before the adjustment starts when use_pop = 1.
stState to fill.

Definition at line 107 of file renewal_infections.hpp.

References renewal_depletes().

Referenced by epinow2::renewal_infections().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ renewal_reverse()

template<typename State >
void epinow2::internal::renewal_reverse ( const State & st,
const Eigen::VectorXd & R,
const Eigen::VectorXd & g,
int use_pop,
const Eigen::VectorXd & Ibar_in,
Eigen::VectorXd & seedbar,
Eigen::VectorXd & Rbar,
Eigen::VectorXd & gbar,
double & popbar )
inline

Reverse pass of the renewal equation on doubles.

Parameters
stState filled by renewal_forward().
RReproduction numbers.
gReversed generation time PMF.
use_popPopulation adjustment (0 none, 1 after nht, 2 all).
Ibar_inAdjoint of the infections, seeds included.
seedbarSet to the adjoint of the seeds.
RbarAdjoint of R, accumulated into.
gbarAdjoint of g, accumulated into.
popbarAdjoint of pop, accumulated into.

Definition at line 167 of file renewal_infections.hpp.

Referenced by epinow2::renewal_infections().

Here is the caller graph for this function:

Variable Documentation

◆ R_to_r_max_steps

int epinow2::internal::R_to_r_max_steps = 100
constexpr

Maximum number of Newton steps taken by R_to_r_newton().

Definition at line 78 of file R_to_r.hpp.

Referenced by R_to_r_newton().