Changeset 749 for cpp/frams/genetics
 Timestamp:
 02/28/18 19:42:24 (2 years ago)
 Location:
 cpp/frams/genetics
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/genetics/oper_fx.cpp
r743 r749 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 19992018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 150 150 void GenoOperators::setIntFromDoubleWithProbabilisticDithering(ParamInterface &p, int index, double value) //TODO 151 151 { 152 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!) 152 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!) 153 } 154 155 void GenoOperators::linearMix(vector<double> &p1, vector<double> &p2, double proportion) 156 { 157 if (p1.size() != p2.size()) 158 { 159 logPrintf("GenoOperators", "linearMix", LOG_ERROR, "Cannot mix vectors of different length (%d and %d)", p1.size(), p2.size()); 160 return; 161 } 162 for (unsigned int i = 0; i < p1.size(); i++) 163 { 164 double v1 = p1[i]; 165 double v2 = p2[i]; 166 p1[i] = v1*proportion + v2*(1  proportion); 167 p2[i] = v2*proportion + v1*(1  proportion); 168 } 153 169 } 154 170 
cpp/frams/genetics/oper_fx.h
r675 r749 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 19992018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 125 125 \code 126 126 { 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 127 int len=strlen(geno); 128 if (len==0  random(2)==0) //add 129 { 130 method=0; 131 char* mutated=(char*)malloc(mutated,len+2); //allocate for mutated genotype 132 mutated[0]='A'+random(10); //first char random 133 strcpy(mutated+1,geno); //the rest is original 134 free(geno); //must take care of the original allocation 135 geno=mutated; 136 } else 137 { 138 method=1; 139 geno[len1]=0; //simply shorten the string  remove last char 140 } 141 chg=1.0/max(len,1); //estimation of mutation strength, divby0safe 142 142 } \endcode 143 143 */ … … 190 190 static double mutateCreep(char type, double current, double mn, double mx); ///<just as mutateCreepNoLimit(), but forces mutated value into the [mn,mx] range using the 'reflect' approach. 191 191 static void setIntFromDoubleWithProbabilisticDithering(ParamInterface &p, int index, double value); ///<sets a double value in an integer field; when a value is noninteger, applies random "dithering" so that both lower and higher integer value have some chance to be set. 192 static void linearMix(ParamInterface &p1, int i1, ParamInterface &p2, int i2, double proportion); ///<mixes i1'th and i2'th properties of p1 and p2; proportion should be within [0,1]; 0.5 causes both properties to become their average. For integer properties applies random "dithering" when necessary. 192 static void linearMix(vector<double> &p1, vector<double> &p2, double proportion); ///<mixes two realvalued vectors; inherited proportion should be within [0,1]; 1.0 does not change values (all inherited), 0.5 causes both vectors to become their average, 0.0 swaps values (none inherited). 193 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. 193 194 static NeuroClass* getRandomNeuroClass(); ///<returns random neuroclass or NULL when no active classes. 194 195 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) … … 215 216 5, // distribution 999 _^_^_ +999 216 217 999, 999, // each weight value may be useful, especially... 217 218 219 220 218 5, 0.3, // ...little nonzero values 219 3, 0.6, 220 0.6, 3, 221 0.3, 5, 221 222 }; 222 223 */
Note: See TracChangeset
for help on using the changeset viewer.