Last active
December 13, 2015 19:09
-
-
Save cvanweelden/4961033 to your computer and use it in GitHub Desktop.
Minimization problem for sampling histograms
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
import cvxpy | |
import numpy as np | |
if __name__ == "__main__": | |
#The histogram data, 250 histograms with 3 bins | |
D = cvxpy.parameter(250,3,name='D') | |
D.value = cvxpy.matrix(np.random.randint(0,100,(250,3))) | |
#The weights, one for each histogram | |
w = cvxpy.variable(D.shape[0],name='w') | |
constraints = [] | |
for i in range(D.shape[0]): | |
constraints.append(cvxpy.geq(w[i,0],0)) | |
#Put the maximum difference as minimization objective | |
pairwise_difference = cvxpy.vstack([w.T*D]*D.shape[1])-cvxpy.hstack([(w.T*D).T]*D.shape[1]) | |
p = cvxpy.program(cvxpy.minimize(cvxpy.max(pairwise_difference)),constraints) | |
p.solve() | |
Author
cvanweelden
commented
Feb 15, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment