1

I'm confused about how to upscale a sigmoid result the right way. for example the input for my NN is between 0,10. I scale this to be between -4,4 as the active input range for sigmoid and i get a result of lets say 0.83201. Now i want to rescale this back to between 0,10.

I thought the inverse of sigmoid was logit but funny stuff happens when i use this:

float u = sig.LogSigmoid(sig.InputScaler(3,0f,10f,-4f,4f));
Debug.Log(-Mathf.Log(u/(1-u)));

results in: 1.6. while

float u = sig.LogSigmoid(sig.InputScaler(4,0f,10f,-4f,4f));
Debug.Log(-Mathf.Log(u/(1-u)));

results in: 0.8.

EDIT: Ok after some fiddling, i found that the Logit does work only it returns my scaled input :-). so for sigmoid + downscaling:

float u = sig.LogSigmoid(sig.InputScaler(6,0f,10f,-4f,4f));

the following logit + upscaling worked perfect:

Debug.Log(sig.InputScaler(-Mathf.Log((1-u)/u),-4f,4f,0f,10f));

InputScaler being:

public float InputScaler(float x, float minFrom, float maxFrom, float minTo, float maxTo)
{
    float t = (((x-minFrom)*(maxTo-minTo))/(maxFrom-minFrom))+minTo;
    return t;
}
Rottjung
  • 493
  • 1
  • 5
  • 15
  • What did you expect your example to output? What do you understand as 'rescale back'? Do you want to make the output of the sigmoid to lie in the range 0,10 or do you want to calculate the inverse opration? – burnpanck Aug 12 '15 at 11:43
  • Also, you speak of scaling to -6,6, but your code scales to -4,4. – burnpanck Aug 12 '15 at 11:45
  • 2
    The results you get do make sense to me: You calculate the inverse of the sigmoid (actually the negative version of it). So you get back the argument of the sigmoid, which is the rescaled version of your input: 3 in (0,10) => -0.4 (-1,1) => -1.6 in (-4,4). 4 in (0,10) => -0.2 in (-1,1) => -0.8 in (-4,4). – burnpanck Aug 12 '15 at 11:46
  • What is your question ? – Fabjan Aug 12 '15 at 11:52
  • hey burnpanck thanks. yes stupid of me i will change the text to say -4,4. @Fabjan guess i solved it, should i remove the Q? the question was how to properly reconvert a sigmoid result to an original input scale. – Rottjung Aug 12 '15 at 11:52

1 Answers1

1

To rescale the output of the sigmoid (which is in the range [0,1]) to [0,10] you could of course generically use sig.InputScale(u,0f,1f,0f,10f) but of course in this case the scaling is as easy as u*10f.

However, I do not understand why you speak about the inverse sigmoid. If you want to rescale the output of a function, you never need the inverse function.

On the other hand, if you were instead trying to invert the sigmoid inclusive the input scaling, then you need to scale back the output of the logit from [-4,4] to [0,10]: I.e. sig.InputScale(Mathf.Log(u/(1-u)),-4f,4f,0f,10f).

burnpanck
  • 1,955
  • 1
  • 12
  • 36
  • ok so the right term is "revert". Wiki called Logit the inverse of a Sigmoid function. Thanks for the explanation, I'll mark this one as the answer. – Rottjung Aug 12 '15 at 12:15
  • Actually, "invert" is the correct technical term, I had written "revert" in case "invert" was too technical. I edited my answer. – burnpanck Aug 12 '15 at 12:19