Initial commit.
[dagnn.git] / README.md
1
2 This package implements a new module nn.DAG which inherits from nn.Container and allows to combine modules in an arbitrary graph without cycle.
3
4 #Example#
5
6 The typical use is:
7
8 ```Lua
9 model = nn.DAG()
10
11 a = nn.Linear(100, 10)
12 b = nn.ReLU()
13 c = nn.Linear(10, 15)
14 d = nn.Linear(10, 15)
15 e = nn.CMulTable()
16 f = nn.Linear(15, 15)
17
18 model:addEdge(a, b)
19 model:addEdge(b, c)
20 model:addEdge(b, d)
21 model:addEdge(c, e)
22 model:addEdge(d, e)
23 model:addEdge(d, f)
24
25 model:setInput(a)
26 model:setOutput({ e, f })
27
28 input = torch.Tensor(300, 100):uniform()
29 output = model:updateOutput(input):clone()
30
31 ```
32
33 which would encode the following graph
34
35                        +--> c ----> e -->
36                       /            /
37                      /            /
38     input --> a --> b ----> d ---+          output
39                              \
40                               \
41                                +--> f -->
42
43 #Input and output#
44
45 If a node has a single successor, its output is sent unchanged as input to that successor. If it has multiple successors, the outputs are collected into a table, and the table is used as input to the successor node. The indexes of the outputs in that table reflects the order in which they appear in the addEdge commands.
46
47 The expected input (respectively the produced output) is a nested table of inputs reflecting the structure of the nested table of modules provided to DAG:setInput (respectively DAG:setOutput)
48
49 So for instance, in the example above, the DAG expects a tensor as input, since it is the input to the module a, and its output will is a table composed of two tensors, corresponding to the outputs of e and f respectively.
50
51 *Francois Fleuret, Jan 12th, 2017*