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(dplyr) | |
library(ggplot2) | |
length_army <- 60 | |
army_front <- function(x) (length_army * x) + length_army | |
army_back <- function(x) (length_army * x) | |
velocity_king <- length_army + length_army * sqrt(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
data { | |
int<lower=0> N; // N games | |
int<lower=0> P; // P teams | |
// Each team is referred to by an integer that acts as an index for the ratings vector. | |
int team1[N]; // Indicator arrays for team 1 | |
int team2[N]; // Indicator arrays for team 1 | |
int results[N]; // Results. 1 if home win, 2 if draw, 3 if away win. | |
real<lower=0> nu_sigma; |
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(tidyverse) | |
library(gganimate) | |
library(ggforce) | |
library(tweenr) | |
# Making up data | |
n_balls <- 20 | |
d <- tibble(x = rnorm(n_balls), | |
y = rnorm(n_balls), | |
time = sample(100, n_balls), |
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 python script to test strategies for the for the riddle described on TED-ed's | |
youtube channel: www.youtube.com/watch?v=dh4nEuhZBgg | |
Your interstellar police squad has tracked a group of criminals to a cluster of | |
seven planets. Now you must apprehend them before their reinforcements arrive. | |
Of course, the fugitives won’t just stay put – they’ll try to dodge you by | |
moving from planet to planet. Can you devise a sequence for searching the | |
planets that’s guaranteed to catch them in ten warps or less? | |
Edwin F. Meyer shows how. |
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(tidyverse) | |
library(tidytext) | |
# Load data ---- | |
# Slightly different to https://juliasilge.com/blog/word-vectors-take-two/ | |
# just because I have this data locally | |
austen_text <- janeaustenr::northangerabbey %>% | |
as_tibble() %>% |
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(tidyverse) | |
stirling_formula <- function(n) sqrt(2*pi*n)*(n / exp(1))^n | |
x <- 1:10 | |
breaks_log10 <- 1:10 %>% | |
map_dbl(~ 10^.x) %>% | |
map(~ .x*(1:10)) %>% | |
unlist() |
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
log <- function(f, ...) { | |
function_name <- as.character(substitute(f)) | |
dots <- list(...) | |
args <- paste0(dots, collapse = ",") | |
function_result <- f(...) | |
print(stringr::str_glue("{function_name}({args}) -> {function_result}")) | |
function_result |
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(tidyverse) | |
library(rgdal) | |
library(plotKML) | |
#Set input and output directories | |
os50_contours_dir <- here::here("~/Downloads/contours/") | |
output_dir <- here::here("~/Downloads/kml/") | |
#Load all shapefiles in input directory | |
shape_filenames <- list.files(os50_contours_dir, "*line.shp") |
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
# CF: www.coursera.org/learn/ml-clustering-and-retrieval/lecture/aZCHX/optional-improving-efficiency-through-multiple-tables | |
tibble(x = seq(0, 0.20, 0.001)) %>% | |
crossing(h = 1:4) %>% | |
mutate(single = 1 - (1-x)^h -h*x*(1-x)^(h-1), | |
multiple = (1 - (1-x)^h)^(h+1), | |
n_lines = h + 1) %>% | |
gather(key, value, -x, -h, -n_lines) %>% | |
ggplot(aes(x = x, y = value, | |
colour = key, group = key)) + | |
geom_path() + |
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
tau <- function(hg, ag, home_rates, away_rates, rho) { | |
case_when( | |
(hg == 0) && (ag == 0) ~ 1 - home_rates * away_rates * rho, | |
(hg == 0) && (ag == 1) ~ 1 + home_rates * rho, | |
(hg == 1) && (ag == 0) ~ 1 + away_rates * rho, | |
(hg == 1) && (ag == 1) ~ 1 - rho, | |
TRUE ~ 1 | |
) | |
} |
OlderNewer