def compute_avg(trial_path, overall=True):
    num_trials = 0
    cum_fitness = list()
    for trial in parser.get_trial_list(trial_path):
        # Only initialize the array on the first iteration
        if not num_trials:
            cum_fitness = np.zeros((2, trial.num_generations))
        num_trials += 1

        if overall:
            for generation in trial:
                cum_fitness[0][generation.number] += generation.max_fitness
                cum_fitness[1][generation.number] += generation.ave_fitness
        else:
            for generation in trial:
                selected_fitness = [
                    i.fitness for i in generation if i.selected
                ]
                if selected_fitness:
                    cum_fitness[0][generation.number] += np.amax(
                        selected_fitness)
                    cum_fitness[1][generation.number] += np.mean(
                        selected_fitness)

    return np.divide(cum_fitness, num_trials, dtype=np.float)
def compute_avg(trial_path, overall=True):
    num_trials = 0
    cum_fitness = list()
    for trial in parser.get_trial_list(trial_path):
        # Only initialize the array on the first iteration
        if not num_trials:
            cum_fitness = np.zeros((2, trial.num_generations))
        num_trials += 1

        if overall:
            for generation in trial:
                cum_fitness[0][generation.number] += generation.max_fitness
                cum_fitness[1][generation.number] += generation.ave_fitness
        else:
            for generation in trial:
                selected_fitness = [i.fitness for i in generation if i.selected]
                if selected_fitness:
                    cum_fitness[0][generation.number] += np.amax(selected_fitness)
                    cum_fitness[1][generation.number] += np.mean(selected_fitness)

    return np.divide(cum_fitness, num_trials, dtype=np.float)
Example #3
0
def count(trial_path):
    num_trials = 0
    cum_nurturing = list()
    for trial in parser.get_trial_list(trial_path):
        if not num_trials:
            cum_nurturing = np.zeros((3, trial.num_generations))
        num_trials += 1

        pop_size = trial.config['populationSize']
        for generation in trial:
            for i in xrange(pop_size):
                a, b = generation[i], generation[i + pop_size]

                if a.light_first or b.light_first:
                    # A nurtured B
                    if b.light_first and a.switch and a <= b:
                        cum_nurturing[0][generation.number] += 1
                    # B nurtured A
                    elif a.light_first and b.switch and a >= b: 
                        cum_nurturing[0][generation.number] += 1
                    # Self care    
                    else:
                        cum_nurturing[1][generation.number] += 1

                # Self care
                elif a.switch or b.switch:
                    if (a.fitness != 0) or (b.fitness != 0):
                        cum_nurturing[1][generation.number] += 1
                    else:
                        cum_nurturing[2][generation.number] += 1

                elif (a.fitness == 0) and (b.fitness == 0):
                    cum_nurturing[2][generation.number] += 1

                else:
                    cum_nurturing[2][generation.number] += 1
                    print 'Warning Case else: {}   {}'.format(a, b)
    return cum_nurturing, num_trials