Changeset 752 for cpp/frams/genetics/fn


Ignore:
Timestamp:
02/28/18 23:43:57 (7 years ago)
Author:
Maciej Komosinski
Message:

Mutation in the 'fn' encoding respects custom min,max,stddev for each variable

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

Legend:

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

    r747 r752  
    2929vector<double> GenoConv_fn0::stringToVector(const char *input) //returns empty vector on error
    3030{
    31         vector<double> output;
     31        vector<double> empty;
    3232        ExtValue val;
    3333        const char* after_des = val.deserialize(input);
    34         if (after_des == NULL) // deserialization failed
     34        if (after_des == NULL) //deserialization failed
    3535        {
    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;
    3838        }
    39         if (after_des[0] != '\0') // not everything was consumed
     39        if (after_des[0] != '\0') //not everything was consumed
    4040        {
    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;
    4343        }
    4444
     
    4646        if (vec)
    4747        {
     48                vector<double> output;
    4849                for (int i = 0; i < vec->data.size(); i++)
    4950                {
     
    5152                        if (val == NULL)
    5253                        {
    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;
    5456                        }
    5557                        else
    5658                                output.push_back(val->getDouble());
    5759                }
     60                return output;
    5861        }
    5962        else
    6063        {
    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;
    6266        }
    63         return output;
    6467}
    6568
  • cpp/frams/genetics/fn/oper_fn.cpp

    r747 r752  
    1111static ParamEntry GENOfnparam_tab[] =
    1212{
    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)", },
    1518        { 0, },
    1619};
     
    5154        if (values.size() == 0)
    5255                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
    5365        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);
    5567        string saved = GenoConv_fn0::vectorToString(values);
    5668        free(gene);
  • cpp/frams/genetics/fn/oper_fn.h

    r747 r752  
    2121
    2222        double xover_proportion;
     23        SString mut_bound_low, mut_bound_high, mut_stddev;
    2324};
    2425
Note: See TracChangeset for help on using the changeset viewer.