Changeset 899 for cpp/frams/genetics
- Timestamp:
- 11/30/19 02:13:25 (5 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_oper.cpp
r896 r899 448 448 int relid = neuid - id; 449 449 nn->l1 = relid; 450 //nn->l1 = (int)(4.0f * (rnd 01- 0.5f));450 //nn->l1 = (int)(4.0f * (rndDouble(1) - 0.5f)); 451 451 } 452 452 // weight 453 453 nn->f1 = GenoOperators::mutateNeuProperty(nn->f1, NULL, -1); 454 //nn->f1 = 10.0f * (rnd 01- 0.5f);454 //nn->f1 = 10.0f * (rndDouble(1) - 0.5f); 455 455 } 456 456 … … 485 485 nn->l1 = neuid - id; 486 486 } 487 //nn->l1 += (int)(2.0f * (rnd 01- 0.5f));487 //nn->l1 += (int)(2.0f * (rndDouble(1) - 0.5f)); 488 488 break; 489 489 case 2: // change weight 490 490 nn->f1 = GenoOperators::mutateNeuProperty(nn->f1, NULL, -1); 491 //nn->f1 += 1.0f * (rnd 01- 0.5f);491 //nn->f1 += 1.0f * (rndDouble(1) - 0.5f); 492 492 break; 493 493 } … … 630 630 631 631 // decide number of nodes to mutate 632 n = (int)( 0.5f + rnd 01* maxToMut );632 n = (int)( 0.5f + rndDouble(1) * maxToMut ); 633 633 if (n<1) n=1; 634 634 if (n>totNodes) n=totNodes; -
cpp/frams/genetics/f9/f9_oper.cpp
r896 r899 5 5 #include "f9_oper.h" 6 6 #include "f9_conv.h" 7 #include <common/nonstd.h> //rndUint, rnd 017 #include <common/nonstd.h> //rndUint, rndDouble 8 8 9 9 -
cpp/frams/genetics/fF/fF_oper.cpp
r896 r899 5 5 #include "fF_oper.h" 6 6 #include "fF_genotype.h" 7 #include <common/nonstd.h> //rndUint, rnd 017 #include <common/nonstd.h> //rndUint, rndDouble 8 8 9 9 -
cpp/frams/genetics/fT/fTest_oper.cpp
r896 r899 4 4 5 5 #include "fTest_oper.h" 6 #include <common/nonstd.h> //randomN, rnd 016 #include <common/nonstd.h> //randomN, rndDouble 7 7 8 8 /** -
cpp/frams/genetics/fn/fn_oper.cpp
r896 r899 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 8Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 5 5 #include "fn_oper.h" 6 6 #include "fn_conv.h" 7 #include <common/nonstd.h> //rndUint, rnd 017 #include <common/nonstd.h> //rndUint, rndDouble 8 8 9 9 -
cpp/frams/genetics/genooperators.cpp
r896 r899 76 76 } 77 77 78 int GenoOperators::selectRandomProperty(Neuro *n)78 int GenoOperators::selectRandomProperty(Neuro *n) 79 79 { 80 80 int neuext = n->extraProperties().getPropCount(), … … 129 129 if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = CustomRnd(distrib_force); else 130 130 { 131 double mn, mx, df;132 getMinMaxDef(&p, i, mn, mx, df);133 newval = mutateCreep(p.type(i)[0], oldval, mn, mx, true);131 double mn, mx, df; 132 getMinMaxDef(&p, i, mn, mx, df); 133 newval = mutateCreep(p.type(i)[0], oldval, mn, mx, true); 134 134 } 135 135 return true; … … 195 195 double v1 = p1[i]; 196 196 double v2 = p2[i]; 197 p1[i] = v1 *proportion + v2*(1 - proportion);198 p2[i] = v2 *proportion + v1*(1 - proportion);197 p1[i] = v1 * proportion + v2 * (1 - proportion); 198 p2[i] = v2 * proportion + v1 * (1 - proportion); 199 199 } 200 200 } … … 208 208 double v1 = p1.getDouble(i1); 209 209 double v2 = p2.getDouble(i2); 210 p1.setDouble(i1, v1 *proportion + v2*(1 - proportion));211 p2.setDouble(i2, v2 *proportion + v1*(1 - proportion));210 p1.setDouble(i1, v1 * proportion + v2 * (1 - proportion)); 211 p2.setDouble(i2, v2 * proportion + v1 * (1 - proportion)); 212 212 } 213 213 else 214 214 if (type1 == 'd' && type2 == 'd') 215 215 { 216 int v1 = p1.getInt(i1);217 int v2 = p2.getInt(i2);218 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1*proportion + v2*(1 - proportion));219 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2*proportion + v1*(1 - proportion));216 int v1 = p1.getInt(i1); 217 int v2 = p2.getInt(i2); 218 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1 * proportion + v2 * (1 - proportion)); 219 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2 * proportion + v1 * (1 - proportion)); 220 220 } 221 221 else … … 232 232 } 233 233 234 NeuroClass *GenoOperators::getRandomNeuroClass()235 { 236 vector<NeuroClass *> active;234 NeuroClass *GenoOperators::getRandomNeuroClass() 235 { 236 vector<NeuroClass *> active; 237 237 for (int i = 0; i < Neuro::getClassCount(); i++) 238 238 if (Neuro::getClass(i)->genactive) … … 241 241 } 242 242 243 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput()244 { 245 vector<NeuroClass *> active;243 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput() 244 { 245 vector<NeuroClass *> active; 246 246 for (int i = 0; i < Neuro::getClassCount(); i++) 247 247 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0) … … 250 250 } 251 251 252 NeuroClass *GenoOperators::getRandomNeuroClassWithInput()253 { 254 vector<NeuroClass *> active;252 NeuroClass *GenoOperators::getRandomNeuroClassWithInput() 253 { 254 vector<NeuroClass *> active; 255 255 for (int i = 0; i < Neuro::getClassCount(); i++) 256 256 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredInputs() != 0) … … 259 259 } 260 260 261 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs()262 { 263 vector<NeuroClass *> active;261 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs() 262 { 263 vector<NeuroClass *> active; 264 264 for (int i = 0; i < Neuro::getClassCount(); i++) 265 265 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0 && Neuro::getClass(i)->getPreferredInputs() == 0) … … 268 268 } 269 269 270 int GenoOperators::getRandomNeuroClassWithOutput(const vector<NeuroClass *>&NClist)270 int GenoOperators::getRandomNeuroClassWithOutput(const vector<NeuroClass *> &NClist) 271 271 { 272 272 vector<int> allowed; … … 277 277 } 278 278 279 int GenoOperators::getRandomNeuroClassWithInput(const vector<NeuroClass *>&NClist)279 int GenoOperators::getRandomNeuroClassWithInput(const vector<NeuroClass *> &NClist) 280 280 { 281 281 vector<int> allowed; … … 301 301 } 302 302 303 NeuroClass * GenoOperators::parseNeuroClass(char*&s)303 NeuroClass *GenoOperators::parseNeuroClass(char *&s) 304 304 { 305 305 int maxlen = (int)strlen(s); 306 306 int NClen = 0; 307 307 NeuroClass *NC = NULL; 308 for (int i = 0; i <Neuro::getClassCount(); i++)308 for (int i = 0; i < Neuro::getClassCount(); i++) 309 309 { 310 310 const char *ncname = Neuro::getClass(i)->name.c_str(); 311 311 int ncnamelen = (int)strlen(ncname); 312 if (maxlen >= ncnamelen && ncnamelen >NClen && (strncmp(s, ncname, ncnamelen) == 0))312 if (maxlen >= ncnamelen && ncnamelen > NClen && (strncmp(s, ncname, ncnamelen) == 0)) 313 313 { 314 314 NC = Neuro::getClass(i); … … 320 320 } 321 321 322 Neuro *GenoOperators::findNeuro(const Model *m, const NeuroClass *nc)322 Neuro *GenoOperators::findNeuro(const Model *m, const NeuroClass *nc) 323 323 { 324 324 if (!m) return NULL; … … 328 328 } 329 329 330 int GenoOperators::neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props)330 int GenoOperators::neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props) 331 331 { 332 332 int len = (int)strlen(s); … … 335 335 { 336 336 Param p = nc->getProperties(); 337 for (int i = 0; i <p.getPropCount(); i++)337 for (int i = 0; i < p.getPropCount(); i++) 338 338 { 339 339 const char *n = p.id(i); 340 340 int l = (int)strlen(n); 341 if (len >= l && l >Len && (strncmp(s, n, l) == 0)) { I = 100 + i; Len = l; }341 if (len >= l && l > Len && (strncmp(s, n, l) == 0)) { I = 100 + i; Len = l; } 342 342 if (also_v1_N_props) //recognize old properties symbols /=! 343 343 { … … 352 352 Neuro n; 353 353 Param p = n.extraProperties(); 354 for (int i = 0; i <p.getPropCount(); i++)354 for (int i = 0; i < p.getPropCount(); i++) 355 355 { 356 356 const char *n = p.id(i); 357 357 int l = (int)strlen(n); 358 if (len >= l && l >Len && (strncmp(s, n, l) == 0)) { I = i; Len = l; }358 if (len >= l && l > Len && (strncmp(s, n, l) == 0)) { I = i; Len = l; } 359 359 } 360 360 s += Len; … … 389 389 } 390 390 391 char *GenoOperators::strchrn0(const char *str, char ch)392 { 393 return ch == 0 ? NULL : strchr((char *)str, ch);391 char *GenoOperators::strchrn0(const char *str, char ch) 392 { 393 return ch == 0 ? NULL : strchr((char *)str, ch); 394 394 } 395 395 … … 398 398 return isupper(firstchar) || firstchar == '|' || firstchar == '@' || firstchar == '*'; 399 399 } 400 -
cpp/frams/genetics/genooperators.h
r801 r899 198 198 static NeuroClass* getRandomNeuroClassWithInput(); ///<returns random neuroclass with input or NULL when no active classes. 199 199 static NeuroClass* getRandomNeuroClassWithOutputAndNoInputs(); ///<returns random sensor or NULL when no active classes. 200 static NeuroClass* getRandomSensorProb(float prob); ///<returns random sensor (only-output neuron class) with presented probability or NULL. \e prob probability of picking neuron class.201 200 static int getRandomNeuroClassWithOutput(const vector<NeuroClass*>& NClist); ///<returns index of random NeuroClass from the NClist or -1 (no neurons on the list that provide output) \e NClist list of available neuron classes 202 201 static int getRandomNeuroClassWithInput(const vector<NeuroClass*>& NClist); ///<returns index of random NeuroClass from the NClist or -1 (no neurons on the list that want input(s)) \e NClist list of available neuron classes
Note: See TracChangeset
for help on using the changeset viewer.