[SciPy-User] inverse function of a spline

Charles R Harris charlesr.harris at gmail.com
Fri May 7 15:37:36 EDT 2010


On Fri, May 7, 2010 at 12:34 PM, <josef.pktd at gmail.com> wrote:

> On Fri, May 7, 2010 at 1:57 PM, Charles R Harris
> <charlesr.harris at gmail.com> wrote:
> >
> >
> > On Fri, May 7, 2010 at 10:40 AM, <josef.pktd at gmail.com> wrote:
> >>
> >> I have a function  y = f(x) which is monotonically increasing (a
> >> cumulative distribution function)
> >> f is defined by piecewise polynomial interpolation, an interpolating
> >> spline on some points
> >>
> >> I would like to get the inverse function (ppf)  x = f^{-1} (y)
> >> if the spline is of higher order than linear
> >>
> >> In the linear case it's trivial, because the inverse function is also
> >> just a piecewise linear interpolation.
> >>
> >> If I have a cubic spline, or any other smooth interpolator in scipy,
> >> is there a way to get the
> >> inverse function directly?
> >>
> >> I don't know much about general properties of splines, and would
> >> appreciate any hints,
> >> so I can avoid numerical inversion (fsolve or similar)
> >>
> >
> > Since the curve is piecewise cubic the problem reduces to inverting a
> piece
> > of a cubic, which inverse won't itself be a cubic in general. I think
> your
> > best bet is interpolate the same points with x,y reversed, or resample
> using
> > your spline and interpolate the new samples with x,y reversed. It won't
> be a
> > exact inverse, but then, the original is probably not exact either.
>
> That's what I suspected, I was hoping for a trick (like one interpolator is
> the
> "natural" inverse of another one).
>
> resampling should give a good enough approximation. Without resampling, the
> error for round tripping x= f^{-1} ( f(x) ) might be too large to give
> consistent results.
> (Even if there are sampling and approximation errors, I still would
> prefer consistency.)
>
>
> Just a follow-up question on approximation:
>
> for the cdf (e.g. normal distribution)  f:R->[0,1]   f^{-1}:[0,1]->R
>
> Is it better to start with a spline on the inverse function (ppf),
> f^{-1}, because it has
> compact support, resample from it, and then create the cdf f from a
> resampled ppf;
> or the other way around, or it wouldn't really matter?
>
> Thanks for the information and hint,
>
> I don't know the answer to that  although I suspect starting from the
inverse might be superior. The end points might be a problem though if the
curve goes vertical. You might have to experiment a bit or use a spline in
combination with other functions. There has probably been a small industry
out there dealing with these sorts of problem but I don't know who they are.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100507/1545e993/attachment.html>


More information about the SciPy-User mailing list