예제 #1
0
def plot_contour_base(xlim, ylim):
  fig = plot.new_figure()

  # shade illegal parameter region, a + b <= 0
  min_x, max_x = xlim
  min_y, max_y = ylim
  x_vertices = [min_x, min_x, max_x]
  lowest = min(min_y, -max_x)
  y_vertices = [-min_x, lowest, lowest]
  plt.fill(x_vertices, y_vertices, 'gray', alpha=0.3)
  plt.plot([min_x, max_x], [-min_x, lowest], color='k')

  #ppl.fill_between([min_x, max_x], [lowest, lowest], [-min_x, lowest], color='gray', alpha=0.2)

  # turn grid on
  plt.grid(b=True)

  # xticks
  plt.xticks(np.arange(0, 1.1, 0.1))

  # axes
  plt.xlim(xlim)
  plt.ylim(ylim)

  plt.xlabel(r'discount $\beta$')
  plt.ylabel(r'strength $\alpha$')

  return fig
예제 #2
0
def generate_resource_figure(test, settings, data):
  file = settings['file']
  algos = settings['algos']
  resources, format = process_resource_data(settings, data)
  resources = resources[file]

  # flatten data
  flattened = [confidence_interval(resources[algo], config.RESOURCE_ALPHA) for algo in algos]
  x = np.arange(len(algos))
  y = [z[0] for z in flattened]
  yerr = [z[1] for z in flattened]

  xticks = list(map(config.ALGO_ABBREVIATIONS.get, algos))
  colors = ppl.brewer2mpl.get_map('Set2', 'qualitative', len(algos)).mpl_colors

  if settings['style']:
    plot.set_style(settings['style'])
  plot.new_figure()
  fig, ax = plt.subplots()
  rects = ppl.bar(x, y, xticklabels=xticks, yerr=yerr, log=True, grid='y', color=colors)

  # Annotate
  for rect in rects:
    bar_x = rect.get_x() + rect.get_width()/2.
    bar_y = rect.get_height()

    label = format(bar_y)
    plt.annotate(label, xy=(bar_x, bar_y), xytext=(0, 10), textcoords='offset points',
                 horizontalalignment='center', verticalalignment='bottom')

  plt.xlabel('Compressor')
  if settings['col'] == 'runtime':
    plt.ylabel(r'Runtime (\si{\second})')
  elif settings['col'] == 'memory':
    plt.ylabel(r'Memory (\si{\byte})')
    ax.set_yscale('log', basey=2) # units are in powers of two, so scale should be as well

    # hack to make labels fit
    ymin, ymax = plt.ylim()
    plt.ylim((ymin, ymax*2))

  plot.save_figure(fig, 'resources', [test])
예제 #3
0
def ppm_efficiency_by_depth_helper2(fnames, priors, depths, test_name, opts):
  test_files = list(itertools.chain(*config.PPM_EFFICIENCY_BY_DEPTH_FILESETS.values()))
  original_sizes = {f : benchmark.tasks.corpus_size(f) for f in fnames}
  work = []
  for opt, (prior, depth) in zip(opts, itertools.product(priors, depths)):
    x, fun, status = opt
    a, b = x
    work += [benchmark.tasks.my_compressor.s(test_file, paranoia, prior,
                                             ['ppm:d={0}:a={1}:b={2}'.format(depth, a, b)])
            for test_file in test_files]
  raw_res = celery.group(work)().get()

  res = {}
  for effectiveness, (prior, depth, test_file) in zip(raw_res,
                                                      itertools.product(priors, depths, test_files)):
    by_prior = res.get(prior, {})
    by_depth = by_prior.get(depth, {})
    by_depth[test_file] = effectiveness
    by_prior[depth] = by_depth
    res[prior] = by_prior

  fig = plot.new_figure()
  colors = ppl.brewer2mpl.get_map('Set2', 'qualitative', len(config.PPM_EFFICIENCY_BY_DEPTH_FILESETS)).mpl_colors
  for (name, fileset), color in zip(config.PPM_EFFICIENCY_BY_DEPTH_FILESETS.items(), colors):
    for prior in priors:
      y = []
      for d in depths:
        by_file = res[prior][d]
        mean = np.mean([by_file[f] / original_sizes[f] * 8 for f in fileset])
        y.append(mean)

      linestyle = config.PPM_EFFICIENCY_BY_DEPTH_PRIOR_LINESTYLES[prior]
      marker = config.PPM_EFFICIENCY_BY_DEPTH_PRIOR_MARKERS[prior]
      min_i = np.argmin(y)
      markevery = list(range(0, min_i)) + list(range(min_i + 1, len(depths)))
      ppl.plot(depths, y, label='{1} on {0}'.format(name, short_name(config.SHORT_PRIOR_NAME, prior)),
               color=color, linestyle=linestyle, marker=marker, markevery=markevery)

      min_depth = depths[min_i]
      min_y = y[min_i]
      ppl.plot([min_depth], [min_y], color=color, linestyle='None', marker='D')

  plt.xlabel(r'Maximal context depth $d$')
  plt.ylabel(r'Compression effectiveness (bits/byte)')

  # stretch x-axis slightly so markers are visible
  plt.xlim(min(depths) - 0.1, max(depths) + 0.1)

  ppl.legend(handlelength=4, # increase length of line segments so that linestyles can be seen
             numpoints=1 # but only show marker once
             )

  return plot.save_figure(fig, test_name, ["dummy"])