Changeset 808 for cpp/frams/genetics/fn/fn_oper.cpp
- Timestamp:
- 06/21/18 02:30:37 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/fn/fn_oper.cpp
r779 r808 24 24 static ParamEntry GENOfnparam_tab[] = 25 25 { 26 { "Genetics: fn", 1, 4, }, 27 { "fn_xover", 0, 0, "Inherited in linear mix crossover", "f 0.5 1.0 0.9", FIELD(xover_proportion), "0.5 => children are averaged parents.\n0.8 => children are only 20% different from parents.\n1.0 => each child is identical to one parent (no crossover).", }, 26 { "Genetics: fn", 1, 6, }, 27 { "fn_xover", 0, 0, "Fraction inherited in linear mix crossover", "f 0.5 1.0 0.9", FIELD(xover_proportion), "0.5 => children are averaged parents.\n0.8 => children are only 20% different from parents.\n1.0 => each child is identical to one parent (no crossover).", }, 28 { "fn_xover_random", 0, 0, "Random fraction inherited in crossover", "d 0 1 1", FIELD(xover_proportion_random), "If active, the amount of linear mix is random in each crossover operation, so the \"Fraction inherited in linear mix crossover\" parameter is ignored.", }, 28 29 { "fn_mut_bound_low", 1, 0, "Lower bounds for mutation", "s 0 0 [-10.0, -10.0]", FIELD(mut_bound_low), "A vector of lower bounds (one real value for each variable)", }, 29 30 { "fn_mut_bound_high", 1, 0, "Higher bounds for mutation", "s 0 0 [10.0, 10.0]", FIELD(mut_bound_high), "A vector of higher bounds (one real value for each variable)", }, 30 31 { "fn_mut_stddev", 1, 0, "Standard deviations for mutation", "s 0 0 [0.1, 0.1]", FIELD(mut_stddev), "A vector of standard deviations (one real value for each variable)", }, 32 { "fn_mut_single_var", 0, 0, "Mutate only a single variable", "d 0 1 0", FIELD(mut_single_var), "If active, only a single randomly selected variable will be mutated in each mutation operation. Otherwise all variables will be mutated.", }, 31 33 { 0, }, 32 34 }; … … 76 78 } 77 79 78 int which = randomN(values.size()); 79 values[which] = GenoOperators::mutateCreep('f', values[which], bound_low[which], bound_high[which], stddev[which], false); 80 if (mut_single_var) //mutate only one, randomly selected variable 81 { 82 int which = randomN(values.size()); 83 values[which] = GenoOperators::mutateCreep('f', values[which], bound_low[which], bound_high[which], stddev[which], false); 84 chg = 1.0f / values.size(); 85 } 86 else //mutate all variables 87 { 88 for (int which = 0; which < values.size(); which++) 89 values[which] = GenoOperators::mutateCreep('f', values[which], bound_low[which], bound_high[which], stddev[which], false); 90 chg = 1.0f; 91 } 80 92 string saved = GenoConv_fn0::vectorToString(values); 81 93 free(gene); 82 94 gene = strdup(saved.c_str()); //reallocate 83 chg = 1.0f / values.size();84 95 return GENOPER_OK; 85 96 } … … 92 103 //xover_proportion = 0.1; //testing... 93 104 94 chg1 = xover_proportion; 95 chg2 = 1 - xover_proportion; 105 double proportion = xover_proportion_random ? 0.5 + rnd0N(0.5) : xover_proportion; 106 107 chg1 = proportion; 108 chg2 = 1 - proportion; 96 109 97 110 vector<double> v1 = GenoConv_fn0::stringToVector(g1); … … 104 117 } 105 118 106 GenoOperators::linearMix(v1, v2, xover_proportion);119 GenoOperators::linearMix(v1, v2, proportion); 107 120 108 121 string saved = GenoConv_fn0::vectorToString(v1);
Note: See TracChangeset
for help on using the changeset viewer.