title: scipy-optimize-minimize does not perform the optimization - CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL
body: <p>I am trying to minimize a function defined as follows:</p>
  <pre><code>utility(decision) = decision * (risk - cost)
  </code></pre>
  <p>where variables take the following form:</p>
  <blockquote>
  <p>decision = binary array</p>
  <p>risk = array of floats</p>
  <p>cost = constant</p>
  </blockquote>
  <p>I know the solution will take the form of:</p>
  <blockquote>
  <p>decision = 1 <em>if (risk &gt;= threshold)</em></p>
  <p>decision = 0 <em>otherwise</em></p>
  </blockquote>
  <p>Therefore, in order to minimize this function I can assume that I transform the function utility to depend only on this threshold. My direct translation to scipy is the following:</p>
  <pre><code>def utility(threshold,risk,cost):
  
       selection_list = [float(risk[i]) &gt;= threshold for i in range(len(risk))]
       v = np.array(risk.astype(float)) - cost
  
       total_utility = np.dot(v, selection_list)
  
       return -1.0*total_utility
  
  result = minimize(fun=utility, x0=0.2, args=(r,c),bounds=[(0,1)], options={&quot;disp&quot;:True} )
  </code></pre>
  <p>This gives me the following result:</p>
  <pre><code>fun: array([-17750.44298655])  hess_inv: &lt;1x1 LbfgsInvHessProduct with
  dtype=float64&gt;
  jac: array([0.])   
  message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_&lt;=_PGTOL'
  nfev: 2
  nit: 0    status: 0   success: True
  x: array([0.2])
  </code></pre>
  <p>However, I know the result is wrong because in this case it must be equal to <em>cost</em>. On top of that, no matter what x0 I use, it always returns it as the result. Looking at the results I observe that jacobian=0 and does not compute 1 iteration correctly.</p>
  <p>Looking more thoroughly into the function. I plot it and observe that it is not convex on the limits of the bounds but we can clearly see the minimum at 0.1. However, no matter how much I adjust the bounds to be in the convex part only, the result is still the same.</p>
  <p><a href="https://i.stack.imgur.com/ELOPj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ELOPj.png" alt="Function plot" /></a></p>
  <p>What could I do to minimize this function?</p>