Finding the smoothest 15% of a curve
What would be the best way to find the smoothest 15% of a curve similar to the one below?
I need to know the beginning and ending x coordinates. I have thought about using a derivative function, but this will give me a point with the smallest derivative, which may or may not always be part of the smoothest 15%.
Any algorithms I should look at or sug开发者_如何转开发gestions?
Unless my memory of calc fails me even more than usual today, what you'd want here would be the second derivative.
Alternatively, you could just use a sliding window of the correct size, and compute the variance for the window at each position, and the one with the smallest variance should be the smoothest.
Of course, it also depends on how you define "smooth". Do you mean the smallest change in the Y value, or would (for example) the almost perfectly straight (but also nearly vertical) line at the lest qualify as "smooth"?
I would decide on a resolution for the analysis (i.e. the size of your closed interval, call it delta X), and then as @Jerry mentioned, find the max and min of the function within that closed interval, including the end points.
That will give you n intervals (or delta Xs), and you will have found the max and min of each interval (let's call them the delta Ys).
Now you will essentially have cut up your function's domain into those n delta Xs, each having a corresponding delta Y.
You should then be able to group the intervals so that a group of m intervals adds up to 15% of the function domain. Let's call a group of m intervals your "window size" of analysis.
It seems like then you should be able to slide the window over the width of a single delta X, and sum the delta Ys for the window. Store that value, and then slide over another delta X, until you run out of space (while keeping a whole window size in the domain). Find the smallest sum, and that should correspond to the "smoothest" 15%-- given that smooth means least Y variance.
精彩评论