Changeset 762 for cpp/frams


Ignore:
Timestamp:
03/28/18 02:27:39 (7 years ago)
Author:
Maciej Komosinski
Message:

Default sample values for a 2D problem, not 1D; added documentation and a sample 2D fitness function; crossover better protected against different lengths of parent vectors

Location:
cpp/frams/genetics/fn
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fn/oper_fn.cpp

    r752 r762  
    88
    99
     10/**
     11\class GenoOper_fn
     12
     13This genetic representation only stores a vector of real numbers. A fitness function must be provided
     14for the gene pool, for example the "Booth function" would be:
     15
     16var X = String.deserialize(this.geno.rawgenotype); //a vector of real values
     17var result = Math.pow(X[0]+2*X[1]-7,2) + Math.pow(2*X[0]+X[1]-5,2);
     18return -result; //negation because Framsticks assumes maximization, and the original function needs to be minimized
     19*/
     20
     21
     22
    1023#define FIELDSTRUCT GenoOper_fn
    1124static ParamEntry GENOfnparam_tab[] =
     
    1326        { "Genetics: fn", 1, 4, },
    1427        { "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)", },
    1831        { 0, },
    1932};
     
    7992        //xover_proportion = 0.1; //testing...
    8093
     94        chg1 = xover_proportion;
     95        chg2 = 1 - xover_proportion;
     96
    8197        vector<double> v1 = GenoConv_fn0::stringToVector(g1);
    8298        vector<double> v2 = GenoConv_fn0::stringToVector(g2);
    8399
    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        }
    86105
    87106        GenoOperators::linearMix(v1, v2, xover_proportion);
  • cpp/frams/genetics/fn/oper_fn.h

    r752 r762  
    1818        int crossOver(char *&g1, char *&g2, float& chg1, float& chg2);
    1919        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
    2121
    2222        double xover_proportion;
Note: See TracChangeset for help on using the changeset viewer.