I just updated the smoothcurve.js library at github (first blogging) because I had a few mathematical insights.
I decided to drop out any emphasis on doubly differentiable curves: those polynomials are still supported but they seem to offer very little extra. More importantly I added a 3rd method to determine the slopes at various points. I think the result is smoother curves.
Previously I was using a sort of heuristic to attempt to force the interpolation curves to fall strictly inside the rectangle defined by the data points. This is the method used in type 2 smoothing. Type 3 is actually guaranteed to remain with in this box (unless I made a mistake in my math). This is done by making sure the slope is always less than 3 times the slope of the diagonal of the rectangle.
Smooth data i is the curve generated with type i where type 1 is basically catmull-rom, type 2 is my first attempt, and type 3 is the new smoothing type.
Update: Added the ability to use the new smoothing technique without respecting local maxima and minima (which I call sanity).
First, here is an example with a small fixed data set to see the differences (or you can go to the page if the iframe doesn't work for you).
And here is the large set of random data (and here is the page).
Showing posts with label plot. Show all posts
Showing posts with label plot. Show all posts
Thursday, March 12, 2009
Tuesday, March 03, 2009
Smooth curves in javascript: fast interpolation for large datasets
The other day I was thinking about generating some data for some blog posts. Since I needed to procrastinate first I started by looking for how to plot smooth curves and I couldn't find a good solution. So here's my solution.
It generates graphs that are doubly differentiable (function is continuous as are the first and second derivatives). There are two smoothing types: the first is a little more flowing while the second attempts to respect the initial data as localmaximums maxima and minimums minima. It's also fast enough to generate smooth data perceptually instantaneously with thousands of points.
I can write about how the math works in a future post if people are interested. These methods should not be used for interpolation for those interested in data mining or analysis. There are many other good algorithms for those uses.
And this is what the plots look like. The actual plotting is done by flot. Note that the data is generated randomly every time the page has reloaded. So I probably haven't seen the graph that you are currently looking at.
Update: I added the singly differentiable versions of this data. Looks pretty much like my previous plots. The type 1 singly differentiable plot is essentially catmull-rom to my understanding.
Update 2: This has been updated and blogged about here. You can find new examples there.
It generates graphs that are doubly differentiable (function is continuous as are the first and second derivatives). There are two smoothing types: the first is a little more flowing while the second attempts to respect the initial data as local
I can write about how the math works in a future post if people are interested. These methods should not be used for interpolation for those interested in data mining or analysis. There are many other good algorithms for those uses.
And this is what the plots look like. The actual plotting is done by flot. Note that the data is generated randomly every time the page has reloaded. So I probably haven't seen the graph that you are currently looking at.
Update: I added the singly differentiable versions of this data. Looks pretty much like my previous plots. The type 1 singly differentiable plot is essentially catmull-rom to my understanding.
Update 2: This has been updated and blogged about here. You can find new examples there.
Subscribe to:
Posts (Atom)