Plotting with Torch7

Dygraph / Dislay

Dygraph is a Javascript library specialized on line-plotting chart. It provides really useful interactive features while dealing with complex time series. The API interface is quite easy to use once you have understand how it works. Unfortunately, the Lua documentation is a bit poor.
The display API encode the data from Lua and send it to the server through POST requests.  This reduce the data workflow and it makes the API much easier to maintain for fewer information are hard-coded.
Display has really strict limitations. Its main drawback is that pictures cannot be saved! Furthermore, the server need to be launched to display the pictures and no cache is available. Dygraph is also limited to plot time-series figures.

dygraph

Once the dygraph format is well-understood, it is really easy to make the plots highly interactive! In the following example, plots are highlighted, it is possible to smooth/unsmooth the chart by using the small number. One can zoom/unzoom. It is far more difficult to reach this level of interactivity with NVD3.

Some tricks to know:

  • The wonderful API can be found here: http://dygraphs.com/options.html
  • Dygraph is really sensible to are ill-formatted data. In such case, it is worth to use the Javascript debugger in your browser (F12). The most common mistakes are the following:
    • The number of column in data mismatch the number of labels. Example, no X-label is defined
    • ErrorBars need an additional array
  • Dygraph is well suited to plot data during the training.
  • If you restart your server while plotting, its configuration is lost

3 Comments on “Plotting with Torch7

  1. Great,
    I would like to ask if there is a way how to compute Recall and precision from a confusion matrix and draw them if it is possible. I am facing this problem for more than a month but I could not find an answer. So, please help.

    • Sure!
      First, you can compute your confusion matrix my using the optim package: https://github.com/torch/optim/blob/master/ConfusionMatrix.lua

      Then, if you want to plot accuracy/recall upon time, Dygraph/Display is a good library

      For every steps:
      – Compute the Precision/Recall from your confusion matrix
      \text{Precision}=\frac{tp}{tp+fp} \,
      \text{Recall}=\frac{tp}{tp+fn} \,

      – Plot it !

      Lua code:

      local labels = {"epoch", 'accuracy', 'recall'}
      local data = {}

      local config =
      {
      title = "Global accuracy/recall upon time",
      labels = labels,
      ylabel = "ratio",
      }

      for t = 1, noEpoch do

      --computation
      local accuracy, recall = someFct()

      --storage
      table.insert(data, {t, accuracy, recall })

      -- display
      config.win = disp.plot(data, config)

      end

      • Hi
        Many thanks for replying but I try it many times but did not work with. Could you please give me more intuition about the code.
        Regards,

Leave a Reply

Your email address will not be published.