Changeset 960


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

Simplified code and fixed a bug where all existing non-default property values of a neuron would be lost before its mutation (affected fH, fB, fL)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fH/fH_oper.cpp

    r957 r960  
    426426}
    427427
    428 void Geno_fH::mutateNeuronProperties(SString &det)
     428void Geno_fH::mutateNeuronProperties(SString &det) //used also by the "fB" and "fL" encodings
    429429{
    430430        Neuro neu;
    431         det = det == "" ? "N" : det;
    432431        neu.setDetails(det == "" ? "N" : det);
    433 
    434         SyntParam par = neu.classProperties();
    435 
    436         if (par.getPropCount() > 0)
    437         {
    438                 int i = rndUint(par.getPropCount());
    439                 if (*par.type(i) == 'f')
    440                 {
    441                         double change = mutateNeuronProperty(par.getDouble(i), &neu, GenoOperators::NEUROCLASS_PROP_OFFSET + i);
    442                         par.setDouble(i, change);
    443                 }
    444                 SString line;
    445                 int tmp = 0;
    446                 par.update(&line);
    447                 SString props;
    448                 line.getNextToken(tmp, props, '\n'); // removal of newline character
    449                 if (props != "")
    450                 {
    451                         det = neu.getClass()->name;
    452                         det += ": ";
    453                         det += props;
    454                 }
    455         }
     432        GenoOperators::mutateRandomNeuronOrNeuroclassProperty(&neu);
     433        det = neu.getDetails();
    456434}
    457435
    458436void Geno_fH::mutateNeuronHandleProperties(fH_NeuronHandle *handle, ParamEntry *tab, bool userandomclass)
    459437{
    460         Neuro neu;
    461438        Param hpar(tab, handle->obj);
    462         SString det = hpar.getStringById("d");
    463         neu.setDetails(det == "" ? "N" : det);
    464         NeuroClass *nc = neu.getClass();
    465 
     439        SString det;
    466440        if (userandomclass)
    467441        {
    468                 nc = getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK);
    469                 // checking of neuron class availability should be done before
    470         }
    471 
    472         det = nc->getName();
    473 
     442                NeuroClass *nc = getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK); // checking that neuron classes are available should be done before
     443                det = nc->getName();
     444        }
     445        else
     446        {
     447                det = hpar.getStringById("d");
     448        }
    474449        mutateNeuronProperties(det);
    475 
    476450        hpar.setStringById("d", det);
    477451}
Note: See TracChangeset for help on using the changeset viewer.