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
makeLmat <- function (h){ | |
x = seq(0,1,by=h) | |
N=length(x) | |
invh2 <- 1/(h^2) | |
res = diag(invh2, N) | |
res[cbind(1:(N-1),2:N)] <- -0.5*invh2 | |
res[cbind(2:N,1:(N-1))] <- -0.5*invh2 | |
return(list(L=res,x=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(dplyr) | |
library(mvtnorm) | |
set.seed(1) | |
x1 = rnorm(10, 0, 1) | |
x2 = x1+rnorm(10, 0, 0.1) | |
y = x1+x2 + rnorm(10, 0, 1) | |
print(cor(x1,x2)) |
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(deSolve) | |
SEIRmod <- function(Time, State, Pars) { | |
with(as.list(c(State, Pars)), { | |
dS <- - beta*I*S | |
dE <- beta*I*S - alpha*E | |
dI <- alpha*E - gamma*I | |
dR <- gamma*I | |
return(list(c(dS, dE, dI, dR))) | |
}) |
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
# Reference: | |
# Hoffman et al. "Stochastic Variational Inference" | |
# browseURL("https://arxiv.org/abs/1206.7051") | |
#### | |
# learning rate | |
lr <-function(t, lr_param){ | |
(t + lr_param[1])^(-lr_param[2]) | |
} |
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
#intensity function | |
lambda <- function(x, shape){ | |
shape*x^(shape-1) | |
} | |
#number of truncated observation | |
counttrunc <- function(tau, WS, weibull_param, | |
shape=1, maxit=10000){ | |
Et = 0 | |
count = 0L |
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
#install.packages('RcppPlanc', repos = c('https://welch-lab.r-universe.dev', 'https://cloud.r-project.org')) | |
library(rliger) | |
library(RcppPlanc) | |
library(bench) | |
pbmc <- normalize(pbmc) | |
pbmc <- selectGenes(pbmc) | |
pbmc <- scaleNotCenter(pbmc) | |
getOption("ligerVerbose", TRUE) | |
bm <- bench::mark({ |
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(animation) | |
make_initial <- function(np, S){ | |
X = rep(S/np, np) | |
return(X) | |
} | |
randomwalk <- function(X){ | |
np = length(X) | |
i = sample.int(np, 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
#参考文献:永井佑紀『1週間で学べる!Julia数値計算プログラミング』(講談社) | |
library(animation) | |
library(reshape2) | |
make_initial <- function(n_people,n_chip){ | |
basket = integer(n_people) | |
for(i in 1:n_chip){ | |
target = sample.int(n_people, 1) | |
basket[target] = basket[target] + 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
library(pdftools) | |
library(tidyr) | |
library(dplyr) | |
library(ggplot2) | |
browseURL("https://www.jstage.jst.go.jp/article/jph/50/8/50_686/_article/-char/ja/") | |
text = pdf_text("~/Downloads/50_686.pdf") | |
tab2raw = unlist(strsplit(text[grep("表2", text)]," ")) | |
tab2raw = tab2raw[sapply(tab2raw, nchar) > 0] | |
tab2raw = tab2raw[16:145] |
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(animation) | |
sim_pois_1d <- function(t_n, g_n, p, seed){ | |
set.seed(seed) | |
counts <- integer(t_n) | |
x <- seq(0, 1, length.out=g_n) | |
delta_list <- vector("list", t_n) | |
hit <- matrix(0, t_n, g_n) | |
pud = 10 | |
for(i in 1:t_n){ |
NewerOlder