Changeset 967 for cpp/frams/genetics


Ignore:
Timestamp:
06/28/20 23:33:17 (4 years ago)
Author:
Maciej Komosinski
Message:

Improved names of functions that mutate neuron properties and improved docs

Location:
cpp/frams/genetics
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_oper.cpp

    r957 r967  
    451451        }
    452452        // weight
    453         nn->f1 = GenoOperators::mutateNeuronProperty(nn->f1, NULL, -1);
     453        nn->f1 = GenoOperators::getMutatedNeuroClassProperty(nn->f1, NULL, -1);
    454454        //nn->f1 = 10.0f * (rndDouble(1) - 0.5f);
    455455}
     
    488488                break;
    489489        case 2: // change weight
    490                 nn->f1 = GenoOperators::mutateNeuronProperty(nn->f1, NULL, -1);
     490                nn->f1 = GenoOperators::getMutatedNeuroClassProperty(nn->f1, NULL, -1);
    491491                //nn->f1 += 1.0f * (rndDouble(1) - 0.5f);
    492492                break;
  • cpp/frams/genetics/fH/fH_oper.cpp

    r960 r967  
    390390                        // if it is weight, then method needs to use mutateNeuProperty
    391391                        double current = par.getDouble(id);
    392                         par.setDouble(id, mutateNeuronProperty(current, NULL, -1));
     392                        par.setDouble(id, getMutatedNeuroClassProperty(current, NULL, -1));
    393393                }
    394394        }
     
    430430        Neuro neu;
    431431        neu.setDetails(det == "" ? "N" : det);
    432         GenoOperators::mutateRandomNeuronOrNeuroclassProperty(&neu);
     432        GenoOperators::mutateRandomNeuroClassProperty(&neu);
    433433        det = neu.getDetails();
    434434}
  • cpp/frams/genetics/fS/fS_oper.cpp

    r958 r967  
    607607                        advance(it, rndUint(inputCount));
    608608
    609                         it->second = GenoOperators::mutateNeuronProperty(it->second, selectedNeuron, -1);
     609                        it->second = GenoOperators::getMutatedNeuroClassProperty(it->second, selectedNeuron, -1);
    610610                        return true;
    611611                }
     
    680680                if (*par.type(i) == 'f')
    681681                {
    682                         double change = GenoOperators::mutateNeuronProperty(par.getDouble(i), neu, GenoOperators::NEUROCLASS_PROP_OFFSET + i);
     682                        double change = GenoOperators::getMutatedNeuroClassProperty(par.getDouble(i), neu, GenoOperators::NEUROCLASS_PROP_OFFSET + i);
    683683                        par.setDouble(i, change);
    684684                }
  • cpp/frams/genetics/genooperators.cpp

    r959 r967  
    7676}
    7777
    78 bool GenoOperators::mutateRandomNeuronOrNeuroclassProperty(Neuro* n)
     78bool GenoOperators::mutateRandomNeuroClassProperty(Neuro* n)
    7979{
    8080        bool mutated = false;
    81         int prop = selectRandomNeuronProperty(n);
     81        int prop = selectRandomNeuroClassProperty(n);
    8282        if (prop >= 0)
    8383        {
    8484                if (prop >= GenoOperators::NEUROCLASS_PROP_OFFSET)
    8585                {
    86                         SyntParam par = n->classProperties();   //commits changes when p is destroyed
     86                        SyntParam par = n->classProperties();   //commits changes when this object is destroyed
    8787                        mutated = mutateProperty(par, prop - GenoOperators::NEUROCLASS_PROP_OFFSET);
    8888                }
     
    9696}
    9797
    98 int GenoOperators::selectRandomNeuronProperty(Neuro *n)
     98int GenoOperators::selectRandomNeuroClassProperty(Neuro *n)
    9999{
    100100        int neuext = n->extraProperties().getPropCount(),
     
    106106}
    107107
    108 double GenoOperators::mutateNeuronProperty(double current, Neuro *n, int i)
     108double GenoOperators::getMutatedNeuroClassProperty(double current, Neuro *n, int i)
    109109{
    110110        if (i == -1) return mutateCreepNoLimit('f', current, 2, true); //i==-1: mutating weight of neural connection
  • cpp/frams/genetics/genooperators.h

    r959 r967  
    181181        //@{
    182182
    183         static const int NEUROCLASS_PROP_OFFSET = 100; //a property is identified by some functions below as a single-value integer index, yet a property concerns either a Neuron or a NeuroClass, hence this offset to tell one case from the other.
     183        static const int NEUROCLASS_PROP_OFFSET = 100; //a NeuroClass property is identified by some functions below as a single-value integer index, yet a property is either "standard" or "extra" (two separate lists), hence this offset to tell one case from the other.
    184184
    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).
    188         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.
    189         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).
     187        static bool mutateRandomNeuroClassProperty(Neuro* n); ///<high-level neuron mutation function, will select and mutate a random property of Neuron's NeuroClass. Returns true if successful and some property was actually mutated. Could return false when the NeuroClass of the Neuron have no properties, or when a randomly selected property was not suitable for mutation (for example a string or another non-number type).
     188        static int selectRandomNeuroClassProperty(Neuro* n); ///<selects random property (either 0-based extraproperty of NeuroClass or NEUROCLASS_PROP_OFFSET-based standard property of NeuroClass). -1 if Neuroclass has no properties.
     189        static double getMutatedNeuroClassProperty(double current, Neuro *n, int propindex); ///<returns value \e current mutated for the property \e propindex of Neuron's NeuroClass or for extraproperty (\e propindex - NEUROCLASS_PROP_OFFSET) of Neuron's NeuroClass. Neuro \e n is used as read-only. Use \e propindex == -1 to mutate connection weight (\e n and \e i are then ignored).
    190190        static bool mutatePropertyNaive(ParamInterface &p, int propindex); ///<creep-mutate selected property. Returns true when success. mutateProperty() should be used instead of this function.
    191191        static bool mutateProperty(ParamInterface &p, int propindex); ///<like mutatePropertyNaive(), but uses special probability distributions for some neuron properties.
     
    207207        static NeuroClass* parseNeuroClass(char *&s); ///<returns longest matching neuroclass or NULL if the string does not begin with a valid neuroclass name. Advances \e s pointer.
    208208        static Neuro* findNeuro(const Model *m, const NeuroClass *nc); ///<returns pointer to first Neuro of class \e nc, or NULL if there is no such Neuro.
    209         static int neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props = false); ///<returns 0-based property number for \e neuroclass, NEUROCLASS_PROP_OFFSET-based extraproperty number for Neuro, or -1 if the string does not begin with a valid property name. Advance \e s pointer if success.
     209        static int neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props = false); ///<returns 0-based extraproperty of NeuroClass or NEUROCLASS_PROP_OFFSET-based standard property of NeuroClass, or -1 if the string does not begin with a valid property name. Advance \e s pointer if success.
    210210        static bool isWS(const char c); ///<is \e c a whitespace char?
    211211        static void skipWS(char *&s); ///<advances pointer \e s skipping whitespaces.
Note: See TracChangeset for help on using the changeset viewer.