Skip to content

Instantly share code, notes, and snippets.

View kosugitti's full-sized avatar
🏯
Working from Office

Koji E. Kosugi kosugitti

🏯
Working from Office
View GitHub Profile
data{
int<lower=0> N;
vector[2] X[N];
}
parameters{
vector[2] mu;
vector<lower=0>[2] sigma;
real<lower=-1,upper=1> rho;
}
transformed parameters{
data{
int<lower=0> N;
vector[3] X[N];
}
parameters{
vector[3] mu;
real<lower=0> sig[3];
real<lower=-1,upper=1> rho;
}
transformed parameters{
data{
int<lower=0> N;
real X1[N];
real X2[N];
real X3[N];
}
parameters{
real mu1;
real mu2;
real mu3;
data{
int<lower=0> N;
vector[2] X1[N];
vector[2] X2[N];
}
parameters{
real mu;
real<lower=0> sig[2];
real<lower=-1,upper=1> rho;
real effectA; //between
library(rvest)
p.data <- read_html("http://baseball-data.com/ranking-salary/all/p.html") #ピッチャーの年俸など
h.data <- read_html("http://baseball-data.com/ranking-salary/all/h.html") #野手のそれ
avg5 <- read_html("http://baseball-data.com/stats/hitter2-all/avg-5.html") #規定打数1/3以上の打者基本成績
era5 <- read_html("http://baseball-data.com/stats/pitcher2-all/era-5.html") #規定投球回1/3以上の投手基本成績
p.df <- as.data.frame(html_table(p.data,head=T))
head(p.df)
library(stringr) # 文字列操作パッケージ
p.df$順位 <- NULL
@kosugitti
kosugitti / gist:42197a6a9f1bc540d710f4f29293f593
Created September 8, 2016 00:46
Test code :: Posterior Predictive Distribution
library(rstan)
library(ggplot2)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
N <- 10000
mu <- 10
sigma <- 20
X <- rnorm(N,mu,sigma)
modelcode <- '
@kosugitti
kosugitti / GA_PDG_primitive
Created April 26, 2016 09:34
Generic AlgorithmでPDGやってみる(習作1)
# 囚人のジレンマ関数をつくる
PDG.rule <- function(A,B){
if(A ==1 && B == 1){ payA <- 8; payB <- 8 }
if(A ==0 && B == 1){ payA <- 12; payB <- 0 }
if(A ==1 && B == 0){ payA <- 0; payB <- 12 }
if(A ==0 && B == 0){ payA <- 4; payB <- 4 }
return(list(A=payA,B=payB))
}
PDG.rule(0,1)
@kosugitti
kosugitti / Lifegame
Created April 22, 2016 09:13
Lifegame
# 初期設定
sizeX <- 20
sizeY <- 20
timeMax <- 60
# dat <- matrix(c(0,0,0,0,0,0,
# 0,0,1,0,0,0,
# 0,0,0,1,0,0,
# 0,1,1,1,0,0,
# 0,0,0,0,0,0,
# 0,0,0,0,0,0),nrow=6,ncol=6,byrow=T)
@kosugitti
kosugitti / onedimCA.R
Last active March 4, 2016 04:58
One dimensional Cell Automaton
cellsize <- 160
trace <- 50
cell <- matrix(ncol=cellsize,nrow=trace)
# 初期化
cell[1,] <- rbinom(cellsize,1,0.5)
### into 2bit
dec2bin <- function(num,digit=8){
if(num <= 0 && digit <= 0){
@kosugitti
kosugitti / improvedKmeans.R
Last active February 28, 2020 08:28
改良型k-means法
require(mvtnorm)
imKmeans <- function(dat,cl){
# step 1
dat.km <- kmeans(dat,cl,algorithm = "MacQueen")
# step 2
conv <- 3
clust <- dat.km$cluster
while(conv>0){