Ignore:
Timestamp:
03/15/18 22:55:05 (6 years ago)
Author:
Maciej Komosinski
Message:
  • added support for new API for neuron types and their properties
  • added support for checkpoints
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/oper_f4.h

    r674 r760  
    1515#include <frams/param/param.h>
    1616
     17/** @name Codes for general mutation types */
     18//@{
     19#define F4_ADD           0 ///<Adding new node
     20#define F4_DEL           1 ///<Deletion of node
     21#define F4_MOD           2 ///<Modification of node
     22#define F4_COUNT         3 ///<Count of mutation types
     23//@}
    1724
    18 #define F4_ADD           0
    19 #define F4_DEL           1
    20 #define F4_MOD           2
    21 #define F4_COUNT         3
    22 
     25/** @name Codes for specific F4_ADD mutation subtypes */
     26//@{
    2327#define F4_ADD_DIV       0
    2428#define F4_ADD_CONN      1
     
    2731#define F4_ADD_SIMP      4
    2832#define F4_ADD_COUNT     5
    29 
     33//@}
    3034
    3135class Geno_f4 : public GenoOperators
     
    4347
    4448        // mutation probabilities
    45         double prob[F4_COUNT], probadd[F4_ADD_COUNT];
     49        double prob[F4_COUNT];            ///<reltive probabilities of selecting mutation types in f4 genotype
     50        double probadd[F4_ADD_COUNT];     ///<relative probabilities of selecting mutation addition subtypes
    4651
    47         SString excluded_modifiers; //not to be used in mutations
     52        SString excluded_modifiers;       ///<Modifiers that are excluded in mutation process
    4853        static const char *all_modifiers;
    4954
    5055protected:
    51         /* int MutateMany(char *& g, float & chg); // not used anymore */
     56
     57        /**
     58         * Validates a f4 genotype. If the genotype is invalid, the genotype is repaired
     59         * and the validation is repeated. Validation is performed as long as repairing
     60         * is not effective, or the number of retries exceeded the given limit.
     61         * @param geno genotype tree
     62         * @param retrycount maximum amount of repair retries
     63         * @return GENOOPER_OK if genotype is valid, GENOPER_REPAIR if genotype can be repaired, GENOPER_OPFAIL if genotype can't be repaired
     64         */
    5265        int  ValidateRec(f4_node * geno, int retrycount) const;
     66
     67        /**
     68         * Performs mutation of an f4 genotype. The mutation is performed on a random node
     69         * from a given tree. The method of mutation is chosen via the roulette selection,
     70         * where probabilities of choosing each mutation type are given in the 'prob'
     71         * array. Possible mutation types are:
     72         *  - F4_ADD - adds new element to the genotype by:
     73         *   - F4_ADD_DIV - replacing randomly selected node with division node '<', setting this node as a child and creating new stick or neuron sibling of the selected cell (the neuron-type sibling will be connected to a random existing neuron),
     74         *   - F4_ADD_CONN - adding connection for an existing neuron,
     75         *   - F4_ADD_NEUPAR - adding neuron property to the selected node, if it is a neuron node,
     76         *   - F4_ADD_REP - adding a repetition node before a randomly selected node (the repetition node has 2 repetitions),
     77         *   - F4_ADD_SIMP - adding a simple node before a selected node,
     78         *  - F4_DEL - removes a randomly selected node (the node needs to have a parent and at least one child, otherwise returns GENOPER_OPFAIL),
     79         *  - F4_MOD - modifies one of simple nodes by:
     80         *   - '<' - swapping children in division
     81         *   - '[' - modifying connection of a neuron
     82         *   - '#' - incrementing or decrementing repetition count
     83         *
     84         * @param g input genotype; the result of mutation will be stored in this parameter
     85         * @param method reference to the variable that will get the selected method of mutation
     86         * @return GENOPER_OK if mutation was performed successfully, GENOPER_FAIL otherwise
     87         */
    5388        int  MutateOne(f4_node *& g, int &method) const;
    54         void linkNodeMakeRandom(f4_node * nn) const;
    55         void linkNodeChangeRandom(f4_node * nn) const;
    56         void nparNodeMakeRandom(f4_node * nn) const;
    57         void repeatNodeChangeRandom(f4_node * nn) const;
     89
     90        /**
     91         * Creates a random connection to an existing neuron or creates an additional
     92         * sensor for a neuron.
     93         * @param nn neuron class node
     94         * @param neuid id of a neuron
     95         * @param neulist list of genotype neuron classes
     96         */
     97        void linkNodeMakeRandom(f4_node * nn, int neuid, std::vector<NeuroClass*> neulist) const;
     98
     99        /**
     100         * Changes connection to an existing neuron or creates an additional
     101         * sensor for neuron.
     102         * @param nn neuron connection node
     103         * @param neuid id of a neuron
     104         * @param neulist list of genotype neuron classes
     105         */
     106        void linkNodeChangeRandom(f4_node * nn, int neuid, std::vector<NeuroClass*> neulist) const;
     107
     108        /**
     109         * Introduces a random modification to the neuron node.
     110         * @param nn neuron node
     111         */
     112        void nparNodeMakeRandom(f4_node *nn) const;
     113
     114        /**
     115         * Increases or decreases the amount of repetitions in the repetition node.
     116         * @param nn repetition node
     117         */
     118        void repeatNodeChangeRandom(f4_node *nn) const;
     119
     120        /**
     121         * Tries to perform a mutation until success. There is a maximum of 20 tries. Returns GENOPER_OK or GENOPER_OPFAIL.
     122         * @param g genotype tree
     123         * @param method reference to the variable that will get the selected method of mutation
     124         * @return GENOPER_OK if performed successful mutation, GENOPER_FAIL otherwise
     125         */
    58126        int  MutateOneValid(f4_node * &g, int &method) const;
     127
     128        /**
     129         * Performs crossover of two creatures. The 'chg' parameter determines approximately what
     130         * percentage of the first creature should form the offspring. '1-chg' is the percentage
     131         * of the second creature in the offspring.
     132         * @param g1 first parent
     133         * @param g2 second parent
     134         * @param chg percentage of the first parent in offspring (the second parent has the rest)
     135         */
    59136        int  CrossOverOne(f4_node *g1, f4_node *g2, float chg) const;
    60         // returns GENOPER_OK or GENOPER_OPFAIL
    61         // chg: fraction of parent1 genes in child (in g1) (parent2 has the rest)
    62137};
    63138
Note: See TracChangeset for help on using the changeset viewer.