Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Walker rwalk

View GitHub Profile
@rwalk
rwalk / bigTent.R
Created Jan 27, 2015
Quadratic programming demo: Circus Tent
View bigTent.R
# This gist uses rgl and quadprog to draw a circus tent
# by solving a quadratic program in R. The original problem is from the MathWorks MATLAB demo at:
# http://www.mathworks.com/help/optim/examples/large-scale-bound-constrained-quadratic-programming.html
#
# More information on this problem at:
# http://quantitate.blogspot.com/2014/04/the-circus-tent-problem-with-rs-quadprog.html
#
# author: R. Walker (r_walker@zoho.com)
# LICENSE: MIT
@rwalk
rwalk / svm_solver_compare.R
Last active Jan 27, 2020
R: Solve the SVM minimization problem with quadprog and ipop
View svm_solver_compare.R
# This gist solves the hard-margin SVM problem in three ways: using quadprog, using kernlab's ipop, and by
# the e1071 wrapper around libsvm.
#
# author: R. Walker (r_walker@zoho.com)
# LICENSE: MIT
library("quadprog")
library("kernlab")
library("e1071")
# Use Fisher iris data and binarize one of the species
@rwalk
rwalk / svm_tm_example.R
Last active Jan 11, 2016
R: SVM example to predict "crude" topic in Reuters21578 Corpus
View svm_tm_example.R
# This gist samples positive and negative examples of a topic
# in the Reuters21578 corpus using R's "tm" package to manage
# the data. After some simple transformations to the text,
# the data are extracted to a document-term matrix and a simple
# SVM model is fit to classify positive examples of the topic.
#
# author: R. Walker (r_walker@zoho.com)
# LICENSE: MIT
#
# NOTE: Download the full Reuters21578 corpus from
@rwalk
rwalk / qp_solver_compare.R
Created Feb 28, 2015
Compare 3 QP solvers on a demo problem in R
View qp_solver_compare.R
# This gist compares three methods for solving a quadratic program in R.
# The original problem is from the MathWorks MATLAB demo at:
# http://www.mathworks.com/help/optim/examples/large-scale-bound-constrained-quadratic-programming.html
#
# More information on this problem at:
# http://quantitate.blogspot.com/2014/04/the-circus-tent-problem-with-rs-quadprog.html
#
# author: R. Walker (r_walker@zoho.com)
# LICENSE: MIT
library(quadprog)
@rwalk
rwalk / qp_experiment_random.R
Created Mar 8, 2015
Quadratic Programming: Compare three methods for solving a randomly generated QP in R
View qp_experiment_random.R
# This gist compares three methods for solving a randomly generated quadratic program in R.
# author: R. Walker (r_walker@zoho.com)
# LICENSE: MIT
library(quadprog)
library(kernlab)
library(ipoptr)
library(ggplot2)
library(reshape2)
#########################################################
# Random QP Generation (in the style of quadprog)
@rwalk
rwalk / quadprog_ipoptr_translate.R
Created Mar 8, 2015
Quadratic programming: Use matrix inputs to solve a QP with ipoptr
View quadprog_ipoptr_translate.R
ipoptr_qp <- function(Dmat, dvec, Amat, bvec, ub=100){
# Solve the quadratic program
#
# min -d^T x + 1/2 x^T D x
# s.t. A%*%x>= b
#
# with ipoptr.
n <- length(bvec)
# Jacobian structural components
@rwalk
rwalk / autocomplete.py
Last active Aug 29, 2015
Autocomplete with a trie
View autocomplete.py
#!/usr/bin/python3
'''
Autocompletion using a trie and a user supplied language file.
HINT: Linux/Unix users can look in "/usr/share/dict" for language files.
Author: rwalker
Email: r_walker@zoho.com
License: MIT
'''
import argparse, os, sys
@rwalk
rwalk / autocompleter
Last active Aug 29, 2015
Autocompleter running in Docker
View autocompleter
#
# Docker demo: container for a simple autocomplete program
# Autocomplete script is python3 and consumes a dictionary
# file packaged in the ubuntu operating system.
#
# start with the base ubuntu image
FROM ubuntu
# Tell apt-get that we are going to be NONINTERACTIVE
@rwalk
rwalk / elasticsearch_quickstart.py
Created Sep 17, 2015
Quickstart elasticsearch with Python
View elasticsearch_quickstart.py
#!/usr/bin/python3
# This script is a simple introduction to the python elasticsearch API.
#
# This script will populate an elasticsearch index from a file and then give a simple command line query interface.
# Each line of the input file will be mapped into a JSON document of the form { "text": "my file line..." } and added
# to the index.
#
# You can use Docker to spin up a local elasticsearch instance to play around with, e.g.
# docker run --name elasticsearch -d -p 9200:9200 elasticsearch:latest
#
View kafka_stream_producer.py
#!/usr/bin/python3
'''
Put documents from the stream into Kafka
'''
import argparse
from kafka import SimpleProducer, KafkaClient
from time import sleep
def chunk_iterable(A,n):
'''An iterable that contains the iterates of A divided into lists of size n.