Changeset 762
- Timestamp:
- 03/28/18 02:27:39 (7 years ago)
- Location:
- cpp/frams/genetics/fn
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/fn/oper_fn.cpp
r752 r762 8 8 9 9 10 /** 11 \class GenoOper_fn 12 13 This genetic representation only stores a vector of real numbers. A fitness function must be provided 14 for the gene pool, for example the "Booth function" would be: 15 16 var X = String.deserialize(this.geno.rawgenotype); //a vector of real values 17 var result = Math.pow(X[0]+2*X[1]-7,2) + Math.pow(2*X[0]+X[1]-5,2); 18 return -result; //negation because Framsticks assumes maximization, and the original function needs to be minimized 19 */ 20 21 22 10 23 #define FIELDSTRUCT GenoOper_fn 11 24 static ParamEntry GENOfnparam_tab[] = … … 13 26 { "Genetics: fn", 1, 4, }, 14 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).", }, 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)", },28 { "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 { "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 { "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)", }, 18 31 { 0, }, 19 32 }; … … 79 92 //xover_proportion = 0.1; //testing... 80 93 94 chg1 = xover_proportion; 95 chg2 = 1 - xover_proportion; 96 81 97 vector<double> v1 = GenoConv_fn0::stringToVector(g1); 82 98 vector<double> v2 = GenoConv_fn0::stringToVector(g2); 83 99 84 chg1 = xover_proportion; 85 chg2 = 1 - xover_proportion; 100 if (v1.size() != v2.size()) 101 { 102 logPrintf("GenoOper_fn", "crossOver", LOG_ERROR, "Tried to cross over solutions with a differing number of variables (%d and %d)", v1.size(), v2.size()); 103 return GENOPER_OPFAIL; 104 } 86 105 87 106 GenoOperators::linearMix(v1, v2, xover_proportion); -
cpp/frams/genetics/fn/oper_fn.h
r752 r762 18 18 int crossOver(char *&g1, char *&g2, float& chg1, float& chg2); 19 19 uint32_t style(const char *g, int pos); 20 const char* getSimplest() { return "[0.0 ]"; }20 const char* getSimplest() { return "[0.0, 0.0]"; } //should actually correspond in length to vectors in mut_bound_low, mut_bound_high, mut_stddev 21 21 22 22 double xover_proportion;
Note: See TracChangeset
for help on using the changeset viewer.