# Changeset 749

Ignore:
Timestamp:
02/28/18 19:42:24 (6 years ago)
Message:

Added a new function to linearly mix two vectors of real numbers

Location:
cpp/frams/genetics
Files:
2 edited

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

 r743 // This file is a part of Framsticks SDK.  http://www.framsticks.com/ // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski. // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. void GenoOperators::setIntFromDoubleWithProbabilisticDithering(ParamInterface &p, int index, double value) //TODO { p.setInt(index, (paInt)value); //TODO value=2.5 will result in 2 but we want it to be 2 or 3 with equal probability. value=2.1 would be mostly 2, rarely 3. Careful with negative values (test it!) p.setInt(index, (paInt)(value + 0.5)); //TODO value=2.499 will result in 2 and 2.5 will result in 3, but we want these cases to be 2 or 3 with almost equal probability. value=2.1 should be mostly 2, rarely 3. Careful with negative values (test it!) } void GenoOperators::linearMix(vector &p1, vector &p2, double proportion) { if (p1.size() != p2.size()) { logPrintf("GenoOperators", "linearMix", LOG_ERROR, "Cannot mix vectors of different length (%d and %d)", p1.size(), p2.size()); return; } for (unsigned int i = 0; i < p1.size(); i++) { double v1 = p1[i]; double v2 = p2[i]; p1[i] = v1*proportion + v2*(1 - proportion); p2[i] = v2*proportion + v1*(1 - proportion); } }
• ## cpp/frams/genetics/oper_fx.h

 r675 // This file is a part of Framsticks SDK.  http://www.framsticks.com/ // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski. // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. \code { int len=strlen(geno); if (len==0 || random(2)==0) //add { method=0; char* mutated=(char*)malloc(mutated,len+2); //allocate for mutated genotype mutated[0]='A'+random(10); //first char random strcpy(mutated+1,geno); //the rest is original free(geno); //must take care of the original allocation geno=mutated; } else { method=1; geno[len-1]=0; //simply shorten the string - remove last char } chg=1.0/max(len,1); //estimation of mutation strength, divby0-safe int len=strlen(geno); if (len==0 || random(2)==0) //add { method=0; char* mutated=(char*)malloc(mutated,len+2); //allocate for mutated genotype mutated[0]='A'+random(10); //first char random strcpy(mutated+1,geno); //the rest is original free(geno); //must take care of the original allocation geno=mutated; } else { method=1; geno[len-1]=0; //simply shorten the string - remove last char } chg=1.0/max(len,1); //estimation of mutation strength, divby0-safe } \endcode */ static double mutateCreep(char type, double current, double mn, double mx); /// &p1, vector &p2, double proportion); ///& NClist); //returns index of random neuroclass from the NClist or -1 (no neurons on the list that provide output) 5,                 // distribution -999 _-^_^-_ +999 -999, 999,         // each weight value may be useful, especially... -5, -0.3,        // ...little non-zero values -3, -0.6, 0.6, 3, 0.3, 5, -5, -0.3,        // ...little non-zero values -3, -0.6, 0.6, 3, 0.3, 5, }; */
Note: See TracChangeset for help on using the changeset viewer.