Changeset 758


Ignore:
Timestamp:
03/15/18 22:50:46 (7 years ago)
Author:
Maciej Komosinski
Message:

Added a few useful functions providing lists of neurons with specific properties

Location:
cpp/frams/genetics
Files:
2 edited

Legend:

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

    r751 r758  
    212212        for (int i = 0; i < Neuro::getClassCount(); i++)
    213213                if (Neuro::getClass(i)->genactive)
     214                        active.push_back(Neuro::getClass(i));
     215        if (active.size() == 0) return NULL; else return active[randomN(active.size())];
     216}
     217
     218NeuroClass* GenoOperators::getRandomNeuroClassWithOutput()
     219{
     220        vector<NeuroClass*> active;
     221        for (int i = 0; i < Neuro::getClassCount(); i++)
     222                if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0)
     223                        active.push_back(Neuro::getClass(i));
     224        if (active.size() == 0) return NULL; else return active[randomN(active.size())];
     225}
     226
     227NeuroClass* GenoOperators::getRandomNeuroClassWithInput()
     228{
     229        vector<NeuroClass*> active;
     230        for (int i = 0; i < Neuro::getClassCount(); i++)
     231                if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredInputs() != 0)
     232                        active.push_back(Neuro::getClass(i));
     233        if (active.size() == 0) return NULL; else return active[randomN(active.size())];
     234}
     235
     236NeuroClass* GenoOperators::getRandomNeuroClassWithOutputAndNoInputs()
     237{
     238        vector<NeuroClass*> active;
     239        for (int i = 0; i < Neuro::getClassCount(); i++)
     240                if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0 && Neuro::getClass(i)->getPreferredInputs() == 0)
    214241                        active.push_back(Neuro::getClass(i));
    215242        if (active.size() == 0) return NULL; else return active[randomN(active.size())];
     
    342369}
    343370
    344 bool GenoOperators::isNeuroClassName(const char firstchar)
     371bool GenoOperators::canStartNeuroClassName(const char firstchar)
    345372{
    346373        return isupper(firstchar) || firstchar == '|' || firstchar == '@' || firstchar == '*';
  • cpp/frams/genetics/oper_fx.h

    r751 r758  
    194194        static void linearMix(ParamInterface &p1, int i1, ParamInterface &p2, int i2, double proportion); ///<mixes i1'th and i2'th properties of p1 and p2; inherited proportion should be within [0,1]; 1.0 does not change values (all inherited), 0.5 causes both properties to become their average, 0.0 swaps values (none inherited). For integer properties applies random "dithering" when necessary.
    195195        static NeuroClass* getRandomNeuroClass(); ///<returns random neuroclass or NULL when no active classes.
    196         static int getRandomNeuroClassWithOutput(const vector<NeuroClass*>& NClist); //returns index of random neuroclass from the NClist or -1 (no neurons on the list that provide output)
    197         static int getRandomNeuroClassWithInput(const vector<NeuroClass*>& NClist); //returns index of random neuroclass from the NClist or -1 (no neurons on the list that want input(s))
     196        static NeuroClass* getRandomNeuroClassWithOutput(); ///<returns random neuroclass with output or NULL when no active classes.
     197        static NeuroClass* getRandomNeuroClassWithInput(); ///<returns random neuroclass with input or NULL when no active classes.
     198        static NeuroClass* getRandomNeuroClassWithOutputAndNoInputs(); ///<returns random sensor or NULL when no active classes.
     199        static NeuroClass* getRandomSensorProb(float prob); ///<returns random sensor (only-output neuron class) with presented probability or NULL. \e prob probability of picking neuron class.
     200        static int getRandomNeuroClassWithOutput(const vector<NeuroClass*>& NClist); ///<returns index of random NeuroClass from the NClist or -1 (no neurons on the list that provide output) \e NClist list of available neuron classes
     201        static int getRandomNeuroClassWithInput(const vector<NeuroClass*>& NClist); ///<returns index of random NeuroClass from the NClist or -1 (no neurons on the list that want input(s)) \e NClist list of available neuron classes
    198202        static int getRandomChar(const char *choices, const char *excluded); ///<returns index of a random character from 'choices' excluding 'excluded', or -1 when everything is excluded or 'choices' is empty.
    199203        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.
     
    204208        static bool areAlike(char*, char*); ///<compares two text strings skipping whitespaces. Returns 1 when equal, 0 when different.
    205209        static char* strchrn0(const char *str, char ch); ///<like strchr, but does not find zero char in \e str.
    206         static bool isNeuroClassName(const char firstchar); ///<determines if \e firstchar may start NeuroClass name. If not, it may start NeuroClass' (or Neuro's) property name.
     210        static bool canStartNeuroClassName(const char firstchar); ///<determines if \e firstchar may start NeuroClass name. If not, it may start NeuroClass' (or Neuro's) property name.
    207211        //@}
    208212};
Note: See TracChangeset for help on using the changeset viewer.