title: How to decide initial parametervalues for curve fitting with lmfit
body: <p>I'm currently working on a non-linear fit for several data coming from a DMA test (rheology).
  For the data I'm currently working with, the program works BUT i want the program to be flexible in a way that the starting parameters for the curve fitting are dependent of the input of my data. Is there a way to determine this?</p>
  <p>Maybe something with a Monte Carlo method, but I don't know where to start.</p>
  <p>This is my code, thanks in advance! :</p>
  <pre><code>def calc_gmm(dframe):
      array_omega = np.array(dframe['Angular Frequency']).flatten()
      array_G_storage = np.array(dframe['Storage Modulus']).flatten()
      array_G_loss = np.array(dframe['Loss Modulus']).flatten()
  
      chisqr = 99999999999;
      j=1
  
  
      fig, (ax1,ax2) = plt.subplots(nrows=2, ncols=1)
  
  
      while j &lt;= 10:
          params = lmfit.Parameters()
  
          # Adding amount n of parameters and G0, start values were determined by trial and error
          params.add('n', value=j, vary=False, min=1, max=10)
          params.add('G0', value=0.4, min=0)
          for i in range(params['n'].value):
              params.add(f't_{i}', value=0.5, min=0)
              params.add(f'g_{i}', value=17, min=0)
  
          # Minimization function
          res = lmfit.minimize(min_function, params, args=(array_omega, array_G_storage, array_G_loss))
  
          # Determining the smallest chi-squared in order to develop a criterium to stop iterating over different orders
          if res.chisqr &lt; chisqr*0.5:
              chisqr = res.chisqr
              ax1.plot(array_omega, array_G_storage + res.residual, label='n: '+ (str)(j))
              ax2.plot(array_omega, array_G_loss + res.residual, label='n: '+ (str)(j))
              j += 1
          else:
              params = lmfit.Parameters()
              j -= 1
              # Adding amount n of parameters and G0, start values were determined by trial and error
              params.add('n', value=j, vary=False, min=1, max=10)
              params.add('G0', value=0.4, min=0)
              for i in range(params['n'].value):
                  params.add(f't_{i}', value=0.5, min=0)
                  params.add(f'g_{i}', value=17, min=0)
  
              # Minimization function
              res = lmfit.minimize(min_function, params, args=(array_omega, array_G_storage, array_G_loss))
  
              j = 11
  </code></pre>