Search code examples
mathinversesigmoid

Sigmoid scale and inverse with custom range


I'm having brain block figuring out how to scale a variable within a custom range using Sigmoid, and then to inverse that scaling.

For example, the below Python script scales variable x between 0 and top, and to then inverse that scaling.

import math

# apply Sigmoid to x on scale between 0 and top:
def sigmoid(x, top):
    y = top / (1 + math.exp(-x))
    return y

# and to inverse:
def invSigmoid(y, top):
    x = np.log(y/(top-y))
    return x

What I would like to do is to set the bottom also, so that x is scaled between bottom-top e.g.(10-100). Then also to get the inverse.


Solution

  • it seems to me that what you are after would be:

    y = bottom + (top - bottom) / (1 + math.exp(-x))
    

    and

    x = np.log((y - bottom) / (top - y))