Changeset 959


Ignore:
Timestamp:
06/26/20 01:30:10 (5 years ago)
Author:
Maciej Komosinski
Message:

Added a high-level neuron mutation function

Location:
cpp/frams/genetics
Files:
2 edited

Legend:

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

    r957 r959  
    7474        }
    7575        return defined == 3;
     76}
     77
     78bool GenoOperators::mutateRandomNeuronOrNeuroclassProperty(Neuro* n)
     79{
     80        bool mutated = false;
     81        int prop = selectRandomNeuronProperty(n);
     82        if (prop >= 0)
     83        {
     84                if (prop >= GenoOperators::NEUROCLASS_PROP_OFFSET)
     85                {
     86                        SyntParam par = n->classProperties();   //commits changes when p is destroyed
     87                        mutated = mutateProperty(par, prop - GenoOperators::NEUROCLASS_PROP_OFFSET);
     88                }
     89                else
     90                {
     91                        Param par = n->extraProperties();
     92                        mutated = mutateProperty(par, prop);
     93                }
     94        }
     95        return mutated;
    7696}
    7797
  • cpp/frams/genetics/genooperators.h

    r957 r959  
    185185        static int roulette(const double *probtab, const int count);    ///<returns random index according to probabilities in the \e probtab table or -1 if all probs are zero. \e count is the number of elements in \e probtab.
    186186        static bool getMinMaxDef(ParamInterface *p, int propindex, double &mn, double &mx, double &def); ///<perhaps a more useful (higher-level) way to obtain min/max/def info for integer and double properties. Returns true if min/max/def was really available (otherwise it is just invented).
     187        static bool mutateRandomNeuronOrNeuroclassProperty(Neuro* n); ///<high-level neuron mutation function, will select and mutate a random property of a neuron or its neuroclass. Returns true if successful and some property was actually mutated. Could return false when the neuron and its neuroclass have no properties, or when a randomly selected property was not suitable for mutation (for example a string or another non-number type).
    187188        static int selectRandomNeuronProperty(Neuro* n); ///<selects random property (either 0-based extraproperty of Neuro or NEUROCLASS_PROP_OFFSET-based property of its NeuroClass). -1 if Neuro has no properties.
    188189        static double mutateNeuronProperty(double current, Neuro *n, int propindex); ///<returns value \e current mutated for the property \e propindex of NeuroClass \e nc or for extraproperty (\e propindex - NEUROCLASS_PROP_OFFSET) of Neuro. Neuro is used as read-only. Give \e propindex == -1 to mutate connection weight (\e nc is then ignored).
Note: See TracChangeset for help on using the changeset viewer.