# [Numpy-discussion] Combining Sigmoid Curves

Anne Archibald peridot.faceted@gmail....
Fri May 2 17:03:32 CDT 2008

```2008/5/2 Rich Shepard <rshepard@appl-ecosys.com>:

>    What will work (I call it a pi curve) is a matched pair of sigmoid curves,
>  the ascending curve on the left and the descending curve on the right. Using
>  the Boltzmann function for these I can calculate and plot each individually,
>  but I'm having difficulty in appending the x and y values across the entire
>  range. This is where I would appreciate your assistance.

It's better not to work point-by-point, appending things, when working
with numpy. Ideally you could find a formula which just produced the
right curve, and then you'd apply it to the input vector and get the
output vector all at once. For example for a Gaussian (which you're
not using, I know), you'd write a function something like

def f(x):
return np.exp(-x**2)

and then call it like:

f(np.linspace(-1,1,1000)).

This is efficient and clear. It does not seem to me that the logistic
function, 1/(1+np.exp(x)) does quite what you want. How about using
the cosine?

def f(left, right, x):
scaled_x = (x-(right+left)/2)/((right-left)/2)
return (1+np.cos((np.pi/2) * scaled_x))/2

exactly zero at both endpoints, exactly one at the midpoint,
inflection points midway between, where the value is 1/2. If you want
to normalize it so that the area underneath is one, that's easy to do.

More generally, the trick of producing a scaled_x as above lets you
move any function anywhere you like.

If you want the peak not to be at the midpoint of the interval, you
will need to do something a litle more clever, perhaps choosing a
different function, scaling the x values with a quadratic polynomial
so that (left, middle, right) becomes (-1,0,1), or using a piecewise
function.

Good luck,
Anne
```