Attachment 'make_graphs.sage'

Download

   1 """ This program collects the data produced by poly_multiply_benchmark.sage
   2 and makes it into pretty pictures.
   3 
   4 AUTHOR: David Harvey (2006-08-21)
   5 """
   6 
   7 
   8 def getInputData():
   9     """ opens and read data file, returns list of tuples
  10     (degree, coeff_bits, system, time)
  11     where degree is the polynomial degree,
  12     coeff_bits is number of bits per coefficient,
  13     system is one of the strings "ntl", "magma", "pari",
  14     time is a float showing time for the polynomial multiplication.
  15     """
  16     inputFile = file("output.txt")   # how to get command line arguments?
  17 
  18     output = []
  19     for line in inputFile:
  20         if "Doubling the PARI stack." in line:
  21             continue
  22         (degree, coeff_bits, system, time) = tuple(line.split()[0:4])
  23         degree = int(degree)
  24         coeff_bits = int(coeff_bits)
  25         system = str(system)
  26         time = float(time)
  27         output.append((degree, coeff_bits, system, time))
  28 
  29     return output
  30 
  31 
  32 def makeGraph1(input, max_diameter, max_value, positive_colour, negative_colour):
  33     """ input should be a list of tuples (x, y, z),
  34     where z is the value to plot at coordinates x, y.
  35 
  36     positive_colour and negative_colour are the colours to use for when
  37     the value is positive or negative
  38 
  39     max_value is the maximum allowable absolute z (anything above this
  40     is cropped to max_value)
  41 
  42     return graphics object
  43     """
  44     # scale data so that z is between -1 and 1:
  45     max_value = max([z for (x, y, z) in input])
  46 
  47     output = Graphics()
  48 
  49     for (x, y, z) in input:
  50         # scale and crop z:
  51         z = z / max_value
  52         if z > 1:
  53             z = 1
  54         elif z < -1:
  55             z = -1
  56         
  57         radius = sqrt(abs(z)) * max_diameter / 2
  58         if z > 0:
  59             colour = positive_colour
  60         else:
  61             colour = negative_colour
  62         output += disk((x, y), radius, 0, 360, rgbcolor=colour)
  63 
  64     return output
  65 
  66 
  67 def compareSystems(lookup, system1, system2, output_filename):
  68     colours = {"magma": (1, 0, 0), "ntl": (0, 0, 1), "pari": (0, 1, 0)}
  69     points = []
  70     for ((log_degree, log_coeff_bits), systems) in lookup.iteritems():
  71         try:
  72             if systems[system1] != 0 and systems[system2] != 0:
  73                 points.append((log_degree, log_coeff_bits, log(systems[system1]/systems[system2])))
  74         except KeyError:
  75             pass
  76 
  77     # the log(10) here means any circles representing ratios above 10 will be cropped at 10
  78     graph = makeGraph1(points, 0.12, log(10), colours[system2], colours[system1])
  79     x_values = [x for (x, y, z) in points]
  80     y_values = [y for (x, y, z) in points]
  81     print "rendering", output_filename, "..."
  82     graph.save(output_filename, xmin=min(x_values), xmax=max(x_values), ymin=min(y_values), ymax=max(y_values))
  83     
  84 
  85 # main script:
  86 
  87 inputData = getInputData()
  88 
  89 # re-organise the data in a more useful way:
  90 lookup = {}
  91 for (degree, coeff_bits, system, time) in inputData:
  92     lookup.setdefault((log(degree)/log(10), log(coeff_bits)/log(10)), {})[system] = time
  93 
  94 compareSystems(lookup, "magma", "ntl", "magma_vs_ntl.png")
  95 compareSystems(lookup, "magma", "pari", "magma_vs_pari.png")
  96 compareSystems(lookup, "pari", "ntl", "pari_vs_ntl.png")

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-03-18 07:49:09, 27.6 KB) [[attachment:magma_vs_ntl.png]]
  • [get | view] (2007-03-18 07:49:09, 39.4 KB) [[attachment:magma_vs_pari.png]]
  • [get | view] (2007-03-18 07:49:08, 3.1 KB) [[attachment:make_graphs.sage]]
  • [get | view] (2007-03-18 07:49:08, 76.4 KB) [[attachment:output.txt]]
  • [get | view] (2007-03-18 07:49:08, 31.0 KB) [[attachment:pari_vs_ntl.png]]
  • [get | view] (2007-03-18 07:49:09, 3.1 KB) [[attachment:poly_multiply_benchmark.sage]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.