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
# 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 |
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
# 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 |
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
# 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 |
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
# 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) |
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
# 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) |
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
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 |
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
#!/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 |
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
# | |
# 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 |
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
#!/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 | |
# |
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
#!/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. |
OlderNewer