Skip to content

Instantly share code, notes, and snippets.

View xboard's full-sized avatar
🏠
Working from home

Flavio xboard

🏠
Working from home
View GitHub Profile
@kjlubick
kjlubick / ISMCTS.py
Created September 21, 2015 01:18
An example of Information Set Monte Carlo Tree Search from http://www.aifactory.co.uk/newsletter/2013_01_reduce_burden.htm
# This is a very simple Python 2.7 implementation of the Information Set Monte Carlo Tree Search algorithm.
# The function ISMCTS(rootstate, itermax, verbose = False) is towards the bottom of the code.
# It aims to have the clearest and simplest possible code, and for the sake of clarity, the code
# is orders of magnitude less efficient than it could be made, particularly by using a
# state.GetRandomMove() or state.DoRandomRollout() function.
#
# An example GameState classes for Knockout Whist is included to give some idea of how you
# can write your own GameState to use ISMCTS in your hidden information game.
#
# Written by Peter Cowling, Edward Powley, Daniel Whitehouse (University of York, UK) September 2012 - August 2013.
@mblondel
mblondel / nmf_cd.py
Last active June 12, 2019 20:00
NMF by coordinate descent
"""
NMF by coordinate descent, designed for sparse data (without missing values)
"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
import scipy.sparse as sp
import numba
@jamestrimble
jamestrimble / census_data_for_online_map.r
Last active January 17, 2017 19:03
An R script to prepare the data for ukdataexplorer.com/census/ Based on work by Alex Singleton, http://www.alex-singleton.com/2011-census-open-atlas-project/
# Script to create data for http://ukdataexplorer.com/census/
# Author James Trimble, james.trimble at yahoo.co.uk
#
# This code is based on Alex Singleton's work:
# http://rpubs.com/alexsingleton/openatlas
# http://www.alex-singleton.com/2011-census-open-atlas-project/
#
# The script takes around an hour to run. It could be made faster!
# The script requires a lookup table and shapefile from
# https://geoportal.statistics.gov.uk/geoportal/catalog/search/browse/browse.page
@mblondel
mblondel / kernel_kmeans.py
Last active January 4, 2024 11:45
Kernel K-means.
"""Kernel K-means"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from sklearn.base import BaseEstimator, ClusterMixin
from sklearn.metrics.pairwise import pairwise_kernels
from sklearn.utils import check_random_state
@cjbayesian
cjbayesian / bayes_update.R
Created August 16, 2012 20:23
generate a video demonstrating Bayesian updating
## Corey Chivers, 2012 ##
sim_bayes<-function(p=0.5,N=100,y_lim=20,a_a=2,a_b=10,b_a=8,b_b=3)
{
## Simulate outcomes in advance
outcomes<-sample(1:0,N,prob=c(p,1-p),replace=TRUE)
success<-cumsum(outcomes)
for(frame in 1:N)
{
png(paste("plots/",1000+frame,".png",sep=""))
/**
* Fast non-maximum suppression in C, port from
* http://quantombone.blogspot.com/2011/08/blazing-fast-nmsm-from-exemplar-svm.html
*
* @blackball (bugway@gmail.com)
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
@mshivers
mshivers / nnlr
Created February 3, 2012 15:46
L2 Regularized Non-negative logistic regression
import scipy as sp
from scipy import optimize as opt
def nnlr(X, y, C):
"""
Non-negative Logistic Regression with L2 regularizer
"""
def lr_cost(X, y, theta, C):
m = len(y)
return (1./m) * (sp.dot(-y, sp.log(sigmoid(sp.dot(X, theta)))) \
@quantombone
quantombone / nms_fast.m
Created August 14, 2011 00:26
blazing fast nms (non-maximum suppression)
function top = nms(boxes, overlap)
% top = nms_fast(boxes, overlap)
% Non-maximum suppression. (FAST VERSION)
% Greedily select high-scoring detections and skip detections
% that are significantly covered by a previously selected
% detection.
% NOTE: This is adapted from Pedro Felzenszwalb's version (nms.m),
% but an inner loop has been eliminated to significantly speed it
% up in the case of a large number of boxes
% Tomasz Malisiewicz (tomasz@cmu.edu)
@blinks
blinks / scanner.py
Created January 16, 2009 16:43
A simple Python token scanner.
"""
Scanner: match text to generate tokens.
Adam Blinkinsop <blinks@acm.org>
First, construct a scanner with the tokens you'd like to match described as
keyword arguments, using Python-syntax regular expressions.
WARNING: Group syntax in these expressions has an undefined effect.
>>> simple = Scan(ID=r'\w+')