From 8f1af522a68145b552f663ebe56d3f6c92c4c5ec Mon Sep 17 00:00:00 2001 From: jeggermo Date: Fri, 5 Oct 2001 09:32:49 +0000 Subject: [PATCH] Since g++ 2.95.x on our solaris server doesn't have macros to check for infinity and NaN these checks have been removed from the source code and a protected divided function node is now used. --- eo/app/gpsymreg/fitness.h | 35 +++++++++-------------------------- eo/app/gpsymreg/node.h | 6 ------ 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/eo/app/gpsymreg/fitness.h b/eo/app/gpsymreg/fitness.h index 35563599..d022e84c 100644 --- a/eo/app/gpsymreg/fitness.h +++ b/eo/app/gpsymreg/fitness.h @@ -77,9 +77,13 @@ double _multiplies(double arg1, double arg2) return arg1 * arg2; } +// the function for a protected divide looks a little bit different double _divides(double arg1, double arg2) { - return arg1 / arg2; + if (arg2 ==0) + return 0; + else + return arg1 / arg2; } double _negate(double arg1) @@ -103,12 +107,8 @@ void init(vector &initSequence) Operation OpPLUS ( _plus, string("+")); Operation OpMINUS( _minus,string("-")); Operation OpMULTIPLIES(_multiplies,string("*")); - // We can use the normal divide function because there is a check for finite numbers in the node class - // so PDIV (protected divided) is enforced there so: (x/0 -> nan -> 0) + // We can use a protected divide function. Operation OpDIVIDE( _divides, string("/") ); - // we can also use the standard 'pow' function from cmath or math because of the check for nan is - // in the node class so: (-3^3.1) -> nan -> 0) - Operation OpPOW( pow, string("^") ); // Now the functions as binary functions @@ -116,23 +116,15 @@ void init(vector &initSequence) Operation MINUS( string("minus"), _minus); Operation MULTIPLIES( string("multiply"), _multiplies); Operation DIVIDE( string("divide"), _divides); - Operation POW(string("pow"), pow); // and some unary functions Operation NEGATE( _negate,string("-")); Operation SIN ( sin, string("sin")); Operation COS ( cos, string("cos")); - // all functions are "protected" inside the Node class so can also use tan(x) - // resulting values of -inf, inf or NaN (not-a-number) are converted to 0 - Operation TAN ( tan, string("tan")); - Operation EXP ( exp, string("e^")); - Operation LOG ( log, string("ln")); - // Now we are ready to add the possible nodes to our initSequence (which is used by the eoDepthInitializer) - - // always add the leaves (nodes with arity 0) first (or the program will crash) + // so lets start with our variable initSequence.push_back(varX); @@ -152,16 +144,12 @@ void init(vector &initSequence) initSequence.push_back( NEGATE ); initSequence.push_back( SIN ); initSequence.push_back( COS ); - initSequence.push_back( TAN ); - initSequence.push_back( EXP ); - initSequence.push_back( LOG ); // and the binary functions initSequence.push_back( PLUS); initSequence.push_back( MINUS ); initSequence.push_back( MULTIPLIES ); initSequence.push_back( DIVIDE ); - initSequence.push_back( POW ); // and the binary operators initSequence.push_back( OpPLUS); @@ -170,8 +158,6 @@ void init(vector &initSequence) initSequence.push_back( OpMULTIPLIES ); initSequence.push_back( OpDIVIDE ); - initSequence.push_back( OpPOW ); - }; @@ -202,11 +188,8 @@ class RegFitness: public eoEvalFunc< eoParseTree > fit += pow(target - output, 2); } - // some versions of gcc (e.g. 2.95.2 on solaris) don't have isinf(x) defined - if (isinf(fit) == 0) - fitness[NORMAL] = fit; - else - fitness[NORMAL] = MAXFLOAT; + + fitness[NORMAL] = fit; fitness[SMALLESTSIZE] = _eo.size() / (1.0*parameter.MaxSize); _eo.fitness(fitness); diff --git a/eo/app/gpsymreg/node.h b/eo/app/gpsymreg/node.h index 6905138c..c22e1f88 100644 --- a/eo/app/gpsymreg/node.h +++ b/eo/app/gpsymreg/node.h @@ -160,12 +160,6 @@ class Node } - // if the result is infinite (positive or negative) or not_a_number (nan) then result becomes 0 - // however some versions of gcc (e.g. 2.95.2 on solaris) don't have the finite(x) defined - #ifdef finite - if (!finite(result)) - result=0; - #endif } template