Changeset 146
 Timestamp:
 02/26/14 20:27:49 (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/genetics/oper_fx.cpp
r121 r146 136 136 } 137 137 138 double GenoOperators::mutateCreep(char type,double current,double mn,double mx) 139 { 140 double result=mutateCreepNoLimit(type,current,mn,mx); //TODO consider that when boundary is touched (reflect/absorb below), the default precision (3 digits) may change. Is it good or bad? 141 //reflect: 142 if (result>mx) result=mx(resultmx); else 143 if (result<mn) result=mn+(mnresult); 144 //absorb (just in case 'result' exceeded the allowed range so much): 145 if (result>mx) result=mx; else 146 if (result<mn) result=mn; 147 return result; 148 } 138 double GenoOperators::mutateCreep(char type, double current, double mn, double mx) 139 { 140 double result = mutateCreepNoLimit(type, current, mn, mx); //TODO consider that when boundary is touched (reflect/absorb below), the default precision (3 digits) may change. Is it good or bad? 141 //reflect: 142 if (result > mx) result = mx  (result  mx); else 143 if (result<mn) result = mn + (mn  result); 144 //absorb (just in case 'result' exceeded the allowed range so much): 145 if (result>mx) result = mx; else 146 if (result < mn) result = mn; 147 return result; 148 } 149 150 void GenoOperators::setIntFromDoubleWithProbabilisticDithering(ParamInterface &p, int index, double value) //TODO 151 { 152 p.setInt(index, value); //TODO value=2.5 will result in 2 but we want it to be 2 or 3 with equal probability. value=2.1 would be mostly 2, rarely 3. Careful with negative values (test it!) 153 } 154 155 void GenoOperators::linearMix(ParamInterface &p1, int i1, ParamInterface &p2, int i2, double proportion) 156 { 157 if (p1.type(i1)[0] == 'f' && p2.type(i2)[0] == 'f') 158 { 159 double v1 = p1.getDouble(i1); 160 double v2 = p2.getDouble(i2); 161 p1.setDouble(i1, v1*proportion + v2*(1  proportion)); 162 p2.setDouble(i2, v2*proportion + v1*(1  proportion)); 163 } 164 if (p1.type(i1)[0] == 'd' && p2.type(i2)[0] == 'd') 165 { 166 int v1 = p1.getInt(i1); 167 int v2 = p2.getInt(i2); 168 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1*proportion + v2*(1  proportion)); 169 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2*proportion + v1*(1  proportion)); 170 } 171 } 172 149 173 150 174 NeuroClass* GenoOperators::getRandomNeuroClass()
Note: See TracChangeset
for help on using the changeset viewer.