4

I am trying to use minimize function from scipy.optimize

From the documentation I was able to set bounds for x (For example: [0,12]). However I'm unable to figure out how to set them as integers.

ans = minimize(lambda x: total_rsquared(training_size, x),
                   [0,1,2,3,4],
                   method='SLSQP',
                   constraints=cons,
                   bounds=([0, 12], [0, 12], [0, 12], [0, 12], [0, 12]))

When I try with above code, x is being set to decimal values (For example: [1.0 11.1 5.4 6.9 3.4]). How do I set x values to integers?? Thanks!!

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
ThReSholD
  • 668
  • 10
  • 15
  • 3
    **You can't**. None of the solvers available in scipy is supporting mixed-integer programming. (and this discrete nature only makes those problems much harder in general). You will need to use some lib supporting MINLP (or something more specific if you know your problem-structure a-priori: the name of your func indicates a MIQP / MISOCP problem which can be easier to solve than MINLP) – sascha Feb 12 '18 at 22:09
  • 2
    If your function is convex and defined for non-integer numbers, if you can find the global optimum, the integer that minimizes it is a neighbour of this gloal minimizer (eg : in 1D, if you find x=5.2 at minimum, the integer minimum is either 5 or 6) – Joseph Budin Feb 12 '18 at 22:19

0 Answers0