Skip to content

Instantly share code, notes, and snippets.

@rwalk
rwalk / svm_solver_compare.R
Last active January 27, 2020 16:41
R: Solve the SVM minimization problem with quadprog and ipop
# 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 / qp_experiment_random.R
Created March 8, 2015 18:29
Quadratic Programming: Compare three methods for solving a randomly generated QP in 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 March 8, 2015 23:22
Quadratic programming: Use matrix inputs to solve a QP with ipoptr
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