Last change
on this file since 1195 was
1185,
checked in by Maciej Komosinski, 2 years ago
|
Renamed a module; new name is "evolalg_steps"
|
File size:
817 bytes
|
Rev | Line | |
---|
[1185] | 1 | from evolalg_steps.base.step import Step |
---|
[1113] | 2 | |
---|
| 3 | |
---|
| 4 | class LambdaStep(Step): |
---|
| 5 | """ |
---|
[1114] | 6 | Wrapper for lambda expressions. In "normal" mode each step is given the entire population to work with. This class |
---|
[1113] | 7 | helps with any Callable that accepts individuals. |
---|
| 8 | |
---|
| 9 | """ |
---|
| 10 | def __init__(self, fun, in_place=True, *args, **kwargs): |
---|
| 11 | """ |
---|
| 12 | @param fun: Callable callable that will be called for each individual |
---|
| 13 | @param in_place: Bool |
---|
| 14 | """ |
---|
| 15 | super(LambdaStep, self).__init__(*args, **kwargs) |
---|
| 16 | self.fun = fun |
---|
| 17 | self.in_place = in_place |
---|
| 18 | |
---|
| 19 | def call(self, population): |
---|
[1139] | 20 | super(LambdaStep, self).call(population) |
---|
[1113] | 21 | if self.in_place: |
---|
| 22 | [self.fun(_) for _ in population] |
---|
| 23 | else: |
---|
| 24 | population = [self.fun(_) for _ in population] |
---|
| 25 | return population |
---|
Note: See
TracBrowser
for help on using the repository browser.