This file contains 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
# Converts the millionbase chess PGN database (http://www.top-5000.nl/pgn.htm) to json | |
# with one json dictionary per row. (That is, the resulting file is contain multiple json objects, | |
# not just one large). | |
import json | |
import chess.pgn # From python-chess https://github.com/niklasf/python-chess | |
pgn = open("millionbase-2.22.pgn") # Or where you have put it | |
fout = open('milionbase-2.22.json', 'w') # Or where you want it |
This file contains 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(microbenchmark) | |
library(arm) | |
library(rstan) | |
library(bbmle) | |
log_post <- function(par, y, x) { | |
sigma <- exp(par[1]) | |
intercept <- par[2] | |
beta <- as.matrix(par[-c(1,2)]) | |
mu <- intercept + x %*% beta |
This file contains 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
### Function for generating the posterior of Robo's position ### | |
landscape <- c(rep("plain", 50), rep("mountain", 25), rep("forest", 45)) | |
landscape_color <- c(mountain = "black", forest = "green", plain = "yellow") | |
cover_cost <- c(mountain = 10, forest = 5, plain = 1) | |
posterior_sample <- function(n) { | |
dist_i <- sample(3, n, replace = TRUE, c(18, 17, 65)) | |
mu <- c(15, 40, 90) |
This file contains 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
# Prior to the tutorial make sure that the script below runs without error on your R installation. | |
# What you need is a working installation of JAGS: http://mcmc-jags.sourceforge.net/ | |
# and the rjags R package that can be installed from R by running | |
# install.packages("rjags") | |
# Generating some fake data | |
set.seed(123) | |
y <- rbinom(30, size = 1, prob = 0.2015) | |
# Fitting a simple binomial model using JAGS |
This file contains 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
# The code below will probably only work on Linux and requires VLC on the path. | |
library(beepr) | |
library(stringr) | |
# Plays a file with vlc and returns the vlc instance's PID | |
play_vlc_pid <- function(fname) { | |
system(paste("vlc -Idummy --no-loop --no-repeat --playlist-autostart --no-media-library --play-and-exit", fname), | |
ignore.stdout = TRUE, ignore.stderr=TRUE,wait = FALSE) | |
ps_out <- system("ps -eo pid,comm,etime| grep vlc", intern=TRUE) | |
This file contains 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(rjags) | |
library(mvtnorm) # to generate correlated data with rmvnorm. | |
library(car) # To plot the estimated bivariate normal distribution. | |
set.seed(31415) | |
mu <- c(10, 30) | |
sigma <- c(20, 40) | |
rho <- -0.7 | |
cov_mat <- rbind(c( sigma[1]^2 , sigma[1]*sigma[2]*rho ), | |
c( sigma[1]*sigma[2]*rho, sigma[2]^2 )) |
This file contains 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
Inlämningsuppgifter SM 1 & 2 | |
======================================================== | |
Rasmus Bååth, Sumsar Htååb | |
Detta är ett exempeldokumen skrivet med R markdown. | |
R markdown-dokumentet måste vara fristående från din nuvarande R session. | |
T.ex. så måste du i R markdown dokumentet alltid ladda in de paket du vill | |
använda även om de redan är inladdade i din nuvarande R-session: | |
```{r message=FALSE} |
This file contains 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
# Test of Significance, takes the same arguments as t.test() . | |
signif.test <- function(x, ...) { | |
p <- t.test(x, ...)$p.value | |
# List of p excuses retrieved from http://mchankins.wordpress.com/2013/04/21/still-not-significant-2/ | |
p_excuses <- c( | |
"(barely) not statistically significant <p>", | |
"a barely detectable statistically significant difference <p>", | |
"a borderline significant trend <p>", | |
"a certain trend toward significance <p>", |
NewerOlder