code: def residual(p, just_generative=False):
      v = p.valuesdict()
      generative = v["a"] + v["b"] * x
      M = 0
      while f"a_max{M}" in v:
          generative += gauss(
              x, v[f"a_max{M}"], v[f"loc{M}"], v[f"sd{M}"]
          )
          M += 1
  
      if just_generative:
          return generative
      return (generative - y) / dy
  
imports: import matplotlib.pyplot
  import numpy
  import lmfit
label_desc: Use image node_id 2 for calling a global function with example usage: residual(p, just_generative) and returns: unknown, generative