I have a set of (slightly noisy) data taken from two (or more) curves, but taken either from one or the other curve. As an example, consider this code (in reality, data is noisier, especially in how intervals are sampled from one of the two curves)

x = np.linspace(0, 50, num=100)
y1 = np.sin(x/5) * 0.1
y2 = y1 + 0.2
y = y1 * (np.cos(x) > 0) + y2 * (np.cos(x) < 0)
y = np.random.normal(y, 0.001)
plt.plot(x, y, '.')

That generates a plot like this:

Two curves

I would like to fit (actually, smooth) two parallel curves to these data, in python. I am using UnivariateSpline, but apparently I cannot do what I need with it.

  • $\begingroup$ Is it known when you're sampling from one or the other or do you only get the response values? $\endgroup$ – Glen_b -Reinstate Monica Jun 22 '18 at 12:13
  • $\begingroup$ I get only the values $\endgroup$ – The Data Scientician Jun 22 '18 at 13:18
  • 1
    $\begingroup$ In your drawing there's no overlap (the y-values of the upper group all exceed the y-values of he lower group). Is this the case in the actual problem or is that simply an artifact of your example? $\endgroup$ – Glen_b -Reinstate Monica Jun 23 '18 at 9:45
  • $\begingroup$ My mistake, it is just an artifact of my example: in reality, there can be overlap. $\endgroup$ – The Data Scientician Jun 24 '18 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.