Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging Variables for Lambda
    text
    copied!<p>I'm writing a Python program using scipy (scipy.optimize.curve_fit). I have to fit multiple curves over a dataset, and then sum them up. The first step is finding all maxima, which is done. There will be at least one, but usually more. I want to generalise something like the following.</p> <pre><code>if (len(Maxima) == 1): f = lambda a, b, c : a * exp((b * x) + c) else if (len(Maxima) == 2): f = lambda a, b, c, d, e, f : (a * exp((b * x) + c)) + (d * exp((e * x) + f) </code></pre> <p>And so forth. I need it so curve_fit will recognise that there are are (3 * Maxima) parameters, where it will then find them for me. There could be up to 20 curves or so, so doing the above statement is not practical.</p> <p>Any help would be appreciated.</p> <p>Thanks.</p> <p>Edit: Sorry, I missed out that the function has a dependency on the maxima. It's actually a Gaussian distribution centralised on each maxima.</p> <p>I.e. a term is actually</p> <pre><code>f = (a * (Gamma ** 2) / (((E - Maxima[i])**2) + (b**2))) </code></pre> <p>And E is the independent variable that args must start with.</p> <p>For example, for</p> <pre><code>len(Maxima) == 2 </code></pre> <p>args would have to be,</p> <pre><code>E, a0, b0, Maxima[0], a1, b1, Maxima[1] </code></pre> <p>Sorry for my mistake.</p> <p>Edit2:</p> <p>I'm thinking something like this:</p> <pre><code>GaussianDistribution = lambda E, E0, I0, Sigma : (I0 * np.exp(-(((E - E0) / Sigma)**2))) args = tuple([long] * ((len(Maxima) * 3) + 1)) d1, d2 = sc.curve_fit(GaussianDistribution(*args), Data[:, 0], Data[:, 1]) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload