0

I've found numerous answers that will average all the Y values of a series of curves, and call that the average of all the plots.

However, I want a 2D average, in which a new X & Y value (not just Y value) is determined from some number of original X/Y plots.

Here's an example:

Illustration of the 2D average of two curves

As you can see, the purple curve has x-coords that aren't present in the blue curve, so averaging the y-values won't work (at least not for the part of the curve I find most interesting - the end/top-right).

Now I fully realize that this is likely a rather complex situation, since the direction in which to find the midpoint changes continuously. (What's it called for 5 curves? Not just a simple midpoint any more.) But I'm assuming some brilliant mathematicians have, in times long past, pondered this very problem and presented some beautifully simple way to do this...

I'm looking for a Python answer, but a Matlab or similar answer would also be great, as I can just transcribe that into Python/Numpy etc. Also my actual situation does involve "averaging" 5-10 similarly-shaped curves.

Demis
  • 5,278
  • 4
  • 23
  • 34
  • 1
    How do you know which point in the blue curve correspond to which point in the pink curve? – Noel Segura Meraz Jan 28 '16 at 06:35
  • Maybe you should calculate the logarithm to some base, fitting your data and then average just the y-values. What you're attempting to to, does not seem to be very scientific to me – Robert Seifert Jan 28 '16 at 06:46
  • Getting a curve-fit with potentially infinite length is actually a fantastic idea. – Demis Jan 28 '16 at 06:56
  • @NoelSegura : great question - I don't know! I know what I *want* it to look like... The best I can figure is that I want a midpoint that is Normal/perpendicular to both curves? No idea how that makes sense for more than two curves though. – Demis Jan 28 '16 at 06:58
  • "Normal"-->"as close to normal as possible". This is starting to sound like some heavy calculus may be involved, curls or some such. I certainly don't know how to figure that out myself. Laplace or Newton or someone really didn't figure this out already? – Demis Jan 28 '16 at 07:00
  • Then you have a problem, a big one. You could define it as the curve of all the points that are equidistant between the closest distance to each line. Or going the other route, what information do you have about the curves? equation, list of coordinates, splines? and what output do you need? equation, list of coordinates, splines? – Noel Segura Meraz Jan 28 '16 at 07:10
  • I have raw data - X & Y points for each curve, where X values are always spaced by the same amount (eg. X=[0,1,2,3...] for all curves. These are for diode I-V curves. Although I would really like this plot, I may fall-back and just do the traditional linear fit to the "straightish" turned-on part of the curve, and just average the slopes & X-intercepts of those curve-fits. – Demis Jan 28 '16 at 07:13
  • Giving that your problem is not well defined, maybe this might give you some insight into what you are looking for http://stackoverflow.com/questions/4555682/determine-the-midline-of-a-bent-elongated-region – Noel Segura Meraz Jan 28 '16 at 07:28
  • That's nearly exactly the "definition" of my problem, thanks! I just have the two-line version of that, instead of one closed loop. I will look up the "Voronoi diagram" tomorrow. – Demis Jan 28 '16 at 07:32

2 Answers2

0

Here's what I'm thinking.

Get the point at the beginning of the blue curve, and the beginning of the pink curve. Find the midpoint of the line connecting them. Then move forwards for 1/n of the blue curve and 1/n of the pink curve, where n is how precise you want this merged curve to be, and repeat midpointing. If you're smart you might be able to interpolate values gotten once you've retrieved a lot of them but that might not be most useful in this situation.

I don't know how you're storing the curves but if you can get the equation or something similar, that may help.

charredgrass
  • 121
  • 4
  • Hmmm... Yeah maybe if I do 'L/n' where L is the length of the line. (Otherwise they'd always be picking the same X values, resulting in the aforementioned y-averaging only.) – Demis Jan 28 '16 at 07:05
0

Basically you need to find corresponding points on the curves and then average them together. The trick is which points correspond. There are many possibilites, which one to use depends on what the curves represent.

Corresponding points could be:

  1. Vertically aligned points
  2. Horizontally aligned points
  3. Points an equal distance along the paths of each curve.
  4. Points an equal percentage along the paths of each curve (Maxwell's idea)
  5. A point on the blue line, and the intersection of a perpendicular to the blue line at that point and the other curves.
  6. Points at which a line starting at the top left corner of the graph going down to the right at angles of 10, 20, 30, ... degrees intersect the curves.
  7. etc.
RootTwo
  • 4,288
  • 1
  • 11
  • 15
  • Good ol' James Clerk. I may try that (similar to @MaxwellChow's answer). It doesn't really seem perfect - the midpoint of a line "as close to perpendicular to both lines as possible" seems like the right answer, but I haven't the foggiest how to code that up. JCM's may be good enough though - will try tomorrow. I should probably repost this on a Math forum. – Demis Jan 28 '16 at 07:16
  • When you say "average them together" - i guess you just average all the X values & then all the Y values? Yeah I guess for the case of two points, that simplifies to the standard midpoint. – Demis Jan 28 '16 at 07:24