Skip to content

Instantly share code, notes, and snippets.

@Kornel
Kornel / norm-vs-beta.ipynb
Created September 23, 2016 19:51
Normal vs Beta approximation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kornel
Kornel / mc_de_moivre.R
Last active September 14, 2016 09:29
Plotting "the most dangerous equation in the world": http://press.princeton.edu/chapters/s8863.pdf. Monte Carlo test how the standard deviation changes with respect to the sample size.
split.into.intervals <- function(what, interval.count = NULL, interval.size = NULL) {
if (sum(sapply(list(interval.count, interval.size), is.null)) != 1)
stop("exactly one of 'interval.count', 'interval.size', must be NULL")
if (!is.null(interval.count))
n <- length(what) / interval.count
else
n <- interval.size
@Kornel
Kornel / mc_norm_diff.R
Created September 12, 2016 08:29
Monte Carlo verification of two Normal Distributions difference
mean.a <- runif(1, min = -10, max = 10)
mean.b <- runif(1, min = -10, max = 10)
sd.a <- runif(1, min = 1, max = 10)
sd.b <- runif(1, min = 1, max = 10)
x <- seq(from = min(mean.a, mean.b) - 4 * max(sd.a, sd.b),
to = max(mean.a, mean.b) + 4 * max(sd.a, sd.b),
by = 0.1)
a <- dnorm(x, mean = mean.a, sd = sd.a)
@Kornel
Kornel / randomwalk.R
Created September 11, 2016 17:11
Random walk in R
library(ggplot2)
walk <- function(N, p = 0.5) {
cumsum((-1)^rbinom(N, 1, 1 - p))
}
# Convergence of the random walk
l <- sapply(1:1000, function(n){
N <- 100
tail(walk(N, 0.5), 1)
@Kornel
Kornel / push-and-pr.sh
Last active September 30, 2016 07:50
Push to bitbucket (stash) and create pull-request
#!/bin/sh
REMOTE_BRANCH=$1
if [[ -z "${REMOTE_BRANCH}" ]]
then
REMOTE_BRANCH="develop"
fi
USER=`whoami`
PROJECT=`git remote -v | grep push | awk -F"/" ' { print $4 } '`
REPO=`git remote -v | grep push | awk -F"/" ' { print $5 } ' | sed 's/\.git.*//'`
@Kornel
Kornel / decision-boundaries.Rmd
Created March 25, 2016 11:00
Decision boundaries for a MLP, SVM and a Random Forest
---
title: "Decision boundaries"
author: "Kornel Kiełczewski"
date: "25 March 2016"
output: html_document
---
Decision boundaries for a somewhat biased test case :)
```{r, echo=FALSE, message=FALSE, warning=FALSE}
@Kornel
Kornel / nnet-decision-boundary.R
Created March 25, 2016 09:50
Decision boundary for MLP
set.seed(1)
pts <- seq(0, 360, 10)
x1 <- c(sapply(pts, function(x) cos(x)),
sapply(pts, function(x) cos(x) * 4),
sapply(pts, function(x) cos(x) * 6))
x2 <- c(sapply(pts, function(x) sin(x)),
sapply(pts, function(x) sin(x) * 4),
sapply(pts, function(x) sin(x) * 6))
@Kornel
Kornel / nnet-decision-boundary.R
Created March 24, 2016 18:19
Decision boundary nnet
library(nnet)
n <- 20
x1 <- rnorm(n)
x2 <- rnorm(n)
y <- as.factor(rbinom(n, 1, 0.5))
data <- data.frame(x1, x2, y)
fit <- nnet(y ~ ., data, size = 10)
@Kornel
Kornel / pull-all.sh
Created February 12, 2016 08:28
Pull all git subdirectories - if successful, be quiet.
#!/usr/bin/env bash
quiet_git() {
tempfile=`mktemp /tmp/git-pull-all-XXXXXXXX`
stdout=$tempfile
stderr=$tempfile
if ! git "$@" </dev/null >$stdout 2>$stderr; then
cat $stderr >&2
@Kornel
Kornel / recursive-cowsay.sh
Last active February 4, 2016 14:18
Recursive cowsay inception - random cow at every step
#!/usr/bin/env bash
COWS_PATH="/usr/local/share/cows"
COW_FILES=($(ls $COWS_PATH))
COWS=${#COW_FILES[@]}
rand_cow() {
#RAND_IDX=$(($RANDOM % $COWS))
RAND_IDX=$((`od -vAn -N4 -tu4 < /dev/urandom` % $COWS))