Last change
on this file since 1185 was
1185,
checked in by Maciej Komosinski, 2 years ago
|
Renamed a module; new name is "evolalg_steps"
|
File size:
817 bytes
|
Line | |
---|
1 | from evolalg_steps.base.step import Step |
---|
2 | |
---|
3 | |
---|
4 | class LambdaStep(Step): |
---|
5 | """ |
---|
6 | Wrapper for lambda expressions. In "normal" mode each step is given the entire population to work with. This class |
---|
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): |
---|
20 | super(LambdaStep, self).call(population) |
---|
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.