title: Is there a way where I can optimize the output restricting the parameters in fmin from scipy.optimize
body: <p><strong>What I am doing:</strong> I modified the code from the zombie invasion system to demonstrate how it should be written and tried to optimize the least square error (defined as score function) with the fmin function.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.integrate import odeint
  from scipy import integrate
  from scipy.optimize import fmin
  #=====================================================
  #Notice we must import the Model Definition
  from zombiewithdata import eq
  #=====================================================
  
  #1.Get Data
  #====================================================
  Td=np.array([0.5,1,1.5,2,2.2,3,3.5,4,4.5,5])#time
  Zd=np.array([0,2,2,5,2,10,15,50,250,400])#zombie pop
  #====================================================
  
  #2.Set up Info for Model System
  #===================================================
  # model parameters
  #----------------------------------------------------
  P = 0       # birth rate
  d = 0.0001  # natural death percent (per day)
  B = 0.0095  # transmission percent  (per day)
  G = 0.0001  # resurect percent (per day)
  A = 0.0001  # destroy perecent (per day)
  rates=(P,d,B,G,A)
  
  # model initial conditions
  #---------------------------------------------------
  S0 = 500.               # initial population
  Z0 = 0                  # initial zombie population
  R0 = 0                  # initial death population
  y0 = [S0, Z0, R0]      # initial condition vector
  
  # model steps
  #---------------------------------------------------
  start_time=0.0
  end_time=5.0
  intervals=1000
  mt=np.linspace(start_time,end_time,intervals)
  
  # model index to compare to data
  #----------------------------------------------------
  findindex=lambda x:np.where(mt&gt;=x)[0][0]
  mindex=map(findindex,Td)
  #=======================================================
  
  
  
  #3.Score Fit of System
  #=========================================================
  def score(parms):
      #a.Get Solution to system
      F0,F1,F2,T=eq(parms,y0,start_time,end_time,intervals)
      #b.Pick of Model Points to Compare
      Zm=F1[mindex]
      #c.Score Difference between model and data points
      ss=lambda data,model:((data-model)**2).sum()
      return ss(Zd,Zm)
  #========================================================
  
  
  #4.Optimize Fit
  #=======================================================
  fit_score=score(rates)
  answ=fmin(score,(rates),full_output=1,maxiter=1000000)
  bestrates=answ[0]
  bestscore=answ[1]
  P,d,B,G,A=answ[0]
  newrates=(P,d,B,G,A)
  #=======================================================
  
  #5.Generate Solution to System
  #=======================================================
  F0,F1,F2,T=eq(newrates,y0,start_time,end_time,intervals)
  Zm=F1[mindex]
  Tm=T[mindex]
  #======================================================
  </code></pre>
  
  <p>Now in the #optimize fit section, is there any way I can get best possible values of bestrates when I restrict the values of "rates" like lb &lt;= P, d, B, G, A &lt;= ub where lb=lower bound and ub=upper bound and manage to get minimum of score in that restricted region? It need not be the most optimized value. fmin uses Nelder-Mead (simplex) algorithm. </p>
  
  <p>I am quite new to this, so any help in the right direction would be awesome. Feel free to ask any doubts regarding the code and I will answer to best of my knowledge. . Thank You.</p>