Changeset 31 for cpp/geno_fx/geno_fx.cpp


Ignore:
Timestamp:
10/21/09 23:45:09 (15 years ago)
Author:
Maciej Komosinski
Message:

mutated connection weights are unlimited (previously the range was -10..10) and another approach to allowed ranges of mutated values (was: absorb, now: reflect)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/geno_fx/geno_fx.cpp

    r3 r31  
    5555double Geno_fx::mutateNeuProperty(double current,Neuro *n,int i)
    5656{
    57    if (i==-1) return mutateCreep('f',current,-10,10);
     57   if (i==-1) return mutateCreepNoLimit('f',current,-10,10);
    5858   ParamInterface *pi;
    5959   if (i>=100) {i-=100; pi=&n->getClass()->getProperties();}
    6060      else pi=&n->extraProperties();
    61    double newval;
     61   double newval=current;
    6262   /*bool ok=*/getMutatedProperty(*pi,i,current,newval);
    6363   return newval;
     
    103103}
    104104
    105 double Geno_fx::mutateCreep(char type,double current,double mn,double mx)
     105double Geno_fx::mutateCreepNoLimit(char type,double current,double mn,double mx)
    106106{
    107107   double result=RndGen.Gauss(current,(mx-mn)/2/5); // /halfinterval, 5 times narrower
    108108   if (type=='d') {result=int(result+0.5); if (result==current) result+=randomN(2)*2-1;}
    109     else result=floor(result*1000)/1000.0;
     109    else result=floor(result*1000+0.5)/1000.0; //round
     110   return result;
     111}
     112
     113double Geno_fx::mutateCreep(char type,double current,double mn,double mx)
     114{
     115   double result=mutateCreepNoLimit(type,current,mn,mx);
     116   //reflect:
     117   if (result>mx) result=mx-(result-mx); else
     118    if (result<mn) result=mn+(mn-result);
     119   //absorb (just in case 'result' exceeded the allowed range so much):
    110120   if (result>mx) result=mx; else
    111121    if (result<mn) result=mn;
Note: See TracChangeset for help on using the changeset viewer.