![](https://secure.gravatar.com/avatar/3d4fcb0bbf6d3bfd68b59aff0573c7fe.jpg?s=120&d=mm&r=g)
What I want is a smooth curve that serves as an upper limit for a data plot. I would like it to be close to the data at the local maxima. Does such a function exist? Bill
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
Bill Dandreta wrote:
What I want is a smooth curve that serves as an upper limit for a data plot. I would like it to be close to the data at the local maxima.
Does such a function exist?
No, not really. It would be quite tricky to construct such a beast. At the one end would be a complete interpolating curve that goes through every point; however, this will almost certainly not be as "smooth" as you want it. You would need to choose the length scale at which variations in the data are ignored. E.g. you need to find some means of determining why the curve should skip over A but try to get close to B. ________ /* *\ / A \ * \_______ *B Possibly limiting the order of an interpolating polynomial or spline will be sufficient. You might be able to formulate this as a constrained minimization problem using scipy.optimize.fmin_cobyla(). Take some curve f(x), minimize (f(x) - y) under the constraint (f(x) - y >= 0). -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
![](https://secure.gravatar.com/avatar/f550e056db352872da8427e50697323d.jpg?s=120&d=mm&r=g)
You might look at Chebyshev polynomials. They have a "min-max of the error" property. One place to start is http://mathworld.wolfram.com/ChebyshevApproximationFormula.html Don't know if there's any python code for using these. --Clinton On 9/25/06, Robert Kern <robert.kern@gmail.com> wrote:
Bill Dandreta wrote:
What I want is a smooth curve that serves as an upper limit for a data plot. I would like it to be close to the data at the local maxima.
Does such a function exist?
No, not really. It would be quite tricky to construct such a beast. At the one end would be a complete interpolating curve that goes through every point; however, this will almost certainly not be as "smooth" as you want it. You would need to choose the length scale at which variations in the data are ignored. E.g. you need to find some means of determining why the curve should skip over A but try to get close to B.
________ /* *\ / A \ * \_______ *B
Possibly limiting the order of an interpolating polynomial or spline will be sufficient.
You might be able to formulate this as a constrained minimization problem using scipy.optimize.fmin_cobyla(). Take some curve f(x), minimize (f(x) - y) under the constraint (f(x) - y >= 0).
-- Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
Clinton Allen wrote:
You might look at Chebyshev polynomials. They have a "min-max of the error" property. One place to start is http://mathworld.wolfram.com/ChebyshevApproximationFormula.html <http://mathworld.wolfram.com/ChebyshevApproximationFormula.html>
Unfortunately, that's two-sided error. It won't do what he wants.
Don't know if there's any python code for using these.
scipy.special.cheby{t,u,c,s} -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
![](https://secure.gravatar.com/avatar/6194b135cba546afa82516de1537de49.jpg?s=120&d=mm&r=g)
Hi, we have used scipy cobyla minimaziation successfully to minimize square error of a parameterized function to data points while obeying the constrain that "function - datapoint" is strictly non-negative. "function" could be anything that can be given by a python function (you might need scipy.vectorize) !! It worked grate. Just used from scipy.omtmize import cobyla (this is from memory - but should be close) and follow the example in the source code. Sebastian Haase Robert Kern wrote:
Clinton Allen wrote:
You might look at Chebyshev polynomials. They have a "min-max of the error" property. One place to start is http://mathworld.wolfram.com/ChebyshevApproximationFormula.html <http://mathworld.wolfram.com/ChebyshevApproximationFormula.html>
Unfortunately, that's two-sided error. It won't do what he wants.
Don't know if there's any python code for using these.
scipy.special.cheby{t,u,c,s}
![](https://secure.gravatar.com/avatar/3d4fcb0bbf6d3bfd68b59aff0573c7fe.jpg?s=120&d=mm&r=g)
Robert Kern wrote:
You would need to choose the length scale at which variations in the data are ignored. E.g. you need to find some means of determining why the curve should skip over A but try to get close to B.
That is exactly the problem. I can look at the data curve and know where the boundary curve should go but trying to figure out an algorithm that works in general is non trivial. If I have to do it by hand, that will severely limit the number of datasets I can analyze.
You might be able to formulate this as a constrained minimization problem using scipy.optimize.fmin_cobyla(). Take some curve f(x), minimize (f(x) - y) under the constraint (f(x) - y >= 0).
Once I have something to optimize, I was thinking that genetic algorithms might yield the fastest solution because I only need an approximate solution. Attached is an example. The green curve is boundary and the blue is data. Bill
![](https://secure.gravatar.com/avatar/8fe55f60ba290dfa3f62a3536ede1d7c.jpg?s=120&d=mm&r=g)
Bill Dandreta wrote:
Once I have something to optimize, I was thinking that genetic algorithms might yield the fastest solution because I only need an approximate solution.
Attached is an example. The green curve is boundary and the blue is data.
For data like yours the attached script works quite well. As Robert suggested it uses fmin_cobyla to fit a 4pt spline to the data subject to one constraint per data point. Therefor it will be quite slow if applied to thousands of points. Initially I tried to use it to determine the background of spectroscopic data but this seems to be more difficult as the data is usually not as *smooth* as yours. Regards, Christian
![](https://secure.gravatar.com/avatar/7725ebdd5a56252641ba727dfa3c8c2d.jpg?s=120&d=mm&r=g)
On Mon, Sep 25, 2006 at 06:11:02PM -0400, Bill Dandreta wrote:
What I want is a smooth curve that serves as an upper limit for a data plot. I would like it to be close to the data at the local maxima.
Does such a function exist?
I'm pretty sure such a need is quite common, even for people not very skilled in maths (for which the tips given in replies to your message are not necessarily meaningful). So I would recomend that you (or someone else that already did this) add a page to the cookbook explaining a simple way of doing this. David
Bill _______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
-- David Douard LOGILAB, Paris (France) Formations Python, Zope, Plone, Debian : http://www.logilab.fr/formations Développement logiciel sur mesure : http://www.logilab.fr/services Informatique scientifique : http://www.logilab.fr/science
participants (6)
-
Bill Dandreta
-
Christian Kristukat
-
Clinton Allen
-
David Douard
-
Robert Kern
-
Sebastian Haase