|
166 | 166 | "def rankSelection(chromosome,fitness,popSize):\n", |
167 | 167 | " \n", |
168 | 168 | " rankTotal = sum(x for x in range(0,popSize))\n", |
169 | | - " totRandom = rankTotal*random.uniform(0,rankTotal)\n", |
| 169 | + " totRandom = rankTotal*random.uniform(0,1) #CREEPY Something is here\n", |
170 | 170 | " tot=0\n", |
171 | 171 | " fitness_sorted = fitness.sort_values(by=['fitness'])\n", |
172 | 172 | " for i in fitness_sorted.index:\n", |
|
194 | 194 | " parent2 = rankSelection(chromosome,fitness,popSize)\n", |
195 | 195 | " \n", |
196 | 196 | " #random crossover point\n", |
197 | | - " crossPoint = random.randint(1,popSize)\n", |
| 197 | + " crossPoint = random.randint(1,10)\n", |
198 | 198 | " \n", |
199 | 199 | " c1p1 = parent1[1:crossPoint]\n", |
200 | 200 | " c1p2 = parent1[crossPoint:11]\n", |
201 | 201 | " \n", |
202 | 202 | " child =c1p1.append(c1p2)\n", |
203 | 203 | " \n", |
204 | 204 | " child = bitflip(child)\n", |
205 | | - " return child\n", |
206 | | - " \n", |
207 | | - " #return parent1, parent2\n", |
208 | | - " #if(random.uniform(0,1)<0.75):\n", |
209 | | - " #crossPoint = random.randint(1,popSize)\n", |
210 | | - " #c1p1 = parent1.loc[,1:crossPoint]\n", |
211 | | - " #c1p2 = parent2.loc[,crossPoint+1:11]\n", |
212 | | - " \n", |
213 | | - " #merge c1p1 and c1p2 as the new offspring\n", |
214 | | - " \n", |
215 | | - " \n", |
216 | | - " " |
| 205 | + " return child" |
217 | 206 | ], |
218 | 207 | "execution_count": 0, |
219 | 208 | "outputs": [] |
|
287 | 276 | }, |
288 | 277 | "source": [ |
289 | 278 | "#initialize\n", |
290 | | - "popSize = 16 #population size\n", |
| 279 | + "popSize = 50 #population size\n", |
291 | 280 | "fifo_index = -1\n", |
292 | 281 | "\n", |
293 | 282 | "#iterate model\n", |
294 | | - "values = trainModel(50)\n" |
| 283 | + "values = trainModel(500)\n" |
295 | 284 | ], |
296 | 285 | "execution_count": 0, |
297 | 286 | "outputs": [] |
|
305 | 294 | "base_uri": "https://localhost:8080/", |
306 | 295 | "height": 204 |
307 | 296 | }, |
308 | | - "outputId": "fccba889-e8d2-4fdc-cc48-ecd4aa14a687" |
| 297 | + "outputId": "f09e0c6c-2e64-4ef7-d153-03240ac39d6c" |
309 | 298 | }, |
310 | 299 | "source": [ |
311 | 300 | "values" |
312 | 301 | ], |
313 | | - "execution_count": 139, |
| 302 | + "execution_count": 204, |
314 | 303 | "outputs": [ |
315 | 304 | { |
316 | 305 | "output_type": "execute_result", |
|
319 | 308 | "file 1 1\n", |
320 | 309 | "file 2 1\n", |
321 | 310 | "file 3 1\n", |
322 | | - "file 4 1\n", |
323 | | - "file 5 1\n", |
| 311 | + "file 4 0\n", |
| 312 | + "file 5 0\n", |
324 | 313 | "file 6 0\n", |
325 | 314 | "file 7 1\n", |
326 | 315 | "file 8 1\n", |
327 | | - "file 9 1\n", |
328 | | - "file 10 0\n", |
329 | | - "Name: 5, dtype: int64" |
| 316 | + "file 9 0\n", |
| 317 | + "file 10 1\n", |
| 318 | + "Name: 0, dtype: int64" |
330 | 319 | ] |
331 | 320 | }, |
332 | 321 | "metadata": { |
333 | 322 | "tags": [] |
334 | 323 | }, |
335 | | - "execution_count": 139 |
| 324 | + "execution_count": 204 |
336 | 325 | } |
337 | 326 | ] |
338 | 327 | }, |
|
0 commit comments