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){ |
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) | |
#browseURL("https://en.wikipedia.org/wiki/Euler–Maruyama_method") | |
mu <- function(y, t, mod){ | |
mod$THETA * (mod$MU - y) | |
} | |
sigma <- function(y, t, mod){ | |
mod$SIGMA |
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" | |
// [[Rcpp::depends(RcppArmadillo)]] | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <vector> | |
using namespace Rcpp; | |
// [[Rcpp::export]] |
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" | |
// [[Rcpp::depends(RcppArmadillo)]] | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
List rowmeanvar_mtx(const int & n_row, const int & n_col, |
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("tidyr") | |
require("dplyr") | |
require("ggplot2") | |
require("see") | |
dfiris <- mutate(iris, id=row_number()) %>% | |
pivot_longer(Sepal.Length:Petal.Width) | |
#head(dfiris) |
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) | |
lr_default <- function(t, delay, forgetting){ | |
(t+delay)^(-forgetting) | |
} | |
linedf <- expand.grid(delay=c(1,2), forgetting=c(0.6,0.9), t=seq(0,20, length.out=50)) %>% | |
mutate(lr=lr_default(t, delay, forgetting)) %>% | |
mutate(param = paste0("delay=",delay, ", ", "forgetting=", forgetting)) %>% |
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(magrittr) | |
library(tidyr) | |
library(dplyr) | |
sigmoid2 <- function(x_from, x_to, y_from, y_to, smooth = 5, n = 100, direction = "x", location = 0, scale = 1) { | |
if(!direction %in% c("x", "y")) {stop("Only the directions x or y is allowed.")} | |
if(direction == "x") { | |
x <- seq(-smooth, smooth, length = n) |