Skip to content

Instantly share code, notes, and snippets.

""" IMPORTANT REMARK:
This is an IP-approach.
Simple examples, like the one given in the question, result in a model for which it SEEMS, produce integral basic feasible solutions.
This MIGHT indicate that the constraint matrix is totally unimodular and no IP/branching is necessary as an pure LP-solver will do.
To try this, change the following:
x = cvx.Variable((N_BLOCKS, N_SLOTS)) #, boolean=True) = now continuous variables
import numpy as np
from scipy.optimize import minimize_scalar, minimize
import matplotlib.pyplot as plt
""" EXAMPLE PROB """
N_EVAL = 5
N_BOUNDS = (0., 1.2)
grid1d = np.linspace(*N_BOUNDS, N_EVAL)
import itertools
import networkx as nx
""" DATA """
S = ('S', [0, 1, 2]) # ranking: good to bad
K = ('K', [1, 2, 0])
L = ('L', [1, 2, 0])
D = ('D', [0, 2, 1])
A = ('A', [0, 2, 1])
J = ('J', [2, 1, 0])
@sschnug
sschnug / scipy.py
Created October 25, 2017 15:40
example callback change
import numpy as np
from scipy import optimize
### Setup inputs to the optimizer
def power_curve(x,beta1,beta2):
return beta1*x**beta2
def mm_curve(x,beta1,beta2):
"Beta2 >= 0"
import numpy as np
from cvxpy import *
from scipy.spatial.distance import pdist, squareform
# Based on formulation described
# @ https://en.wikipedia.org/wiki/Travelling_salesman_problem (February 2016)
np.random.seed(1)
N = 5
@sschnug
sschnug / lasso_init_sklearn_demo.py
Last active October 3, 2018 06:38
lasso init in sklearn
import numpy as np
from sklearn.datasets.samples_generator import make_regression
from sklearn.linear_model import Lasso
X, y = make_regression(n_samples=200, n_features=5000, random_state=0)
dense_lasso = Lasso(alpha=1, fit_intercept=False, max_iter=1000)
dense_lasso.fit(X, y)
print('iterations needed: ', dense_lasso.n_iter_)
init_lasso = Lasso(alpha=1, fit_intercept=False, max_iter=1000, warm_start=True)
@sschnug
sschnug / mpv_log.txt
Created July 5, 2017 23:58
mpv log playing mp4 with cenc-aes-ctr
[ 0.006][v][cplayer] mpv 0.25.0-289-g69289aec6c (C) 2000-2017 mpv/MPlayer/mplayer2 projects
[ 0.006][v][cplayer] built on Sat Jul 1 13:00:45 UTC 2017
[ 0.006][v][cplayer] ffmpeg library versions:
[ 0.006][v][cplayer] libavutil 55.67.100
[ 0.006][v][cplayer] libavcodec 57.100.103
[ 0.006][v][cplayer] libavformat 57.75.100
[ 0.006][v][cplayer] libswscale 4.7.101
[ 0.006][v][cplayer] libavfilter 6.94.100
[ 0.006][v][cplayer] libswresample 2.8.100
[ 0.006][v][cplayer] ffmpeg version: N-45219-g0eb783eb06
@sschnug
sschnug / seafile_git_clone.log
Created June 19, 2017 13:29
seafile_git_clone.log
[06/19/17 15:26:15] seadrive.c(589): Starting SeaDrive client 0.7.0
[06/19/17 15:26:15] seadrive.c(614): rpc server started.
[06/19/17 15:26:15] dokan-ops.(2358): GetVolumeInformation called.
[06/19/17 15:26:15] dokan-ops.(2438): Mounted called.
[06/19/17 15:26:16] dokan-ops.(1054): CreateFile \ called. desired_access: 0x100000, share_access: 0, file_attributes: 0x0,create_disposition: 0x3, create_options: 0x21
[06/19/17 15:26:16] dokan-ops.(205): GetFileInformation \ called.
[06/19/17 15:26:16] dokan-ops.(205): GetFileInformation \ called.
[06/19/17 15:26:16] dokan-ops.(2358): GetVolumeInformation called.
[06/19/17 15:26:16] dokan-ops.(2358): GetVolumeInformation called.
[06/19/17 15:26:16] dokan-ops.(2063): Cleanup \ called.
@sschnug
sschnug / seafile.log
Created June 19, 2017 13:24
seafile.log
[06/19/17 14:43:29] dokan-ops.(205): GetFileInformation \Meine Bibliothek\seafile-tutorial.doc called.
[06/19/17 14:43:29] dokan-ops.(2063): Cleanup \Meine Bibliothek\seafile-tutorial.doc called.
[06/19/17 14:43:29] dokan-ops.(2120): Close \Meine Bibliothek\seafile-tutorial.doc called.
[06/19/17 14:43:29] dokan-ops.(1054): CreateFile \ called. desired_access: 0x100000, share_access: 0, file_attributes: 0x0,create_disposition: 0x3, create_options: 0x21
[06/19/17 14:43:29] dokan-ops.(2358): GetVolumeInformation called.
[06/19/17 14:43:29] dokan-ops.(2063): Cleanup \ called.
[06/19/17 14:43:29] dokan-ops.(2120): Close \ called.
[06/19/17 14:43:29] dokan-ops.(1054): CreateFile \Meine Bibliothek\seafile-tutorial.doc called. desired_access: 0x100080, share_access: 7, file_attributes: 0x80,create_disposition: 0x3, create_options: 0x20
[06/19/17 14:43:29] dokan-ops.(602): Open file seafile-tutorial.doc in repo Meine Bibliothek(31aa178f)
[06/19/17 14:43:29] dokan-ops.(205): GetFileInformation \Meine Bibliothek\seafile
#include "Halide.h"
#include "Halide/tools/halide_image_io.h"
#include <iostream>
// This code calculates a block based mean on some a-priori known image-dimensions (1 uint8_t channel)
// An example image to process: http://i.imgur.com/Eyo0Xvc.png
// No customized scheduling within this code, but the SO-answer gives some recommendation!
int main(int argc, char **argv) {
Halide::Buffer<uint8_t> input = Halide::Tools::load_image("TestImages/block_example.png");