0

I'm using a Python package called lmfit to create a model:

from lmfit import Model
def PnE(E, sigma, n, E_k, overlap):
    return ((1+np.exp(-(E_k-E)*sigma))**n*overlap)

To create a model, by instruction, I will do model = Model(PnE).

However, I wonder if I can create a function, which allows me to replace the variables sigma and n with different values. In other words, I want to generate different models, which have similar structures but only differ by sigma and n. I tried

def fit_PnE(sigma, n):
    G = functools.partial(PnE, sigma, n)
    model = Model(G)

But it returns NameError: name 'E_k' is not defined. How can I define such a function that generates similar models? Thanks!!

IGY
  • 199
  • 1
  • 4
  • Does this answer your question? [Pass a function as a variable with one input fixed](https://stackoverflow.com/questions/22028640/pass-a-function-as-a-variable-with-one-input-fixed) – mkrieger1 Jul 24 '22 at 19:03
  • how is "have similar structures but only differ by `sigma` and `n`" different from "are different model functions"? You could create a more general version that your different (more restricted?) model functions call. But also: you know that you could just fix the values of the `sigma`, `n`, `E_k`, or `overlap` parameters when using the model, right? As it turns out, `lmfit.Model` doesn't work with "partial functions" because it works by inspection of the call signature of the model function. – M Newville Jul 25 '22 at 05:07
  • I know you're using `Model`, but what about creating different `Parameters`, and set `sigma` and `n` to `vary=False` and a specific value? – K.Cl Jul 25 '22 at 10:55

0 Answers0