Ejemplo n.º 1
0
 def plot(self,
          metrics='loss',
          symbols=None,
          interactive=True,
          format='svg'):
     """
     Plot all of the results of the experiment on a single plot.
     """
     from conx import Network
     colors = list('bgrcmyk')
     symbols = {}
     count = 0
     for (category, exp_name) in self.results:
         if category not in symbols:
             symbols[category] = colors[count % len(colors)] + '-'
             count += 1
     fig_ax = None
     for (category, exp_name) in self.results:
         if exp_name in self.cache:
             net = self.cache[exp_name]
         else:
             net = Network.load(exp_name)
         fig_ax = net.plot(metrics,
                           return_fig_ax=True,
                           fig_ax=fig_ax,
                           label=category,
                           symbols=symbols,
                           title=self.name)
     fig, ax = fig_ax
     if interactive:
         plt.show(block=False)
     else:
         from IPython.display import SVG
         bytes = io.BytesIO()
         if format == "svg":
             plt.savefig(bytes, format="svg")
             plt.close(fig)
             img_bytes = bytes.getvalue()
             return SVG(img_bytes.decode())
         elif format == "pil":
             plt.savefig(bytes, format="png")
             plt.close(fig)
             bytes.seek(0)
             pil_image = PIL.Image.open(bytes)
             return pil_image
         else:
             raise Exception("format must be 'svg' or 'pil'")