#encoding:UTF-8 __author__ = 'auroua' import theano_test.tensor as T from theano_test import function import theano_test import pydot print pydot.find_graphviz() x = T.dmatrix('x') y = x*2 print type(y.owner) print y.owner.op.name print len(y.owner.inputs) print type(y.owner.inputs[1].owner) #apply nodes are those that define which computations the graph does # When compiling a Theano function, what you give to the theano.function is actually a graph # (starting from the output variables you can traverse the graph up to the input variables). # While this graph structure shows how to compute the output from the input, # it also offers the possibility to improve the way this computation is carried out. a = T.vector('a') b = a+a**10 fab = function([a],b) print fab([0,1,2]) theano_test.printing.pydotprint(b, outfile="/home/auroua/symbolic_graph_unopt.png", var_with_name_simple=True) theano_test.printing.pydotprint(fab, outfile="/home/auroua/symbolic_graph_opt.png", var_with_name_simple=True)
#encoding:UTF-8 __author__ = 'auroua' import theano_test from theano_test import pp from theano_test import function import theano_test.tensor as T x = T.dscalar('x') y = x**2 gy = T.grad(y,x) f = function([x],y) print f(4) x2 = T.dmatrix('x2') s = T.sum(1/(1+T.exp(-x2))) gs = T.grad(s,x2) dlogistic = function([x2],gs) print dlogistic([[0,1],[-1,-2]]) x3 = T.dvector('x3') y3 = x3**2 J,updates = theano_test.scan(lambda i,y,x:T.grad(y[i],x),sequences=T.arange(y3.shape[0]),non_sequences=[y3,x3]) f = function([x3],J,updates=updates) print f([4,4]) x4 = T.dvector('x4') y4 = x4**2 cost = y4.sum() gy4 = T.grad(cost,x4) H,updates2 = theano_test.scan(lambda i,gy,x4:T.grad(gy[i],x4),sequences=T.arange(gy4.shape[0]),non_sequences=[gy4,x4])
__author__ = "auroua" import theano_test.tensor as T from theano_test import function from theano_test import pp x = T.dscalar("x") y = T.dscalar("y") z = x + y f = function([x, y], z) f(2, 3) z.eval({x: 16.3, y: 14.3}) print z print pp(z) xm = T.dmatrix("xm") ym = T.dmatrix("ym") zm = xm + ym f2 = function((xm, ym), zm) f2(np.array([[1, 2], [2, 3]]), np.array([[3, 4], [4, 5]])) xv = T.dvector("xv") yv = T.dvector("yv") zv = xv ** 2 + yv ** 2 + 2 * xv * yv fv = function((xv, yv), zv) print pp(zv) print fv([1, 2], [3, 4])