Skip to content

Instantly share code, notes, and snippets.

@sschnug
sschnug / gist:436b595505c61cb6a8da2abb287ee59b
Created March 21, 2017 18:11 — forked from fepa/gist:2187179
A makefile for gecode projects (created this for the ID2204 course at KTH)
# Configure this makefile if needed then run
# $ make all
# to compile and link
# What files to compile
OBJS=money.cpp
# What file to compile to
MAINFILE=money
# What compiler to use
CC=g++
@sschnug
sschnug / mps_import.py
Created March 11, 2017 16:49
MPS-import for scipy.linprog benchmarking
""" Hacky import & solving of MPS-files (only tested for netlib)
- source of mps-files: http://www.netlib.org/lp/data/
- instances need to be uncompressed -> see readme in link-folder
- uses cvxopt's mps-parsing
- internal problem-modification / canonicalization by cvxopt "_inmatrixform"
- only implemented / tested for problems without explicit bound-/range-constraints
- see problem table within readme in link-folder for instance-type table
- probably ugly/unnecessary dense/sparse-stuff (code is old and hacky)
- just to be careful: cvxopt's license is not compatible with scipy!
@sschnug
sschnug / compare.py
Last active October 4, 2016 17:48
Comparison of different approaches for SO-question https://goo.gl/MjADHs
import numpy as np
import time
from scipy.optimize import minimize, nnls
from cvxpy import *
np.random.seed(1)
""" Test-data generator """
def create_test_data(samples, features, noise, loc=10, scale=2.5):
m = np.random.normal(loc=loc, scale=scale, size=(samples, features))
@sschnug
sschnug / plot.py
Created September 30, 2016 14:08
Example plot
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1)
N = 1000
r= np.random.randn(N)
x = np.exp(0.01 * np.arange(N)) + 0.2
y = np.exp(0.4 * np.arange(N)+r)
plt.loglog(x,y,label="Hello ")
plt.axvline(x=1.2, color='g')
from gurobipy import *
m = Model("model")
x = m.addVar(lb=0.0, name="x")
y = m.addVar(lb=0.0, name="y")
m.update()
obj = -x*x - y*y
m.setObjective(obj) # default: minimize
@sschnug
sschnug / trimodal_fit.jl
Created February 26, 2016 20:26
Trimodal Gaussian Fit (MLE-opt by JuMP)
using JuMP, AmplNLWriter, NLopt
n = 1000
mu1_true = 0.3
mu2_true = 0.55
mu3_true = 0.10
sig1_true = 0.08
sig2_true = 0.12
sig3_true = 0.32
a_0_true = 0.5