[Numpy-discussion] Generating Bell Curves (was: Using normal() )

Anne Archibald peridot.faceted@gmail....
Fri Apr 25 12:03:37 CDT 2008


On 24/04/2008, Rich Shepard <rshepard@appl-ecosys.com> wrote:
>    Thanks to several of you I produced test code using the normal density
>  function, and it does not do what we need. Neither does the Gaussian
>  function using fwhm that I've tried. The latter comes closer, but the ends
>  do not reach y=0 when the inflection point is y=0.5.
>
>    So, let me ask the collective expertise here how to generate the curves
>  that we need.
>
>    We need to generate bell-shaped curves given a midpoint, width (where y=0)
>  and inflection point (by default, y=0.5) where y is [0.0, 1.0], and x is
>  usually [0, 100], but can vary. Using the NumPy arange() function to produce
>  the x values (e.g, arange(0, 100, 0.1)), I need a function that will produce
>  the associated y values for a bell-shaped curve. These curves represent the
>  membership functions for fuzzy term sets, and generally adjacent curves
>  overlap where y=0.5. It would be a bonus to be able to adjust the skew and
>  kurtosis of the curves, but the controlling data would be the
>  center/midpoint and width, with defaults for inflection point, and other
>  parameters.
>
>    I've been searching for quite some time without finding a solution that
>  works as we need it to work.

First I should say, please don't call these "bell curves"! It is
confusing people, since that usually means specifically a Gaussian. In
fact it seems that you want something more usually called a "sigmoid",
or just a curve with a particular shape. I would look at
http://en.wikipedia.org/wiki/Sigmoid_function
In particular, they point out that the integral of any smooth,
positive, "bump-shaped" function will be a sigmoid. So dreaming up an
appropriate bump-shaped function is one way to go.

Alternatively, tou can look at polynomial fitting - if you want, say,
a function that is 1 with derivative zero at 0, 0.5 with derivative -1
at x, and 0 with derivative 0 at 1, you can construct a unique
degree-6 polynomial that does exactly that; there's a new tool,
KroghInterpolator, in scipy svn that can do that for you.

Anne


More information about the Numpy-discussion mailing list