- Timestamp:
- 06/30/20 00:30:39 (4 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_oper.cpp
r967 r968 451 451 } 452 452 // weight 453 nn->f1 = GenoOperators::getMutatedNeuro ClassProperty(nn->f1, NULL, -1);453 nn->f1 = GenoOperators::getMutatedNeuronConnectionWeight(nn->f1); 454 454 //nn->f1 = 10.0f * (rndDouble(1) - 0.5f); 455 455 } … … 488 488 break; 489 489 case 2: // change weight 490 nn->f1 = GenoOperators::getMutatedNeuro ClassProperty(nn->f1, NULL, -1);490 nn->f1 = GenoOperators::getMutatedNeuronConnectionWeight(nn->f1); 491 491 //nn->f1 += 1.0f * (rndDouble(1) - 0.5f); 492 492 break; -
cpp/frams/genetics/fH/fH_oper.cpp
r967 r968 390 390 // if it is weight, then method needs to use mutateNeuProperty 391 391 double current = par.getDouble(id); 392 par.setDouble(id, getMutatedNeuro ClassProperty(current, NULL, -1));392 par.setDouble(id, getMutatedNeuronConnectionWeight(current)); 393 393 } 394 394 } -
cpp/frams/genetics/genooperators.cpp
r967 r968 9 9 #include <frams/util/rndutil.h> 10 10 11 // 12 // custom distributions for mutations of various parameters 13 // 11 14 static double distrib_force[] = // for '!' 12 15 { … … 31 34 -1, 1, // ~linear 32 35 }; 33 36 /* 37 static double distrib_weight[] = 38 { 39 5, // distribution -999 _-^_^-_ +999 40 -999, 999, // each weight value may be useful, especially... 41 -5, -0.3, // ...little non-zero values 42 -3, -0.6, 43 0.6, 3, 44 0.3, 5, 45 }; 46 */ 34 47 35 48 int GenoOperators::roulette(const double *probtab, const int count) … … 108 121 double GenoOperators::getMutatedNeuroClassProperty(double current, Neuro *n, int i) 109 122 { 110 if (i == -1) return mutateCreepNoLimit('f', current, 2, true); //i==-1: mutating weight of neural connection 123 if (i == -1) 124 { 125 logPrintf("GenoOperators", "getMutatedNeuroClassProperty", LOG_WARN, "Deprecated usage in C++ source: to mutate connection weight, use getMutatedNeuronConnectionWeight()."); 126 return getMutatedNeuronConnectionWeight(current); 127 } 111 128 Param p; 112 129 if (i >= NEUROCLASS_PROP_OFFSET) { i -= NEUROCLASS_PROP_OFFSET; p = n->getClass()->getProperties(); } … … 117 134 } 118 135 136 double GenoOperators::getMutatedNeuronConnectionWeight(double current) 137 { 138 return mutateCreepNoLimit('f', current, 2, true); 139 } 140 119 141 bool GenoOperators::mutatePropertyNaive(ParamInterface &p, int i) 120 142 { … … 145 167 if (p.type(i)[0] != 'f' && p.type(i)[0] != 'd') return false; //don't know how to mutate 146 168 const char *n = p.id(i), *na = p.name(i); 147 if (strcmp(n, "si") == 0 && strcmp(na, "Sigmoid") == 0) newval = CustomRnd(distrib_sigmo); else148 if (strcmp(n, "in") == 0 && strcmp(na, "Inertia") == 0) newval = CustomRnd(distrib_inertia); else149 if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = CustomRnd(distrib_force); else169 if (strcmp(n, "si") == 0 && strcmp(na, "Sigmoid") == 0) newval = round(CustomRnd(distrib_sigmo), 3); else 170 if (strcmp(n, "in") == 0 && strcmp(na, "Inertia") == 0) newval = round(CustomRnd(distrib_inertia), 3); else 171 if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = round(CustomRnd(distrib_force), 3); else 150 172 { 151 173 double mn, mx, df; … … 167 189 { 168 190 if (limit_precision_3digits) 169 result = floor(result * 1000 + 0.5) / 1000.0; //round191 result = round(result, 3); 170 192 } 171 193 return result; … … 186 208 { 187 209 //reflect and wrap above may have changed the (limited) precision, so try to round again (maybe unnecessarily, because we don't know if reflect+wrap above were triggered) 188 double result_try = floor(result * 1000 + 0.5) / 1000.0; //round210 double result_try = round(result, 3); 189 211 if (mn <= result_try && result_try <= mx) result = result_try; //after rounding still witin allowed range, so keep rounded value 190 212 } … … 375 397 int l = (int)strlen(n); 376 398 if (len >= l && l > Len && (strncmp(s, n, l) == 0)) { I = NEUROCLASS_PROP_OFFSET + i; Len = l; } 377 if (also_v1_N_props) //recognize old properties symbols/=!399 if (also_v1_N_props) //recognize old symbols of properties: /=! 378 400 { 379 401 if (strcmp(n, "si") == 0) n = "/"; else -
cpp/frams/genetics/genooperators.h
r967 r968 187 187 static bool mutateRandomNeuroClassProperty(Neuro* n); ///<high-level neuron mutation function, will select and mutate a random property of Neuron's NeuroClass. Returns true if successful and some property was actually mutated. Could return false when the NeuroClass of the Neuron have no properties, or when a randomly selected property was not suitable for mutation (for example a string or another non-number type). 188 188 static int selectRandomNeuroClassProperty(Neuro* n); ///<selects random property (either 0-based extraproperty of NeuroClass or NEUROCLASS_PROP_OFFSET-based standard property of NeuroClass). -1 if Neuroclass has no properties. 189 static double getMutatedNeuroClassProperty(double current, Neuro *n, int propindex); ///<returns value \e current mutated for the property \e propindex of Neuron's NeuroClass or for extraproperty (\e propindex - NEUROCLASS_PROP_OFFSET) of Neuron's NeuroClass. Neuro \e n is used as read-only. Use \e propindex == -1 to mutate connection weight (\e n and \e i are then ignored). 189 static double getMutatedNeuroClassProperty(double current, Neuro *n, int propindex); ///<returns value \e current mutated for the property \e propindex of Neuron's NeuroClass or for extraproperty (\e propindex - NEUROCLASS_PROP_OFFSET) of Neuron's NeuroClass. Neuro \e n is used as read-only. 190 static double getMutatedNeuronConnectionWeight(double current); ///<returns mutated value of \e current. 190 191 static bool mutatePropertyNaive(ParamInterface &p, int propindex); ///<creep-mutate selected property. Returns true when success. mutateProperty() should be used instead of this function. 191 192 static bool mutateProperty(ParamInterface &p, int propindex); ///<like mutatePropertyNaive(), but uses special probability distributions for some neuron properties. … … 216 217 }; 217 218 218 219 //220 // custom distributions for mutations of various parameters221 //222 /*223 static double distrib_weight[]=224 {225 5, // distribution -999 _-^_^-_ +999226 -999, 999, // each weight value may be useful, especially...227 -5, -0.3, // ...little non-zero values228 -3, -0.6,229 0.6, 3,230 0.3, 5,231 };232 */233 234 219 #endif
Note: See TracChangeset
for help on using the changeset viewer.