# get the num_top seeds from gen_num
    new_seeds = winning_seeds[gen_num]
    # iterate through the previous generations
    score = 0.0
    for old_num in range(gen_num):
      # get the num_top seeds from old_num
      old_seeds = winning_seeds[old_num]
      # compare the old seeds to the new seeds
      raw_score = 0.0
      for new_seed in new_seeds:
        for old_seed in old_seeds:
          # new_score will range from 0 to 1
          # - new_score is the fraction of the trials that
          #   are won by new_seed
          [old_score, new_score] = mfunc.score_pair(g, \
            old_seed, new_seed, width_factor, height_factor, \
            time_factor, num_trials)
          # increment the sum raw_score
          raw_score = raw_score + new_score
      # calculate the average value of new_score over
      # the pairs of seeds in new_seeds and old_seeds
      norm_score = raw_score / (num_top * num_top)
      # adjust norm_score to range from -1 to +1
      # instead of from 0 to 1
      score = score + (2.0 * norm_score) - 1.0
    # write result to output file
    mfunc.show_message(g, analysis_handle, 
      str(gen_num) + "\t" + str(score) + "\n")
    #
  #
#
Beispiel #2
0
        # match each seed in x_sample with a random baseline seed
        # of the same dimensions -- the size of x_sample is
        # elite_size, the number of seeds in the elite pickles
        total_fitness = 0
        total_sample_size = 0
        for evolved_seed in x_sample:
            # so that the noise level here is comparable to the noise level
            # in compare_generations.py, generate the same number of random
            # seeds as there are seeds in the elite pickles
            for sample in range(num_runs * elite_size):
                # make a copy of evolved_seed and randomly shuffle the cells
                # in the new seed, so that the new randomized seed has the
                # same dimensions and the same density as evolved_seed
                random_seed = evolved_seed.shuffle()
                # compare the evolved seed to the random seed
                [random_score, evolved_score] = mfunc.score_pair(g, random_seed, \
                  evolved_seed, width_factor, height_factor, time_factor, num_trials)
                total_fitness = total_fitness + evolved_score
                total_sample_size = total_sample_size + 1
        # calculate average fitness for the run
        avg_fitness = total_fitness / total_sample_size
        # convert to formatted string
        avg_fitnesses.append("{:.4f}".format(avg_fitness))
    # write out the fitness
    tab = "\t"
    mfunc.show_message(g, analysis_handle, \
      str(i) + tab + tab.join(avg_fitnesses) + "\n")
#
# Final message.
#
mfunc.show_message(g, analysis_handle, "\nAnalysis complete.\n")
analysis_handle.close()
Beispiel #3
0
  for run in range(num_runs):
    pickle_name = sorted_pickle_names[run] # log-2018-11-19-15h-40m-05s
    # read in X
    x_name = pickle_name + "-pickle-" + str(i) + ".bin"
    x_path = pickle_dir + x_name
    x_handle = open(x_path, "rb") # rb = read binary
    x_sample = pickle.load(x_handle)
    x_handle.close()
    # get Z
    z_sample = z_pickles[run]
    # compare X with Z
    total_fitness = 0.0
    total_sample_size = 0
    for sx in x_sample:
      for sz in z_sample:
        [scorex, scorez] = mfunc.score_pair(g, sx, sz, \
          width_factor, height_factor, time_factor, num_trials)
        total_fitness = total_fitness + scorex
        total_sample_size = total_sample_size + 1
    # calculate average fitness for the run
    avg_fitness = total_fitness / total_sample_size
    # convert to formatted string
    avg_fitnesses.append("{:.4f}".format(avg_fitness)) 
  # write out the fitness
  tab = "\t"
  mfunc.show_message(g, analysis_handle, \
    str(i) + tab + tab.join(avg_fitnesses) + "\n")
#
# Final message.
#
mfunc.show_message(g, analysis_handle, "\nAnalysis complete.\n")
analysis_handle.close()
Beispiel #4
0
 # read the pattern into a seed
 designed_seed = mfunc.load_designed_seed(g, pattern_file)
 # write the x span and y span of the designed seed pattern
 designed_seed_area = designed_seed.xspan * designed_seed.yspan
 designed_seed_density = designed_seed.density()
 text_file.write("designed seed size: x = " + \
   str(designed_seed.xspan) + ", y = " + \
   str(designed_seed.yspan) + ", area = " + \
   str(designed_seed_area) + ", density = " + \
   str(designed_seed_density) + "\n")
 # compete the designed seed against the evolved seeds
 total_designed_score = 0.0
 total_evolved_score = 0.0
 for evolved_seed in evolved_seeds:
     [designed_score, evolved_score] = mfunc.score_pair(g, \
       designed_seed, evolved_seed, width_factor, height_factor, \
       time_factor, num_trials)
     total_designed_score = total_designed_score + designed_score
     total_evolved_score = total_evolved_score + evolved_score
 # write out the score for the analysis report file
 avg_designed_score = total_designed_score / num_evolved_seeds
 avg_evolved_score = total_evolved_score / num_evolved_seeds
 text_file.write("score designed = " + str(avg_designed_score) + \
   "\nscore evolved = " + str(avg_evolved_score) + "\n\n")
 #
 # write out the score for the spreadsheet file
 #
 # - from the path "...\Patterns\Life\Bounded-Grids\agar-p3.rle",
 #   we want to extract both the file name "agar-p3.rle" and
 #   the category "Bounded-Grids"
 # - "agar-p3.rle" is given by file_name
Beispiel #5
0
    x1_handle.close()
    # for each run of Algorithm 2 in generation i ...
    for run2 in range(num_runs2):
      # A1, B1, C1, D1
      long_name2 = long_names2[run2] # log-2018-11-19-15h-40m-05s
      # read in X2
      x2_long_name = long_name2 + "-pickle-" + str(i) + ".bin"
      x2_path = path2 + x2_long_name
      x2_handle = open(x2_path, "rb") # rb = read binary
      x2_sample = pickle.load(x2_handle)
      x2_handle.close()
      # for each seed in x1_sample ...
      for s1 in x1_sample:
        # for each seed in x2_sample ...
        for s2 in x2_sample:
          [score1, score2] = mfunc.score_pair(g, s1, s2, \
            width_factor, height_factor, time_factor, num_trials)
          total_fitness = total_fitness + score2
          total_sample_size = total_sample_size + 1
  #
  average_fitness = total_fitness / total_sample_size
  #
  mfunc.show_message(g, analysis_handle, \
    str(i) + "\t" + str(average_fitness) + "\n")
#
# Final message.
#
mfunc.show_message(g, analysis_handle, "\nAnalysis complete.\n")
analysis_handle.close()
#
#