David's stuff!
Drawing graphs¶
Let's define a compact way of representing directed graphs (suitable for describing neural networks) as python dictionaries. Each node has a name which should be a string, a value which can be anything and an (ordered) list of inputs representing incoming edges from other nodes. Inputs are ordered as they typically represent function args. We can alternatively provide a dict of inputs to represent named args. Here is our graph format:
Graph := {name: (value, [input])}
or
Graph := {name: (value, {input_name: input}}
Here is an example of such a Graph using both kinds of inputs:
#define some node values - just strings for now we'll use more interesting values later
A,B,C,D = 'Aa Bb Cc Dd'.split()
graph = {
'a': (A, []),
'b': (B, ['a']),
'c': (C, {'x': 'a', 'y': 'c'}),
'd': (D, ['b'])
}
It will be useful to be able to display Graphs. Here is a function that does that:
draw_graph(graph)
Exploding graphs¶
Creating Networks¶
from nbdev.export import notebook2script
notebook2script()