- Timestamp:
- 02/28/18 23:43:57 (7 years ago)
- Location:
- cpp/frams/genetics/fn
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/fn/conv_fn.cpp
r747 r752 29 29 vector<double> GenoConv_fn0::stringToVector(const char *input) //returns empty vector on error 30 30 { 31 vector<double> output;31 vector<double> empty; 32 32 ExtValue val; 33 33 const char* after_des = val.deserialize(input); 34 if (after_des == NULL) // 34 if (after_des == NULL) //deserialization failed 35 35 { 36 logPrintf(" fn", "stringToVector", LOG_ERROR, "Unable to deserialize - expecting a vector of real values, got '%s'", input);37 return output;36 logPrintf("GenoConv_fn0", "stringToVector", LOG_ERROR, "Unable to deserialize - expecting a vector of real values, got '%s'", input); 37 return empty; 38 38 } 39 if (after_des[0] != '\0') // 39 if (after_des[0] != '\0') //not everything was consumed 40 40 { 41 logPrintf(" fn", "stringToVector", LOG_ERROR, "Extra characters after deserialized '%s'", input);42 return output;41 logPrintf("GenoConv_fn0", "stringToVector", LOG_ERROR, "Extra characters after deserialized '%s'", input); 42 return empty; 43 43 } 44 44 … … 46 46 if (vec) 47 47 { 48 vector<double> output; 48 49 for (int i = 0; i < vec->data.size(); i++) 49 50 { … … 51 52 if (val == NULL) 52 53 { 53 logPrintf("fn", "stringToVector", LOG_ERROR, "Expecting a real value in a vector, got NULL"); 54 logPrintf("GenoConv_fn0", "stringToVector", LOG_ERROR, "Expecting a real value in a vector, got NULL"); 55 return empty; 54 56 } 55 57 else 56 58 output.push_back(val->getDouble()); 57 59 } 60 return output; 58 61 } 59 62 else 60 63 { 61 logPrintf("fn", "stringToVector", LOG_ERROR, "Expecting a vector of real values, got '%s'", input); 64 logPrintf("GenoConv_fn0", "stringToVector", LOG_ERROR, "Expecting a vector of real values, got '%s'", input); 65 return empty; 62 66 } 63 return output;64 67 } 65 68 -
cpp/frams/genetics/fn/oper_fn.cpp
r747 r752 11 11 static ParamEntry GENOfnparam_tab[] = 12 12 { 13 { "Genetics: fn", 1, 1, }, 14 { "fn_xover", 0, 0, "Inherited in linear mix crossover", "f 0.5 1.0 0.5", 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).", }, 13 { "Genetics: fn", 1, 4, }, 14 { "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).", }, 15 { "fn_mut_bound_low", 1, 0, "Lower bounds for mutation", "s 0 0 [-1.0]", FIELD(mut_bound_low), "A vector of lower bounds (one real value for each variable)", }, 16 { "fn_mut_bound_high", 1, 0, "Higher bounds for mutation", "s 0 0 [1.0]", FIELD(mut_bound_high), "A vector of higher bounds (one real value for each variable)", }, 17 { "fn_mut_stddev", 1, 0, "Standard deviations for mutation", "s 0 0 [0.1]", FIELD(mut_stddev), "A vector of standard deviations (one real value for each variable)", }, 15 18 { 0, }, 16 19 }; … … 51 54 if (values.size() == 0) 52 55 return GENOPER_OPFAIL; 56 vector<double> bound_low = GenoConv_fn0::stringToVector(mut_bound_low.c_str()); 57 vector<double> bound_high = GenoConv_fn0::stringToVector(mut_bound_high.c_str()); 58 vector<double> stddev = GenoConv_fn0::stringToVector(mut_stddev.c_str()); 59 if (bound_low.size() != bound_high.size() || bound_high.size() != stddev.size() || stddev.size() != values.size()) 60 { 61 logPrintf("GenoOper_fn", "mutate", LOG_ERROR, "The solution vector, bound vectors, and standard deviation vectors must all have the same number of values"); 62 return GENOPER_OPFAIL; 63 } 64 53 65 int which = randomN(values.size()); 54 values[which] = GenoOperators::mutateCreep('f', values[which], -100, 100); //TODO precision 0.001 is forced!66 values[which] = GenoOperators::mutateCreep('f', values[which], bound_low[which], bound_high[which], stddev[which], false); 55 67 string saved = GenoConv_fn0::vectorToString(values); 56 68 free(gene); -
cpp/frams/genetics/fn/oper_fn.h
r747 r752 21 21 22 22 double xover_proportion; 23 SString mut_bound_low, mut_bound_high, mut_stddev; 23 24 }; 24 25
Note: See TracChangeset
for help on using the changeset viewer.