Last change
on this file since 1190 was
1190,
checked in by Maciej Komosinski, 2 years ago
|
Added the "evolalg" module for evolutionary optimization
|
File size:
592 bytes
|
Line | |
---|
1 | import numpy as np |
---|
2 | |
---|
3 | |
---|
4 | class RandomIndexSequence: |
---|
5 | """A helper function for tournament selection. Allows each individual to take part in a tournament, |
---|
6 | thus reducing the risk of overlooking individuals by not sampling them due to uncontrolled |
---|
7 | randomness, as can happen in the naive implementation of tournament selection.""" |
---|
8 | |
---|
9 | def __init__(self, popsize): |
---|
10 | self.popsize: int = popsize |
---|
11 | self.permut: list = [] |
---|
12 | |
---|
13 | def getNext(self): |
---|
14 | if len(self.permut) < 1: |
---|
15 | self.permut = list(np.random.permutation(self.popsize)) |
---|
16 | return self.permut.pop() |
---|
Note: See
TracBrowser
for help on using the repository browser.