コード例 #1
0
    def __init__(self,
                 chromosome,
                 maxNIndividuals,
                 valueInitializer=Randomization(-0.1, 0.1),
                 **kwargs):
        """ :key chromosome: The prototype chromosome
            :key maxNIndividuals: The maximum allowed number of individuals
        """
        SimplePopulation.__init__(self)

        self._prototype = EvolinoSubIndividual(chromosome)

        self._maxNIndividuals = maxNIndividuals
        self._valueInitializer = valueInitializer

        self.setArgs(**kwargs)

        for _ in range(maxNIndividuals):
            self.addIndividual(self._prototype.copy())
        self._valueInitializer.apply(self)
コード例 #2
0
ファイル: population.py プロジェクト: Boblogic07/pybrain
class EvolinoSubPopulation(SimplePopulation):
    """ The class for Evolino subpopulations. Mostly the same as SimplePopulation
        but with a few extensions.
        It contains a set of EvolinoSubIndividuals.

        On initialization, a prototype individual is created from the prototype
        chromosome. This individual is then cloned and added so that the
        population exists of maxNIndividuals individuals.

        The genomes of these clones are then randomized by the Randomization
        operator.
    """
    def __init__(self, chromosome, maxNIndividuals, valueInitializer=Randomization(-0.1, 0.1), **kwargs):
        """ :key chromosome: The prototype chromosome
            :key maxNIndividuals: The maximum allowed number of individuals
        """
        SimplePopulation.__init__(self)

        self._prototype = EvolinoSubIndividual(chromosome)

        self._maxNIndividuals = maxNIndividuals
        self._valueInitializer = valueInitializer


        self.setArgs(**kwargs)


        for _ in range(maxNIndividuals):
            self.addIndividual(self._prototype.copy())
        self._valueInitializer.apply(self)


    def setArgs(self, **kwargs):
        for key, val in kwargs.iteritems():
            getattr(self, key)
            setattr(self, key, val)


    def getMaxNIndividuals(self):
        """ Returns the maximum allowed number of individuals """
        return self._maxNIndividuals

    def addIndividualFitness(self, individual, fitness):
        """ Add fitness to the individual's fitness value.
            :key fitness: a float value denoting the fitness
        """
        self._fitness[individual] += fitness
コード例 #3
0
class EvolinoSubPopulation(SimplePopulation):
    """ The class for Evolino subpopulations. Mostly the same as SimplePopulation
        but with a few extensions.
        It contains a set of EvolinoSubIndividuals.

        On initialization, a prototype individual is created from the prototype
        chromosome. This individual is then cloned and added so that the
        population exists of maxNIndividuals individuals.

        The genomes of these clones are then randomized by the Randomization
        operator.
    """
    def __init__(self,
                 chromosome,
                 maxNIndividuals,
                 valueInitializer=Randomization(-0.1, 0.1),
                 **kwargs):
        """ :key chromosome: The prototype chromosome
            :key maxNIndividuals: The maximum allowed number of individuals
        """
        SimplePopulation.__init__(self)

        self._prototype = EvolinoSubIndividual(chromosome)

        self._maxNIndividuals = maxNIndividuals
        self._valueInitializer = valueInitializer

        self.setArgs(**kwargs)

        for _ in range(maxNIndividuals):
            self.addIndividual(self._prototype.copy())
        self._valueInitializer.apply(self)

    def setArgs(self, **kwargs):
        for key, val in list(kwargs.items()):
            getattr(self, key)
            setattr(self, key, val)

    def getMaxNIndividuals(self):
        """ Returns the maximum allowed number of individuals """
        return self._maxNIndividuals

    def addIndividualFitness(self, individual, fitness):
        """ Add fitness to the individual's fitness value.
            :key fitness: a float value denoting the fitness
        """
        self._fitness[individual] += fitness
