Skip to content

Instantly share code, notes, and snippets.

View dmasad's full-sized avatar

David Masad dmasad

View GitHub Profile
@kastnerkyle
kastnerkyle / mcts_tictactoe.py
Last active August 16, 2019 06:39
MCTS tictactoe, play 2 against each other, or play against it yourself
# Based on tutorial from https://jeffbradberry.com/posts/2015/09/intro-to-monte-carlo-tree-search/
# Author: Kyle Kastner
# License: BSD 3-Clause
from __future__ import print_function
import random
import copy
import numpy as np
import time
import argparse
import sys
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)
@karpathy
karpathy / min-char-rnn.py
Last active May 25, 2024 03:02
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@geotheory
geotheory / alluvial.R
Last active April 2, 2016 02:15
A function to make alluvial-style plots of simple categorical time-series data
require(grid)
require(scales)
require(reshape2)
# Notes:
# dat should be a 3 column data.frame with fields in order as per example below
# wave wavyness of curves defined in terms of x axis data range - experiment to get this right
# ygap gap between items on each y axis
# col a single colour or vector of colours for categories when listed in alphabetical order
# leg.mode if true legend plotted in largest data observation, otherwise custom coordinates (leg.x/y [0,1])
@GaelVaroquaux
GaelVaroquaux / mutual_info.py
Last active June 18, 2023 12:25
Estimating entropy and mutual information with scikit-learn: visit https://github.com/mutualinfo/mutual_info
'''
Non-parametric computation of entropy and mutual-information
Adapted by G Varoquaux for code created by R Brette, itself
from several papers (see in the code).
This code is maintained at https://github.com/mutualinfo/mutual_info
Please download the latest code there, to have improvements and
bug fixes.
@lmullen
lmullen / Makefile
Last active May 12, 2024 15:11
PDF slides and handouts using Pandoc and Beamer
SLIDES := $(patsubst %.md,%.md.slides.pdf,$(wildcard *.md))
HANDOUTS := $(patsubst %.md,%.md.handout.pdf,$(wildcard *.md))
all : $(SLIDES) $(HANDOUTS)
%.md.slides.pdf : %.md
pandoc $^ -t beamer --slide-level 2 -o $@
%.md.handout.pdf : %.md
pandoc $^ -t beamer --slide-level 2 -V handout -o $@
@gabraganca
gabraganca / output_toggle_html.tpl
Last active February 15, 2017 17:37
Template to use with `ipython nbconvert` when generating HTML. With this, all input cell are hidden. Thanks @damianavila for the initial setup (http://www.damian.oquanta.info/posts/hide-the-input-cells-from-your-ipython-slides.html). I have also take some code from the `custom.css` of @olgablot published in http://nbviewer.ipython.org/5357268.
{%- extends 'full.tpl' -%}
{% block input_group -%}
<div class="input_hidden">
{{ super() }}
</div>
{% endblock input_group %}
{%- block header -%}
{{ super() }}
@dsparks
dsparks / coefficent_plot_walkthrough.R
Created December 18, 2012 22:31
A coefficient plot for multiple models
doInstall <- TRUE
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
ANES <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/ANES.csv")
ANES <- ANES[ANES$year == 2008, -c(1, 11, 17)] # Limit to just 2008 respondents,
head(ANES) # remove some non-helpful variables
# Fit several models with the same DV: