[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Strange occurence of NaN
From: |
Matthew Mitchell |
Subject: |
Re: Strange occurence of NaN |
Date: |
Thu, 18 May 2000 11:52:20 +1000 (EST) |
Thanks for your reply Marcus,
Like you, the first thing I did was write a small program to test it and
see what happened. However, I did this again executing your program with
a loop (and a few changes to the compile command. I am actually using
egcs). The NaN problem didn't occur.
Here is the compile command I used and its result (in case there is
something I left out):
/usr/local/bin/libtool-swarm --mode link egcs -O2 -o main -Wall -Werror
-Wno-import -g -L/usr/local/lib -I/usr/local/include/swarm -L/usr/lib/
-rpath /usr/local/lib -rpath /usr/lib -I/usr/local/include
-L/usr/X11R6/lib main.m -lspace -lspace -lanalysis -lsimtools
-lsimtoolsgui -ltkobjc -ltclobjc -lactivity -lrandom -lobjectbase
-lcollections -ldefobj -lmisc -lBLT -ltk8.0 -ltcl8.0 -lpng -lz -lffi -lm
-lobjc -lpthread -ldl -lposix -lXpm -lX11
egcs -O2 -o main -Wall -Werror -Wno-import -g -L/usr/local/lib
-I/usr/local/include/swarm -L/usr/lib/ -I/usr/local/include
-L/usr/X11R6/lib main.m -lspace -lspace -lanalysis -lsimtools
-lsimtoolsgui -ltkobjc -ltclobjc -lactivity -lrandom -lobjectbase
-lcollections -ldefobj -lmisc -lBLT -ltk8.0 -ltcl8.0 -lpng -lz -lffi -lm
-lobjc -lpthread -ldl -lposix -lXpm -lX11 -Wl,--rpath -Wl,/usr/local/lib
-Wl,--rpath -Wl,/usr/lib
Here is the code I ran:
#import <simtools.h> // Need this for some reason
#import <defobj/Create.h>
@interface AgentModel: CreateDrop
- (double)getLearningRate;
@end
@implementation AgentModel
- (double)getLearningRate
{
return 0.2;
}
@end
int
main (int argc, const char **argv)
{
double tempStrength = 0.0;
double rewardStrength = 0.0;
double Qreturn = 0.0;
double discountRate = 0.9;
id agentModel;
int x = 0;
initSwarmApp (argc, argv, "1.4.1", "address@hidden");
// initSwarmBatch (argc, argv);
agentModel = [AgentModel create: globalZone];
for (x=0;x<1000;x++) {
tempStrength = tempStrength +
([agentModel getLearningRate] *
((rewardStrength + (discountRate * Qreturn)) - tempStrength));
printf ("%f\n", tempStrength);
}
return 0;
}
In the actual code all variables (including the return type) are doubles.
The problem does NOT seem to occur when I remove the two occurences of
"-O2" option from Makefile.common. Nor does it occur if I use "-O1".
I did not realise optimization was turned on, so thanks for
pointing that out. Yesterday I found a work-around to the problem by
splitting the statement into 2 as follows:
tempValue = ((rewardStrength + (discountRate * Qreturn))
- tempStrength)
tempStrength = tempStrength + [agentModel getLearningRate]
* tempValue;
But that is a bit dodgy, and doesn't instill much confidence that
the problem won't re-occur somewhere else later.
Thanks for your help Marcus, I think I will stick to using optimization
option -O1 and see how that goes.
Matt
On Wed, 17 May 2000, Marcus G. Daniels wrote:
> >>>>> "MM" == Matthew Mitchell <address@hidden> writes:
>
> MM> I have noticed I am getting NaN's occuring.
>
> Is this all `double' arithmetic, including the return type of
> getLearningRate?
>
> Does it go away when optimization is off?
>
> Can you make this program exhibit the behavior?
>
> #import <simtools.h>
> #import <defobj/Create.h>
>
> @interface AgentModel: CreateDrop
> - (double)getLearningRate;
> @end
>
> @implementation AgentModel
> - (double)getLearningRate
> {
> return 0.2;
> }
> @end
>
> int
> main (int argc, const char **argv)
> {
> double tempStrength = 0.0;
> double rewardStrength = 0.0;
> double Qreturn = 0.0;
> double discountRate = 0.9;
> id agentModel;
>
> initSwarmBatch (argc, argv);
>
> agentModel = [AgentModel create: globalZone];
>
> tempStrength = tempStrength +
> ([agentModel getLearningRate] *
> ((rewardStrength + (discountRate * Qreturn)) - tempStrength));
>
> printf ("%f\n", tempStrength);
> return 0;
> }
> /*
> Local Variables:
> compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc -O2 -o diff
> -Wall -Werror -g -Wno-import -I$SWARMHOME/include/swarm
-L$SWARMHOME/lib/swarm diff.m -lswarm -lobjc"
> End:
> */
>
> ==================================
> Swarm-Support is for discussion of the technical details of the day
> to day usage of Swarm. For list administration needs (esp.
> [un]subscribing), please send a message to <address@hidden>
> with "help" in the body of the message.
>
>
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.