コード例 #4
0
ファイル: population.py プロジェクト: Boblogic07/pybrain
    def __init__(self, chromosome, maxNIndividuals, valueInitializer=Randomization(-0.1, 0.1), **kwargs):
        """ :key chromosome: The prototype chromosome
            :key maxNIndividuals: The maximum allowed number of individuals
        """
        SimplePopulation.__init__(self)

        self._prototype = EvolinoSubIndividual(chromosome)

        self._maxNIndividuals = maxNIndividuals
        self._valueInitializer = valueInitializer


        self.setArgs(**kwargs)


        for _ in range(maxNIndividuals):
            self.addIndividual(self._prototype.copy())
        self._valueInitializer.apply(self)
コード例 #5
0
ファイル: evolino.py プロジェクト: xj361685640/molSimplify
    def __init__(self, evolino_network, dataset, **kwargs):
        """
            :key subPopulationSize: Size of the subpopulations.
            :key nCombinations: Number of times each chromosome is built into an individual. default=1
            :key nParents: Number of individuals left in a subpopulation after selection.
            :key initialWeightRange: Range of the weights of the RNN after initialization. default=(-0.1,0.1)
            :key weightInitializer: Initializer object for the weights of the RNN. default=Randomization(...)
            :key mutationAlpha: The mutation's intensity. default=0.01
            :key mutationVariate: The variate used for mutation. default=CauchyVariate(...)
            :key wtRatio: The quotient: washout-time/training-time. Needed to
                            split the sequences into washout phase and training phase.
            :key nBurstMutationEpochs: Number of epochs without increase of fitness in a row,
                                         before burstmutation is applied. default=Infinity
            :key backprojectionFactor: Weight of the backprojection. Usually
                                         supplied through evolino_network.
            :key selection: Selection object for evolino
            :key reproduction: Reproduction object for evolino
            :key burstMutation: BurstMutation object for evolino
            :key evaluation: Evaluation object for evolino
            :key verbosity: verbosity level
        """
        Trainer.__init__(self, evolino_network)

        self.network = evolino_network
        self.setData(dataset)

        ap = KWArgsProcessor(self, kwargs)

        # misc
        ap.add('verbosity', default=0)

        # population
        ap.add('subPopulationSize', private=True, default=8)
        ap.add('nCombinations', private=True, default=4)
        ap.add('nParents', private=True, default=None)
        ap.add('initialWeightRange', private=True, default=(-0.1, 0.1))
        ap.add('weightInitializer', private=True, default=Randomization(self._initialWeightRange[0], self._initialWeightRange[1]))

        # mutation
        ap.add('mutationAlpha', private=True, default=0.01)
        ap.add('mutationVariate', private=True, default=CauchyVariate(0, self._mutationAlpha))

        # evaluation
        ap.add('wtRatio', private=True, default=(1, 3))

        # burst mutation
        ap.add('nBurstMutationEpochs', default=Infinity)

        # network
        ap.add('backprojectionFactor', private=True, default=float(evolino_network.backprojectionFactor))
        evolino_network.backprojectionFactor = self._backprojectionFactor

        # aggregated objects
        ap.add('selection', default=EvolinoSelection())
        ap.add('reproduction', default=EvolinoReproduction(mutationVariate=self.mutationVariate))
        ap.add('burstMutation', default=EvolinoBurstMutation())
        ap.add('evaluation', default=EvolinoEvaluation(evolino_network, self.ds, **kwargs))

        self.selection.nParents = self.nParents

        self._population = EvolinoPopulation(
            EvolinoSubIndividual(evolino_network.getGenome()),
            self._subPopulationSize,
            self._nCombinations,
            self._weightInitializer
            )

        filters = []
        filters.append(self.evaluation)
        filters.append(self.selection)
        filters.append(self.reproduction)

        self._filters = filters

        self.totalepochs = 0
        self._max_fitness = self.evaluation.max_fitness
        self._max_fitness_epoch = self.totalepochs