source: framspy/evolalg/base/lambda_step.py @ 1139

Last change on this file since 1139 was 1139, checked in by Maciej Komosinski, 4 years ago

Added --debug mode that prints names of steps; final multiple evaluation now evaluates genotypes in hall of fame instead of the last population

File size: 811 bytes
Line 
1from evolalg.base.step import Step
2
3
4class 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.