Hi, The error you have seem related to sympy and the code is sympy only. Do why wrote to Theano mailing list? What is the full error? If it don't contain Theano information, you should probably write to sympy mailing list.
Fred Le dim. 2 avr. 2017 03:01, Reza Mortazavi <[email protected]> a écrit : > I want to optimize x computation based on C, D, and b using sympy and > Theano. However, I have two problems: > > 1. > > I cannot replace (simplify/subs,...) C*DT by G. For instance, > C(0,0)*DT(0,0)+C(0,1)*DT(1,0)must be replaced by G(0,0), since G=C*DT. > 2. > > I cannot convert final computed x as a Theano function, since it > produces Error: > > TypeError: unhashable type: 'MutableDenseMatrix' > > My code: > > import sympyfrom sympy import * > > n, m = 2, 2 > > C = sympy.Matrix(n, m, lambda i, j: sympy.var('C%d_%d' % (i, j))) > D = sympy.Matrix(n, m, lambda i, j: sympy.var('D%d_%d' % (i, j))) > b = sympy.Matrix(n, 1, lambda i, j: sympy.var('b%d_%d' % (i, j))) > > > DT = D.transpose() > > CDT = C * DT > > G = sympy.Matrix(n, n, lambda i, j: sympy.var('G%d_%d' % (i, j))) > # does not work, no change in CDT# CDT.subs(CDT,G) > > x=sympy.Matrix(n, 1, lambda i, j:0) > F=sympy.Matrix(n, m, lambda i, j:0) > v=sympy.Matrix(m, 1, lambda i, j:0) > s=sympy.Matrix(1, n, lambda i, j:0) > y=sympy.Matrix(n, 1, lambda i, j:1) > t=sympy.Matrix(1, m, lambda i, j:0) > > w = symbols('w') > z = symbols('z') > > zeroHelper = Matrix([0]) > > z = (C.row(0)*transpose(D[0,:]))[0] > > x[0,0] = b[0,0]/z > F[0, :]=C[0, :]/z > v = transpose(D[1, :]) > y[0] = (-F[0, :]*v)[0] > s[0] = (C[1, :]*DT[:, 0])[0] > for i in range(1, n-1): > print "step: %d" % i > t=C[i, :]-s[0,0:i]*F[0:i, :] > z+=(t*v)[0] > w=b[i,0]-(s[0,0:i]*x[0:i,0])[0] > x[0:i+1,0] += w/z*y[0:i+1,0] > F[0:i+1, :]+= y[0:i+1,0]*t/z > v=DT[:, 0:i+2]*zeroHelper.col_join(y[0:i+1,0]) > y[0:i+1,0]=zeroHelper.col_join(y[0:i,0])-F[0:i+1, :]*v > s[0,0:i+1]=zeroHelper.row_join(s[0,0:i])+C[i+1, :]*DT[:, 0:i+1] > > t = C[n-1, :] - s[0, 0:n-1] * F[0:n-1, :] > z += (t * v)[0] > w = b[n-1, 0] - (s[0, 0:n-1] * x[0:n-1, 0])[0] > x[0:n , 0] += w / z * y[0:n , 0] > > x=sympy.simplify(x) > print (x) > # produces Error > func=theano_function([C,D,b],[x],dtypes={C:'float64',D:'float64',b:'float64'}) > > -- > > --- > You received this message because you are subscribed to the Google Groups > "theano-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- --- You received this message because you are subscribed to the Google Groups "theano-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
