This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(dplyr) | |
| simulate_branching_death <- function(alpha, | |
| beta, | |
| Tmax) { | |
| death_time <- rexp(1,beta) | |
| death <- min(Tmax, death_time) | |
| N0 <- rpois(1, death * alpha) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(RHawkes) | |
| simulate_branching_death <- function(mu, | |
| alpha, | |
| beta, | |
| Tmax) { | |
| N0 <- rpois(1, Tmax * mu) | |
| if(N0==0L){ | |
| return( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(ggplot2) | |
| simulate_branching_death <- function(mu, | |
| lambda, | |
| beta, | |
| Tmax) { | |
| N0 <- rpois(1, Tmax * mu) | |
| t0 <- sort(runif(N0, 0, Tmax)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(dplyr) | |
| branching_process <- function(mu, lambda, Tmax, G){ | |
| gen <- vector("list", G) | |
| X <- rpois(1, mu*Tmax) #第1世代 | |
| if(X>0){ | |
| id <- 1L:X | |
| parent <- 0L | |
| birth_time <- sort(runif(X, 0, Tmax)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(ggplot2) | |
| simulate_multitype_gillespie <- function( | |
| R, | |
| Tmax, | |
| initial_type = 1L | |
| ) { | |
| K <- nrow(R) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(hawkes) | |
| mu <- 0.5 | |
| a <- 0.7 | |
| b <- 1.0 | |
| Tau <- 100 | |
| set.seed(12345) | |
| dat <- simulateHawkes( | |
| lambda0 = mu, | |
| alpha = a*b, | |
| beta = b, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(dplyr) | |
| multitype_branching_process <- function(M, G, initial_type = 1L) { | |
| # M[i, j] = type i の個体1個体あたりの | |
| # type j の平均子孫数 | |
| K <- nrow(M) | |
| if (ncol(M) != K) { | |
| stop("M must be a square matrix.") | |
| } | |
| if (any(M < 0)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(ggplot2) | |
| simulate_branching <- function(mu, | |
| lambda, | |
| Tmax) { | |
| N0 <- rpois(1, Tmax*mu) | |
| t <- sort(runif(N0, 0, Tmax)) | |
| individuals <- data.frame( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(ggplot2) | |
| ### | |
| branching_process <- function(theta, gamma, G){ | |
| gen <- vector("list", G) | |
| K <- rpois(1, theta) | |
| id <- 1L:K | |
| parent <- 1L | |
| gen[[1]] <- data.frame(id = id, | |
| parent = parent, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| iter_nextstep <- function(n, K){ | |
| I <- c(1, 0) | |
| I_hist <- matrix(0, nrow = 2, ncol = n+1) | |
| I_hist[, 1] <- I | |
| for(i in 1:n){ | |
| I <- K%*%I | |
| I_hist[,i+1] <- I | |
| } | |
| return(t(I_hist)) | |
| } |
NewerOlder