X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=dagnn.lua;h=92032640e9c250a8dfbc7db04871805bd2f319d2;hb=9dad4fa1118632bfa02c01e4d6a8a5a129061a54;hp=9202932da2950905fc49734c8762226e0e4d6f28;hpb=be353fdfc2a57172064a024f8cec6015c9d908e5;p=dagnn.git diff --git a/dagnn.lua b/dagnn.lua index 9202932..9203264 100755 --- a/dagnn.lua +++ b/dagnn.lua @@ -42,7 +42,7 @@ end -- The main use should be to add an edge between two modules, but it -- can also add a full sequence of modules -function DAG:addEdge(...) +function DAG:connect(...) self.sorted = nil local prev for _, nnm in pairs({...}) do @@ -261,3 +261,35 @@ function DAG:accGradParameters(input, gradOutput, scale) end ---------------------------------------------------------------------- + +function DAG:dot(filename) + local file = (filename and io.open(filename, 'w')) or io.stdout + + file:write('digraph {\n') + + file:write('\n') + + for nnma, node in pairs(self.node) do + file:write( + ' ' + .. node.index + .. ' [shape=box,label=\"' .. torch.type(nnma) .. '\"]' + .. '\n' + ) + + for _, nnmb in pairs(node.succ) do + file:write( + ' ' + .. node.index + .. ' -> ' + .. self.node[nnmb].index + .. '\n' + ) + end + + file:write('\n') + end + + file:write('}\n') + +end