3 + 8
30 / 23
3005 %% 3
sin(100)
log(20)
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
#include <RcppArmadillo.h> | |
using namespace Rcpp; | |
using namespace arma; | |
// [[Rcpp::depends(RcppArmadillo)]] | |
rowvec rdirichlet(const vec & alpha){ | |
int K = alpha.n_rows; | |
rowvec y(K); | |
for(int k=0;k<K ;k++){ | |
y[k] = R::rgamma(alpha[k],1); |
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
require(ggplot2) | |
require(grid) | |
require(dplyr) | |
"%||%" <- function(a, b) { | |
if (!is.null(a)) a else b | |
} | |
geom_grid <- function(mapping = NULL, data = NULL, | |
position = "identity", |
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
require(ggplot2) | |
####utilities | |
"%||%" <- function(a, b) { | |
if (!is.null(a)) a else b | |
} | |
rbind_dfs <- function(dfs) { | |
out <- list() | |
columns <- unique(unlist(lapply(dfs, names))) |
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
require(ggplot2) | |
####utilities | |
"%||%" <- function(a, b) { | |
if (!is.null(a)) a else b | |
} | |
rbind_dfs <- function(dfs) { | |
out <- list() | |
columns <- unique(unlist(lapply(dfs, names))) |
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
#このソースコードの自由な複製・改変・再配布を認める。 | |
set.seed(1234) | |
N <- 100 | |
ind <- sample.int(2,N,replace = TRUE) | |
lambda <- c(2,10) | |
y <- rpois(N,lambda[ind]) | |
a <- 1 #ガンマ事前分布のパラメータ | |
b <- 1 #ガンマ事前分布のパラメータ | |
alpha <-c(2,2) #ディリクレ事前分布のパラメータ | |
softmax <- function(x){ |
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(gganimate) | |
library(dplyr) | |
rwbounded <- function(U,scaling){ | |
u <- runif(length(U),-1,1) | |
return(U + scaling*ifelse(u>0,(1-U)*u,U*u)) | |
} | |
rwSIR <- function(N,Tmax,ini,scaling,r,infect_p,remove_p,rwfun=rwbounded,seed=NULL){ | |
if(is.null(seed)){ |
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(gganimate) | |
library(dplyr) | |
rwSIR <- function(N,Tmax,ini,scaling,r2,infect_p,remove_p, | |
decay=1,seed=NULL){ | |
rwbounded1 <- function(U,scaling){ | |
u <- runif(length(U),-1,1) | |
scaling*ifelse(u>0,(1-U)*u,U*u) | |
} |
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(gganimate) | |
library(dplyr) | |
rwSIR <- function(N,Tmax,ini,scaling,r2,infect_p,remove_p, | |
randu = function(U){runif(length(U),-1,1)}, | |
decay=1,seed=NULL){ | |
rwbounded1 <- function(U,scaling){ | |
u <- randu(U) | |
scaling*ifelse(u>0,(1-U)*u,U*u) |