[Numpy-discussion] Combining Sigmoid Curves
Anne Archibald
peridot.faceted@gmail....
Fri May 2 17:27:05 CDT 2008
2008/5/2 Rich Shepard <rshepard@appl-ecosys.com>:
> On Fri, 2 May 2008, Anne Archibald wrote:
>
> > 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.
>
> Anne,
>
> That's been my goal. :-)
>
>
> > 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.
>
> This looks like a pragmatic solution. When I print scaled_x (using left =
> 0.0 and right = 100.0), the values range from -1.0 to +0.998. So, I need to
> figure out the scale_x that sets the end points at 0 and 100.
No, no. You *want* scaled_x to range from -1 to 1. (The 0.998 is
because you didn't include the endpoint, 100.) The function I gave,
(1+np.cos((np.pi/2) * scaled_x))/2, takes [-1, 1] to a nice
bump-shaped function. If you feed in numbers from 0 to 100 as x, they
get transformed to scaled_x, and you feed them to the function,
getting a result that goes from 0 at x=0 to 1 at x=50 to 0 at x=100.
Anne
More information about the Numpy-discussion
mailing list