• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Error in function exp()

U

Ulrich6

Guest
Hello everyone.

I am running a script called sigma within the object obj Create Event.
This script is as simple as this:

Code:
return 1/(1+exp(-argument0))
which is returning the output of the logistic function.

I don't see anything wrong with the code. However, sometimes I'd say like 1/5 of the times I run my game this error message appears:

___________________________________________
ERROR in
action number 1
of Create Event
for object obj:

Error in function exp().
Do you know what may be causing the error? I'm sure the exp function's domain is IR, so I can't understand what's going on.
Thank you very much.
 

jo-thijs

Member
First of all, it is worth noting you're getting this error in GM8.1, you cannot reproduce it in GM:S.
Secondly, I've only managed to get this error when passing huge numbers to exp,
so much that floating point numbers fail to represent the outcome by anything else than positive infinity.

What values are you passing to it and what do you need it for?
 

jo-thijs

Member
Are you passing large numbers into exp() such that the result overflows? It only takes around 700 to make that happen.
I was just testing when it occurs.
I actually expected it to happen way earlier (somewhere between 200 and 400).
However, you're right, it only gets thrown from about 700,
before that an invalid floating point operation error is thrown.
Why is that? Why does it change the type of error at as]bout 700?


EDIT: Nvm, I remembered some numbers incorrectly, I understand it.

EDIT:
The other error I was getting was not caused by exp, but by show_message.
 
Last edited:
U

Ulrich6

Guest
Thank you for your replies.

I think I am passing small numbers to the function (between -1 and 1), however I cannot guarantee that since my full code is giant and I am not being able to debug it in order to see the input values. However, I am almost sure they are pretty small.

Also, why does that error only show up in GM 8.1?

Thank you again.
 

jo-thijs

Member
Nope, it doesn't happen at low numbers for me.
Can you show what code calls this function, what determins argument0?

The reason it doesn't show up in GM:S, is because GM:S doesn't care as much about dealing with "infinity".
GM8.1 thinks however that when you get "infinity", you've got some bug that produces way too high numbers and it tells you about this.
It could also just be that the other functions in GM8.1 just don't work well with infinity and this is a precaution to pass this number to them.
 
U

Ulrich6

Guest
The code that determines argument0 is giant and it's not worth it to show here, although, if I could, I would of course do that.
It is also difficult to debug because the variables are randomized at the beginning of the game and it takes 1000 loops to reach the result (which is not advisable to debug iteration by iteration by hand).

EDIT: actually I've now astoundingly found that the values can go up to 1200 and -1200 (but sometimes the error appears and other doesn't). I really don't get it o_O
Also, is there a way to make the game automatically restart whenever an error appears? Thank could save a lot of time...
 
Last edited by a moderator:

TheouAegis

Member
We went from +/-1 to +/-1200. You don't need a restart, you need to debug your code that sets argument0, because it sounds like you don't even know what it actually does.
 

Yal

🐧 *penguin noises*
GMC Elder
I think I am passing small numbers to the function (between -1 and 1), however I cannot guarantee that since my full code is giant and I am not being able to debug it in order to see the input values. However, I am almost sure they are pretty small.
Never assume, always check. Pop a show_debug_message() in somewhere before the script call and print out the actual values you pass in :p

From my experiences, the most common error is code that does not do what it's supposed to do. Assuming code works as intended is a surefire way to not find this type of error, and the first thing you should ALWAYS do when debugging is doing sanity checks.
 
U

Ulrich6

Guest
Okay, I found that the argument0 value can be really random (absolutely small or absolutely giant).
The program is repeating itself many times, so I cannot just see the debug console (there are appearing lots of values almost at the same time).
 

Yal

🐧 *penguin noises*
GMC Elder
Okay, I found that the argument0 value can be really random (absolutely small or absolutely giant).
The program is repeating itself many times, so I cannot just see the debug console (there are appearing lots of values almost at the same time).
You could run the program in debug mode and pause every few seconds so you get a chance to check the values (and see if the numbers look completely random with an even spread from 0 to 1200, or if most have similar values close to 0 but you occasionally get a really high, etc etc).
 
U

Ulrich6

Guest
You could run the program in debug mode and pause every few seconds so you get a chance to check the values (and see if the numbers look completely random with an even spread from 0 to 1200, or if most have similar values close to 0 but you occasionally get a really high, etc etc).
Thanks for replying. The program is running inside a loop. I can't pause the program, since it isn't possible to stop the loop and keep the program working.
 

Yal

🐧 *penguin noises*
GMC Elder
Thanks for replying. The program is running inside a loop. I can't pause the program, since it isn't possible to stop the loop and keep the program working.
You could always have a random chance to print a debug message, I guess? Not sure whether it holds statistically since it's just a pseudorandom number, but if we decouple the chance from the code itself it should hopefully give a sufficiently reasonable approximation to a statistically representative sample of the population of all debug messages.
Code:
s = random_get_seed()
randomize()
if(!irandom(1000)){
  show_debug_message(variablenamehere)
}
random_set_seed(s)
 
U

Ulrich6

Guest
You could always have a random chance to print a debug message, I guess?
Code:
s = random_get_seed()
randomize()
if(!irandom(1000)){
  show_debug_message(variablenamehere)
}
random_set_seed(s)
Great idea! Let's see what I can do!

EDIT: Alright, I solved the problem! Thank you everyone!
First, I was generating the value to argument0 from a set of random numbers between [-1, 1]. It may not make sense, even less for you who didn't see the code, but I managed to solve the problem by limiting the range to [0, 1].
 

Yal

🐧 *penguin noises*
GMC Elder
Whoa, that was fast. You read that before I finished editing my post with an explanation I realized I left out xD
 
Top