Plotting with Torch7
Bokeh / iTorch
Bokeh is a Python interactive visualization library that use modern web browsers to display plots. It can be highly interactive and it can plot barely everything in a pretty way. In a few words, it looks perfect.
A Bokeh wrapper is implemented in the iTorch Framework. First I was very enthusiastic since the interface is clean and Tensor are really well integrated. However, only the most basic features are wrapped. A small number of charts are available and few interaction are allowed on the plots. Maybe, I misused the library but it looks like a lot of features are hard-coded.
Nevertheless, Bokeh/iTorch is still a good alternative for beginners. The Lua interface is way more-user friendly than NVD3 or dygraph!
- Lua API : https://github.com/facebook/iTorch
- Underlying API : http://bokeh.pydata.org/en/latest/
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Plot = require ("itorch.Plot") local x = torch.linspace(-2*math.pi,2*math.pi) local y1 = torch.sin(x) local y2 = torch.cos(x):mul(0.5) local plot = Plot() plot:line(x, y1,'red' ,'Sinus Wave') plot:line(x, y2,'blue','Cosinus Wave') plot:xaxis('Time (ms)') plot:legend(true):title('Line Plot Demo') plot:gfx() -- or plot:draw() or plot:html() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
local x1 = torch.randn(40):mul(100) local y1 = torch.randn(40):mul(100) local x2 = torch.randn(40):mul(100) local y2 = torch.randn(40):mul(100) local x3 = torch.randn(40):mul(200) local y3 = torch.randn(40):mul(200) -- scatter plots local plot = Plot() plot:circle(x1,y2,'green','Group1') plot:circle(x2,y2,'red' ,'Group2') plot:circle(x3,y3,'blue' ,'Group3') plot:title('Bokeh Demo') plot:xaxis('length'):yaxis('width') plot:legend(true) plot:gfx() |
By default, you need to use either iTorch and its notebook or to save the html in a file.
Yet, by tricking a bit the API, it is possible to display the plots in a gfx server. I found this solution more user friendly
Some tricks to know:
- One cannot simply throw the baby out with the bathwater. iTorch plotting abilities are likely to evolve. Some charts are only available with bokeh such as quiver or quad.
- The redraw method is very nice to dynamically upgrade figures
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,