Ignore:
Timestamp:
06/30/20 00:30:39 (4 years ago)
Author:
Maciej Komosinski
Message:

Introduced a separate function to mutate neuron connection weight

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/genooperators.cpp

    r967 r968  
    99#include <frams/util/rndutil.h>
    1010
     11//
     12// custom distributions for mutations of various parameters
     13//
    1114static double distrib_force[] =   // for '!'
    1215{
     
    3134        -1, 1,         // ~linear
    3235};
    33 
     36/*
     37static double distrib_weight[] =
     38{
     395,                 // distribution -999 _-^_^-_ +999
     40-999, 999,         // each weight value may be useful, especially...
     41-5, -0.3,          // ...little non-zero values
     42-3, -0.6,
     430.6, 3,
     440.3, 5,
     45};
     46*/
    3447
    3548int GenoOperators::roulette(const double *probtab, const int count)
     
    108121double GenoOperators::getMutatedNeuroClassProperty(double current, Neuro *n, int i)
    109122{
    110         if (i == -1) return mutateCreepNoLimit('f', current, 2, true); //i==-1: mutating weight of neural connection
     123        if (i == -1)
     124        {
     125                logPrintf("GenoOperators", "getMutatedNeuroClassProperty", LOG_WARN, "Deprecated usage in C++ source: to mutate connection weight, use getMutatedNeuronConnectionWeight().");
     126                return getMutatedNeuronConnectionWeight(current);
     127        }
    111128        Param p;
    112129        if (i >= NEUROCLASS_PROP_OFFSET) { i -= NEUROCLASS_PROP_OFFSET; p = n->getClass()->getProperties(); }
     
    117134}
    118135
     136double GenoOperators::getMutatedNeuronConnectionWeight(double current)
     137{
     138        return mutateCreepNoLimit('f', current, 2, true);
     139}
     140
    119141bool GenoOperators::mutatePropertyNaive(ParamInterface &p, int i)
    120142{
     
    145167        if (p.type(i)[0] != 'f' && p.type(i)[0] != 'd') return false; //don't know how to mutate
    146168        const char *n = p.id(i), *na = p.name(i);
    147         if (strcmp(n, "si") == 0 && strcmp(na, "Sigmoid") == 0) newval = CustomRnd(distrib_sigmo); else
    148                 if (strcmp(n, "in") == 0 && strcmp(na, "Inertia") == 0) newval = CustomRnd(distrib_inertia); else
    149                         if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = CustomRnd(distrib_force); else
     169        if (strcmp(n, "si") == 0 && strcmp(na, "Sigmoid") == 0) newval = round(CustomRnd(distrib_sigmo), 3); else
     170                if (strcmp(n, "in") == 0 && strcmp(na, "Inertia") == 0) newval = round(CustomRnd(distrib_inertia), 3); else
     171                        if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = round(CustomRnd(distrib_force), 3); else
    150172                        {
    151173                                double mn, mx, df;
     
    167189        {
    168190                if (limit_precision_3digits)
    169                         result = floor(result * 1000 + 0.5) / 1000.0; //round
     191                        result = round(result, 3);
    170192        }
    171193        return result;
     
    186208                {
    187209                        //reflect and wrap above may have changed the (limited) precision, so try to round again (maybe unnecessarily, because we don't know if reflect+wrap above were triggered)
    188                         double result_try = floor(result * 1000 + 0.5) / 1000.0; //round
     210                        double result_try = round(result, 3);
    189211                        if (mn <= result_try && result_try <= mx) result = result_try; //after rounding still witin allowed range, so keep rounded value
    190212                }
     
    375397                        int l = (int)strlen(n);
    376398                        if (len >= l && l > Len && (strncmp(s, n, l) == 0)) { I = NEUROCLASS_PROP_OFFSET + i; Len = l; }
    377                         if (also_v1_N_props) //recognize old properties symbols /=!
     399                        if (also_v1_N_props) //recognize old symbols of properties: /=!
    378400                        {
    379401                                if (strcmp(n, "si") == 0) n = "/"; else
Note: See TracChangeset for help on using the changeset viewer.