Ignore:
Timestamp:
06/21/18 02:30:37 (6 years ago)
Author:
Maciej Komosinski
Message:

New option for mutation in numerical encoding fn: mutate all variables instead of one, randomly selected variable
New option for crossover in numerical encoding fn: the amount of linear mix can be random, not only fixed by user

File:
1 edited

Legend:

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

    r779 r808  
    2424static ParamEntry GENOfnparam_tab[] =
    2525{
    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.", },
    2829        { "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)", },
    2930        { "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)", },
    3031        { "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.", },
    3133        { 0, },
    3234};
     
    7678        }
    7779
    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        }
    8092        string saved = GenoConv_fn0::vectorToString(values);
    8193        free(gene);
    8294        gene = strdup(saved.c_str()); //reallocate
    83         chg = 1.0f / values.size();
    8495        return GENOPER_OK;
    8596}
     
    92103        //xover_proportion = 0.1; //testing...
    93104
    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;
    96109
    97110        vector<double> v1 = GenoConv_fn0::stringToVector(g1);
     
    104117        }
    105118
    106         GenoOperators::linearMix(v1, v2, xover_proportion);
     119        GenoOperators::linearMix(v1, v2, proportion);
    107120
    108121        string saved = GenoConv_fn0::vectorToString(v1);
Note: See TracChangeset for help on using the changeset viewer.