-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
# This file was generated by Rcpp::compileAttributes | ||
# Generated by using Rcpp::compileAttributes() -> do not edit by hand | ||
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
bb_lt_invert_Cpp <- function(t, lambda1, lambda2, Ap1, Bp1, direction, nblocks, tol, Lmax, computeMode, nThreads) { | ||
.Call('MultiBD_bb_lt_invert_Cpp', PACKAGE = 'MultiBD', t, lambda1, lambda2, Ap1, Bp1, direction, nblocks, tol, Lmax, computeMode, nThreads) | ||
.Call('_MultiBD_bb_lt_invert_Cpp', PACKAGE = 'MultiBD', t, lambda1, lambda2, Ap1, Bp1, direction, nblocks, tol, Lmax, computeMode, nThreads) | ||
} | ||
|
||
bbd_lt_invert_Cpp <- function(t, a0, b0, lambda1, lambda2, mu2, gamma, x, y, A, Bp1, nblocks, tol, computeMode, nThreads, maxdepth) { | ||
.Call('MultiBD_bbd_lt_invert_Cpp', PACKAGE = 'MultiBD', t, a0, b0, lambda1, lambda2, mu2, gamma, x, y, A, Bp1, nblocks, tol, computeMode, nThreads, maxdepth) | ||
.Call('_MultiBD_bbd_lt_invert_Cpp', PACKAGE = 'MultiBD', t, a0, b0, lambda1, lambda2, mu2, gamma, x, y, A, Bp1, nblocks, tol, computeMode, nThreads, maxdepth) | ||
} | ||
|
||
SEIR_Cpp <- function(t, alpha, beta, kappa, S0, E0, I0, Ap1, Bp1, Cp1, direction, nblocks, tol, Lmax, computeMode, nThreads) { | ||
.Call('_MultiBD_SEIR_Cpp', PACKAGE = 'MultiBD', t, alpha, beta, kappa, S0, E0, I0, Ap1, Bp1, Cp1, direction, nblocks, tol, Lmax, computeMode, nThreads) | ||
} | ||
|
||
SIR_Cpp <- function(t, alpha, beta, S0, I0, Ap1, Bp1, direction, nblocks, tol, Lmax, computeMode, nThreads) { | ||
.Call('MultiBD_SIR_Cpp', PACKAGE = 'MultiBD', t, alpha, beta, S0, I0, Ap1, Bp1, direction, nblocks, tol, Lmax, computeMode, nThreads) | ||
.Call('_MultiBD_SIR_Cpp', PACKAGE = 'MultiBD', t, alpha, beta, S0, I0, Ap1, Bp1, direction, nblocks, tol, Lmax, computeMode, nThreads) | ||
} | ||
|
||
tb_lt_invert_Cpp <- function(t, lambda1, lambda2, lambda3, Ap1, Bp1, Cp1, direction, nblocks, tol, Lmax, computeMode, nThreads) { | ||
.Call('_MultiBD_tb_lt_invert_Cpp', PACKAGE = 'MultiBD', t, lambda1, lambda2, lambda3, Ap1, Bp1, Cp1, direction, nblocks, tol, Lmax, computeMode, nThreads) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
################################################### | ||
### Compute transition probabilities of SEIR models | ||
################################################### | ||
|
||
#' Transition probabilities of an SEIR process | ||
#' | ||
#' Computes the transition pobabilities of an SIR process | ||
#' using the bivariate birth process representation | ||
#' @param t time | ||
#' @param alpha removal rate | ||
#' @param kappa rate at which an exposed person becomes infective | ||
#' @param beta infection rate | ||
#' @param S0 initial susceptible population | ||
#' @param E0 initial exposed population | ||
#' @param I0 initial infectious population | ||
#' @param nSE number of infection events | ||
#' @param nEI number of events at which an exposed person becomes infective | ||
#' @param nIR number of removal events | ||
#' @param direction direction of the transition probabilities (either \code{Forward} or \code{Backward}) | ||
#' @param nblocks number of blocks | ||
#' @param tol tolerance | ||
#' @param computeMode computation mode | ||
#' @param nThreads number of threads | ||
#' @return a matrix of the transition probabilities | ||
#' @export | ||
|
||
SEIR_prob <- function(t, alpha, beta, kappa, S0, E0, I0, nSE, nEI, nIR, direction = c("Forward","Backward"), | ||
nblocks = 20, tol = 1e-12, computeMode = 0, nThreads = 4) { | ||
|
||
direction <- match.arg(direction) | ||
dir = 0 | ||
if (direction == "Backward") dir = 1 | ||
|
||
#################################### | ||
### t is too small | ||
### set probability 1 at a0, b0, c0 | ||
#################################### | ||
|
||
res = array(0, dim= c(nSE + 1,nEI + 1,nIR+1)) | ||
if (t < tol) { | ||
res[1,1,1] = 1 | ||
} else { | ||
Lmax = nblocks # initialize Lmax | ||
tmp = SEIR_Cpp(t, alpha, beta, kappa, S0, E0, I0, nSE + 1, nEI + 1, nIR + 1, dir, nblocks, tol, | ||
Lmax, computeMode, nThreads) | ||
for (i in 0:nSE) { | ||
for (j in 0:nEI) { | ||
for (k in 0:nIR) | ||
res[i+1,j+1,k+1] = tmp[i + j*(nSE+1) + k*(nSE+1)*(nEI+1) + 1] | ||
} | ||
} | ||
} | ||
|
||
return(abs(res)) | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "bbd.h" | ||
|
||
// [[Rcpp::export]] | ||
std::vector<double> SEIR_Cpp(const double t, const double alpha, const double beta, const double kappa, | ||
const long int S0, const long int E0, const long int I0, | ||
const int Ap1, const int Bp1, const int Cp1, const int direction, | ||
const int nblocks, const double tol, int& Lmax, const int computeMode, const int nThreads) { | ||
|
||
const int matsize = Ap1*Bp1*Cp1; | ||
std::vector<double> lambda1(matsize), lambda2(matsize), lambda3(matsize); | ||
|
||
for (int a=0; a<Ap1; ++a) { //nSE | ||
for (int b=0; b<Bp1; ++b) { // nEI | ||
for (int c=0; c<Cp1; ++c) { // nIR | ||
double Spop = std::max(0.0, S0-a+0.0); | ||
double Epop = std::max(0.0, E0+a-b+0.0); | ||
double Ipop = std::max(0.0, I0+b-c+0.0); | ||
lambda1[a + b*Ap1 + c*Ap1*Bp1] = beta*Spop*Ipop; // Infection rate is beta*S*I | ||
lambda2[a + b*Ap1 + c*Ap1*Bp1] = kappa*Epop; | ||
lambda3[a + b*Ap1 + c*Ap1*Bp1] = alpha*Ipop; | ||
} | ||
} | ||
} | ||
|
||
return(tb_lt_invert_Cpp(t, lambda1, lambda2, lambda3, Ap1, Bp1, Cp1, direction, | ||
nblocks, tol, Lmax, computeMode, nThreads)); | ||
} |