Changeset 1228 for cpp/frams/genetics/f4/f4_oper.cpp
- Timestamp:
- 04/28/23 23:44:31 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_oper.cpp
r1227 r1228 13 13 // TODO getting rid of redundancy (having valid genotypes with a lot of "junk code") in this representation looks like a good idea. 14 14 // 15 // Note: symbols after the last > are ignored, for example /*4*/<X>N:N> N:N[2:-0.5]XXXwhatever but since they are not parsed into the f4_Node tree, they will be lost after any mutation.15 // Note: symbols after the last > are ignored, for example /*4*/<X>N:N>blablaN:N[2:-0.5]XXXwhatever but since they are not parsed into the f4_Node tree, they will be lost after any mutation. 16 16 // 17 // TODO the behavior of neuron input indexes during mutation seems badly implemented (see also TREAT_BAD_CONNECTIONS_AS_ ERRORS). Are they kept properly maintained when nodes are added and removed? This could be done well because during mutation we operate on the tree structure with cross-references between nodes (so they should not be affected by local changes in the tree), and then convert the tree back to string. Yet, the f4_Node.conn_from is an integer and these fields in nodes do not seem to be maintained on tree node adding/removal... change these integer offsets to references to node objects? But actually, do the offsets that constitute relative connection references concern the f4_Node tree structure (and all these sophisticated calculations of offsets during mutation are useful) or rather they concern the f4_Cells development? verify all situations in f4_Cell::oneStep(), case '['.17 // TODO the behavior of neuron input indexes during mutation seems badly implemented (see also TREAT_BAD_CONNECTIONS_AS_INVALID_GENO). Are they kept properly maintained when nodes are added and removed? This could be done well because during mutation we operate on the tree structure with cross-references between nodes (so they should not be affected by local changes in the tree), and then convert the tree back to string. Yet, the f4_Node.conn_from is an integer and these fields in nodes do not seem to be maintained on tree node adding/removal... change these integer offsets to references to node objects? But actually, do the offsets that constitute relative connection references concern the f4_Node tree structure (and all these sophisticated calculations of offsets during mutation are useful) or rather they concern the f4_Cells development? verify all situations in f4_Cell::oneStep(), case '['. 18 18 // TODO add simplifying sequences of modifiers (so capital and small letter cancel out, like in f1) - but seems like each single modifier is a separate f4_Node? and perhaps we don't want to use the repair mechanism for this... maybe mutations, when they add/modify/remove a modifier node, should be "cleaning" the tree by removing nodes when they encounter contradictory modifiers on the same subpath? 19 19 // TODO add support for properties of (any class of) neurons - not just sigmoid/force/intertia (':' syntax) for N … … 122 122 // convert geno to tree, then try to validate 20 times 123 123 f4_Node root; 124 if (f4_process rec(geno, 0, &root) || root.childCount() != 1) return GENOPER_OK; // cannot repair124 if (f4_processRecur(geno, 0, &root) || root.childCount() != 1) return GENOPER_OK; // cannot repair 125 125 if (ValidateRec(&root, 20) == GENOPER_REPAIR) // if repaired, make it back to string 126 126 { … … 135 135 { 136 136 f4_Node root; 137 int res = f4_process rec(geno, 0, &root);137 int res = f4_processRecur(geno, 0, &root); 138 138 if (res) return res; // errorpos, >0 139 139 if (root.childCount() != 1) return 1; //earlier: GENOPER_OPFAIL … … 208 208 // The "false" argument in findConnectionNeuronIndexes() below is not suffient, because we also need to access (find) the f4_Node of the other neuron. 209 209 // A similar logic is implemented in F4_ADD_CONN below, but let's not complicate this F4_ADD_DIV mutation anymore. 210 // Adisadvantage is that the node_new_neuron added here which is a neuron that provides output (e.g., a receptor, N, etc.) will not get connected immediately here even when there are already existing neurons wanting inputs (e.g., muscles, N, etc.).210 // The disadvantage is that the node_new_neuron added here which is a neuron that provides output (e.g., a receptor, N, etc.) will not get connected immediately here even when there are already existing neurons wanting inputs (e.g., muscles, N, etc.). 211 211 //bool ok = findConnectionNeuronIndexes(g, ... , false, ..., ...); 212 212 } … … 230 230 231 231 // the probability that a randomly selected node will be a neuron and additionally this neuron will accept inputs is low, 232 // so we disregard randomly picked node_mutated and build a list of all valid candidate nodes here, then select a randomone from them.232 // so we disregard randomly picked node_mutated and build a list of all valid candidate nodes here, then randomly select one from them. 233 233 234 234 vector<f4_Node*> candidate_nodes; //neurons that accept input(s) … … 476 476 // relative input connection to some existing neuron 477 477 nn->conn_from = nn_index - other_index; 478 //nn->conn_from = (int)(4.0f * (rndDouble(1) - 0.5 f)); //in very old times - did not care about neuron input/output preferences478 //nn->conn_from = (int)(4.0f * (rndDouble(1) - 0.5)); //in very old times - did not care about neuron input/output preferences 479 479 480 480 nn->conn_weight = GenoOperators::getMutatedNeuronConnectionWeight(nn->conn_weight); … … 493 493 void Geno_f4::repeatNodeChangeRandom(f4_Node *nn) const 494 494 { 495 if (rndDouble(1) < 0.5 f) nn->reps++; else nn->reps--; // change count495 if (rndDouble(1) < 0.5) nn->reps++; else nn->reps--; // change count 496 496 if (nn->reps < 1) nn->reps = 1; 497 497 if (nn->reps > mut_max_rep) nn->reps = mut_max_rep; … … 547 547 { 548 548 f4_Node *root = new f4_Node; 549 if (f4_process rec(g, 0, root) || root->childCount() != 1)549 if (f4_processRecur(g, 0, root) || root->childCount() != 1) 550 550 { 551 551 delete root; … … 607 607 608 608 // decide number of nodes to mutate 609 n = (int)( 0.5 f+ rndDouble(1) * maxToMut );609 n = (int)( 0.5 + rndDouble(1) * maxToMut ); 610 610 if (n<1) n=1; 611 611 if (n>totNodes) n=totNodes; … … 671 671 672 672 // convert genotype strings into tree structures 673 if (f4_process rec(g1, 0, &root1) || (root1.childCount() != 1)) return GENOPER_OPFAIL;674 if (f4_process rec(g2, 0, &root2) || (root2.childCount() != 1)) return GENOPER_OPFAIL;673 if (f4_processRecur(g1, 0, &root1) || (root1.childCount() != 1)) return GENOPER_OPFAIL; 674 if (f4_processRecur(g2, 0, &root2) || (root2.childCount() != 1)) return GENOPER_OPFAIL; 675 675 676 676 // decide amounts of crossover, 0.25-0.75
Note: See TracChangeset
for help on using the changeset viewer.