In [1]:

    import numpy
    import theano as th
    import theano.tensor as T
    import theano.printing as pr
    import theano.d3printing as d3p

    Couldn't import dot_parser, loading of dot files will not be possible.

In [2]:

    %load_ext autoreload
    %autoreload 2

In [3]:

    x, y, z = T.scalars('xyz')
    a = x + y + z
    p = T.nnet.sigmoid(a**2)
    op = th.OpFromGraph([x, y, z], [p])

    comp = op(x, y, z) + op(z, y, x)
    comp_fun = th.function([x, y, z], [comp])

# OpFromGraph¶

In [4]:

    comp_fun(1, 2, 3)

Out[4]:

    [array(2.0)]

In [5]:

    pr.pydotprint(comp_fun, outfile='comp_fun.png', var_with_name_simple=True)
    d3p.d3write(comp_fun, 'comp_fun.dot')

    The output file is available at comp_fun.png

# Idea¶

Clicking on one of OpFromGraph nodes will open the following sub-graph:

In [6]:

    pr.pydotprint(p, outfile='p.png', var_with_name_simple=True)
    d3p.d3write(p, 'p.dot')

    The output file is available at p.png