(self, fitness_values, es=None, more_data=[], modulo=None)
append some logging data from `CMAEvolutionStrategy` class instance `es`,
        if ``number_of_times_called % modulo`` equals to zero, never if ``modulo==0``.

        The sequence ``more_data`` must always have the same length.
append some logging data from `CMAEvolutionStrategy` class instance `es`,
        if ``number_of_times_called % modulo`` equals to zero, never if ``modulo==0``.
append some logging data from CMAEvolutionStrategy class instance es if number_of_times_called % modulo equals to zero never if modulo == 0 .
def add(self, fitness_values, es=None, more_data=[], modulo=None): # TODO: find a different way to communicate current x and f
        """append some logging data from `CMAEvolutionStrategy` class instance `es`,
        if ``number_of_times_called % modulo`` equals to zero, never if ``modulo==0``.

        The sequence ``more_data`` must always have the same length.

        """
        self.counter += 1
        fitness_values = np.sort(fitness_values)
        if fitness_values[0] < self.best_fitness:
            self.best_fitness = fitness_values[0]
        mod = modulo if modulo is not None else self.modulo
        if mod == 0 or (self.counter > 3 and self.counter % mod):
            return
        if es is None:
            try:
                es = self.es  # must have been registered
            except AttributeError :
                raise _Error('call register() before add() or add(es)')
        elif not self.registered:
            self.register(es)

        if 11 < 3:
            try: # TODO: find a more decent interface to store and pass recent_x
                xrecent = es.best.last.x
            except:
                if self.counter == 2:  # by now a recent_x should be available
                    print('WARNING: es.out[\'recent_x\'] not found in CMADataLogger.add, count='
                          + str(self.counter))
        try:
            # fit
            if es.update_count > 0:
                # fit = es.fit.fit[0]  # TODO: where do we get the fitness from?
                fn = self.name_prefix + 'fit.dat'
                with open(fn, 'a') as f:
                    f.write(str(es.update_count) + ' '
                            + str(es.update_count * es.lambda_) + ' '
                            + str(es.sigma) + ' '
                            + str(es.diagD[-1]/es.diagD[0]) + ' '
                            + str(self.best_fitness) + ' '
                            + '%.16e' % fitness_values[0] + ' '
                            + str(fitness_values[es.lambda_//2]) + ' '
                            + str(fitness_values[-1]) + ' '
                            # + str(es.sp.popsize) + ' '
                            # + str(10**es.noiseS) + ' '
                            # + str(es.sp.cmean) + ' '
                            # + ' '.join(str(i) for i in es.more_to_write)
                            + ' '.join(str(i) for i in more_data)
                            + '\n')
                    # es.more_to_write = []
            # axlen
            fn = self.name_prefix + 'axlen.dat'
            with open(fn, 'a') as f:  # does not rely on reference counting
                f.write(str(es.update_count) + ' '
                        + str(es.update_count * es.lambda_) + ' '
                        + str(es.sigma) + ' '
                        + str(es.diagD[-1]) + ' '
                        + str(es.diagD[0]) + ' '
                        + ' '.join(map(str, es.diagD))
                        + '\n')
            # stddev
            fn = self.name_prefix + 'stddev.dat'
            with open(fn, 'a') as f:
                f.write(str(es.update_count) + ' '
                        + str(es.update_count * es.lambda_) + ' '
                        + str(es.sigma) + ' '
                        + '0 0 '
                        + ' '.join(map(str, es.sigma*np.sqrt([es.C[i][i] for i in xrange(es.dim)])))
                        + '\n')
            # xmean
            fn = self.name_prefix + 'xmean.dat'
            with open(fn, 'a') as f:
                if es.update_count < 1:
                    f.write('0 0 0 0 0 '
                            + ' '.join(map(str,
                                              # TODO should be optional the phenotyp?
                                              # es.gp.geno(es.x0)
                                              es.mean))
                            + '\n')
                else:
                    f.write(str(es.update_count) + ' '
                            + str(es.update_count * es.lambda_) + ' '
                            # + str(es.sigma) + ' '
                            + '0 0 0 '
                            # + str(es.fmean_noise_free) + ' '
                            # + str(es.fmean) + ' '  # TODO: this does not make sense
                            # TODO should be optional the phenotyp?
                            + ' '.join(map(str, es.centroid))
                            + '\n')
            # xrecent
            if 11 < 3:
                fn = self.name_prefix + 'xrecentbest.dat'
                if es.countiter > 0 and xrecent is not None:
                    with open(fn, 'a') as f:
                        f.write(str(es.countiter) + ' '
                                + str(es.countevals) + ' '
                                + str(es.sigma) + ' '
                                + '0 '
                                + str(es.fit.fit[0]) + ' '
                                + ' '.join(map(str, xrecent))
                                + '\n')

        except (IOError, OSError):
            if es.countiter == 1:
                print('could not open/write file')
def add ( self , fitness_values , es = None , more_data = [ ] , modulo = None ) : # TODO: find a different way to communicate current x and f self . counter += 1 fitness_values = np . sort ( fitness_values ) if fitness_values [ 0 ] < self . best_fitness : self . best_fitness = fitness_values [ 0 ] mod = modulo if modulo is not None else self . modulo if mod == 0 or ( self . counter > 3 and self . counter % mod ) : return if es is None : try : es = self . es # must have been registered except AttributeError : raise _Error ( 'call register() before add() or add(es)' ) elif not self . registered : self . register ( es ) if 11 < 3 : try : # TODO: find a more decent interface to store and pass recent_x xrecent = es . best . last . x except : if self . counter == 2 : # by now a recent_x should be available print ( 'WARNING: es.out[\'recent_x\'] not found in CMADataLogger.add, count=' + str ( self . counter ) ) try : # fit if es . update_count > 0 : # fit = es.fit.fit[0]  # TODO: where do we get the fitness from? fn = self . name_prefix + 'fit.dat' with open ( fn , 'a' ) as f : f . write ( str ( es . update_count ) + ' ' + str ( es . update_count * es . lambda_ ) + ' ' + str ( es . sigma ) + ' ' + str ( es . diagD [ - 1 ] / es . diagD [ 0 ] ) + ' ' + str ( self . best_fitness ) + ' ' + '%.16e' % fitness_values [ 0 ] + ' ' + str ( fitness_values [ es . lambda_ // 2 ] ) + ' ' + str ( fitness_values [ - 1 ] ) + ' ' # + str(es.sp.popsize) + ' ' # + str(10**es.noiseS) + ' ' # + str(es.sp.cmean) + ' ' # + ' '.join(str(i) for i in es.more_to_write) + ' ' . join ( str ( i ) for i in more_data ) + '\n' ) # es.more_to_write = [] # axlen fn = self . name_prefix + 'axlen.dat' with open ( fn , 'a' ) as f : # does not rely on reference counting f . write ( str ( es . update_count ) + ' ' + str ( es . update_count * es . lambda_ ) + ' ' + str ( es . sigma ) + ' ' + str ( es . diagD [ - 1 ] ) + ' ' + str ( es . diagD [ 0 ] ) + ' ' + ' ' . join ( map ( str , es . diagD ) ) + '\n' ) # stddev fn = self . name_prefix + 'stddev.dat' with open ( fn , 'a' ) as f : f . write ( str ( es . update_count ) + ' ' + str ( es . update_count * es . lambda_ ) + ' ' + str ( es . sigma ) + ' ' + '0 0 ' + ' ' . join ( map ( str , es . sigma * np . sqrt ( [ es . C [ i ] [ i ] for i in xrange ( es . dim ) ] ) ) ) + '\n' ) # xmean fn = self . name_prefix + 'xmean.dat' with open ( fn , 'a' ) as f : if es . update_count < 1 : f . write ( '0 0 0 0 0 ' + ' ' . join ( map ( str , # TODO should be optional the phenotyp? # es.gp.geno(es.x0) es . mean ) ) + '\n' ) else : f . write ( str ( es . update_count ) + ' ' + str ( es . update_count * es . lambda_ ) + ' ' # + str(es.sigma) + ' ' + '0 0 0 ' # + str(es.fmean_noise_free) + ' ' # + str(es.fmean) + ' '  # TODO: this does not make sense # TODO should be optional the phenotyp? + ' ' . join ( map ( str , es . centroid ) ) + '\n' ) # xrecent if 11 < 3 : fn = self . name_prefix + 'xrecentbest.dat' if es . countiter > 0 and xrecent is not None : with open ( fn , 'a' ) as f : f . write ( str ( es . countiter ) + ' ' + str ( es . countevals ) + ' ' + str ( es . sigma ) + ' ' + '0 ' + str ( es . fit . fit [ 0 ] ) + ' ' + ' ' . join ( map ( str , xrecent ) ) + '\n' ) except ( IOError , OSError ) : if es . countiter == 1 : print ( 'could not open/write file' )