Line | |
---|
1 | from evolalg.base.step import Step |
---|
2 | |
---|
3 | |
---|
4 | class LambdaStep(Step): |
---|
5 | """ |
---|
6 | Wrapper for lambda expressions. In "normal" mode each step is given whole 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 | if self.in_place: |
---|
21 | [self.fun(_) for _ in population] |
---|
22 | else: |
---|
23 | population = [self.fun(_) for _ in population] |
---|
24 | return population |
---|
Note: See
TracBrowser
for help on using the repository browser.