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 Stan: http://mc-stan.org/ . | |
# For installation instructions, see here: | |
# https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started | |
# After installation you should be able to run this script which should output | |
# some summary statistics and some pretty plots, :) | |
# Generating some fake data | |
set.seed(123) |
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
### An example of building a TensorFlow model from R using rPython ### | |
# For this script you need to | |
# 1. Have python 2.7 installed. | |
# 2. Install the rPython package in R. | |
# 3. Install Google's TensorFlow library as per these instructions: | |
# http://www.tensorflow.org/get_started/os_setup.md#binary_installation | |
### Here is how to setup and run a trivial TensorFlow model ### | |
# Load TensorFlow (I couldn't get this to work without setting sys.argv... ) |
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
--- | |
title: "A Bayesian Model to Calculate Whether My Wife is Pregnant or Not" | |
author: "Rasmus Bååth" | |
output: html_document | |
--- | |
```{r echo = FALSE} | |
library(knitr) | |
options(digits=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
# A Bayesian model that calculates a probability that a couple is fertile | |
# and pregnant. Please use this for fun only, not for any serious purpose | |
# like *actually* trying to figure out whether you are pregnant. | |
# Enter your own period onsets here: | |
period_onset <- as.Date(c("2014-07-02", "2014-08-02", "2014-08-29", "2014-09-25", | |
"2014-10-24", "2014-11-20", "2014-12-22", "2015-01-19")) | |
# If you have no dates you can just set days_between_periods to c() instead like: | |
# days_between_periods <- c() | |
days_between_periods <- as.numeric(diff(period_onset)) |
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
0 CLS | |
10 REM SETTING UP THE VARIABLES AND DATA | |
20 | |
30 REM NO OF PUPS PER DEN FROM A SAMPLE OF 16 WOLF DENS | |
40 DATA 5, 8, 7, 5, 3, 4, 3, 9, 5, 8, 5, 6, 5, 6, 4, 7 | |
50 | |
60 NDATA = 16 | |
70 NSAMPLES = 1000 | |
75 NBURNIN = 250 | |
80 NPARAMS = 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
--- | |
title: "Easy Bayesian Bootstrap in R" | |
author: "Rasmus" | |
date: "04/06/2015" | |
output: | |
html_document: | |
keep_md: yes | |
self_contained: no | |
--- |
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
# From https://aschinchon.wordpress.com/2015/06/23/the-2d-harmonograph-in-shiny/ | |
# All code by Antonio S. Chinchón (@aschinchon), just rearranged so that you can directly | |
# run it by copy and pasting it into an R console. | |
library(shiny) | |
CreateDS = function () { | |
f=jitter(sample(c(2,3),4, replace = TRUE)) | |
d=runif(4,0,1e-02) | |
p=runif(4,0,pi) | |
xt = function(t) exp(-d[1]*t)*sin(t*f[1]+p[1])+exp(-d[2]*t)*sin(t*f[2]+p[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
library(ggplot2) | |
library(plyr) | |
n_games <- readRDS("n_games.Rdata") | |
n_positions <- readRDS("n_positions.Rdata") | |
fullmoves_white <- readRDS("fullmoves_white.Rdata") | |
fits <- readRDS("chess_fits.Rdata") | |
fit <- fits$fit | |
fit <- fit |
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
# Takes the matrix created by this script: https://gist.github.com/rasmusab/fb98cced046d4c675d74 | |
# and calculates some statistics and fits some models to it. All this is pretty memory heavy so saving | |
# the interesting parts using saveRDS so the script only need to be run once. | |
set.seed(123) | |
games <- as.data.frame(readRDS("milionbase_matrix.rds")) | |
# Saving some info | |
n_games <- max(games[,"game_id"]) | |
fullmoves_white <- games[ games[, "fullmoves"] < 100 & games[,"active_player"] == 1, "fullmoves"] |
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
# Takes a json file describing chess games and produces a matrix with one row | |
# per turn showing how many pieces are left, one column per piece. | |
### Don't run this in R studio because it will take up twice the RAM | |
### as R will make copies instead of references. | |
library(jsonlite) | |
library(stringi) | |
# Path to your json file as produced by this script: https://gist.github.com/rasmusab/07f1823cb4bd0bc7352d |