Discussion:
[theano-users] derivative of function based on eigenvalues in theano
Frédéric Bastien
2017-08-10 13:11:23 UTC
Permalink
The problem is smat(x)

It return list of list of Theano variable. This isn't a Theano variable
itself. You can have Theano contact all of this correctly to make a new
corresponding Theano variable with:

v,w=nlin.eigh(theano.tensor.stacklists(smat(x)))

Fred

On Tue, Aug 1, 2017 at 7:37 AM Jyotiranjan Beuria <
Hi All,
I am trying to calculate the derivative of a function that
depends on eigenvalues of a matrix. I am new to Theano.
Here is a snippet of the code.
import numpy as np
import theano
import theano.tensor as T
import theano.tensor.nlinalg as nlin
s=T.dmatrix('s')
x=T.dvector('x')
a=T.dscalar('a')
return [[x[0]**2,x[1],x[2]],
[x[1]**2,a*x[1],a*X[0]],
[x[2]**2,x[0],a*x[1]]]
v,w=nlin.eigh(smat(x))
TG=T.grad(v,x)
Eigen,Grad = theano.function([x], [v,TG],allow_input_downcast=True )
ev=Eigen(X)
der=Grad(X)
print ev,der
myFun([2,3,5])
Can anyone help me to solve this problem?
Regards,
Jyotiranjan
--
---
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
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 theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jyotiranjan Beuria
2017-08-10 14:08:56 UTC
Permalink
Thanks, Fred.

On Thu, Aug 10, 2017 at 6:41 PM, Frédéric Bastien <
Post by Frédéric Bastien
The problem is smat(x)
It return list of list of Theano variable. This isn't a Theano variable
itself. You can have Theano contact all of this correctly to make a new
v,w=nlin.eigh(theano.tensor.stacklists(smat(x)))
Fred
On Tue, Aug 1, 2017 at 7:37 AM Jyotiranjan Beuria <
Hi All,
I am trying to calculate the derivative of a function that
depends on eigenvalues of a matrix. I am new to Theano.
Here is a snippet of the code.
import numpy as np
import theano
import theano.tensor as T
import theano.tensor.nlinalg as nlin
s=T.dmatrix('s')
x=T.dvector('x')
a=T.dscalar('a')
return [[x[0]**2,x[1],x[2]],
[x[1]**2,a*x[1],a*X[0]],
[x[2]**2,x[0],a*x[1]]]
v,w=nlin.eigh(smat(x))
TG=T.grad(v,x)
Eigen,Grad = theano.function([x], [v,TG],allow_input_downcast=True )
ev=Eigen(X)
der=Grad(X)
print ev,der
myFun([2,3,5])
Can anyone help me to solve this problem?
Regards,
Jyotiranjan
--
---
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
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the
Google Groups "theano-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/theano-users/2FKrpaS4Q7Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
--
Jyotiranjan Beuria
Ph.D Student, HRI Allahabad
--
---
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 theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jyotiranjan Beuria
2017-08-12 08:59:00 UTC
Permalink
I further tried to calculate Hessian by

import numpy as np
import theano
import theano.tensor as T
import theano.tensor.nlinalg as nlin

s=T.dmatrix('s')
x=T.dvector('x')
a=T.dscalar('a')
def smat(x,a):
return [[x[0]**2,x[1],x[2]],
[x[1]**2,a*x[1],a*x[0]],
[x[2]**2,x[0],a*x[1]]]
s=smat(x,a)
v,w=nlin.eigh(T.stacklists(smat(x,a)))

TH,updates = theano.scan(lambda i: T.hessian(v[i], x),
sequences=T.arange(v.shape[0]))
Hes = theano.function([x,a], TH,updates=updates)

It does not work. Can anyone help?
--
---
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 theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jesse Livezey
2017-08-14 23:42:18 UTC
Permalink
Can you post the error?
Post by Jyotiranjan Beuria
I further tried to calculate Hessian by
import numpy as np
import theano
import theano.tensor as T
import theano.tensor.nlinalg as nlin
s=T.dmatrix('s')
x=T.dvector('x')
a=T.dscalar('a')
return [[x[0]**2,x[1],x[2]],
[x[1]**2,a*x[1],a*x[0]],
[x[2]**2,x[0],a*x[1]]]
s=smat(x,a)
v,w=nlin.eigh(T.stacklists(smat(x,a)))
TH,updates = theano.scan(lambda i: T.hessian(v[i], x),
sequences=T.arange(v.shape[0]))
Hes = theano.function([x,a], TH,updates=updates)
It does not work. Can anyone help?
--
---
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 theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jyotiranjan Beuria
2017-08-15 04:57:31 UTC
Permalink
I am using theano-0.9
The error message is as follows.























































































*Traceback (most recent call last): File "test.py", line 16, in <module>
TH,updates = theano.scan(lambda i: T.hessian(v[i], x),
sequences=T.arange(v.shape[0])) File
"/Library/Python/2.7/site-packages/theano/scan_module/scan.py", line 773,
in scan condition, outputs, updates =
scan_utils.get_updates_and_outputs(fn(*args)) File "test.py", line 16, in
<lambda> TH,updates = theano.scan(lambda i: T.hessian(v[i], x),
sequences=T.arange(v.shape[0])) File
"/Library/Python/2.7/site-packages/theano/gradient.py", line 1888, in
hessian non_sequences=[expr, input]) File
"/Library/Python/2.7/site-packages/theano/scan_module/scan.py", line 773,
in scan condition, outputs, updates =
scan_utils.get_updates_and_outputs(fn(*args)) File
"/Library/Python/2.7/site-packages/theano/gradient.py", line 1886, in
<lambda> disconnected_inputs='ignore'), File
"/Library/Python/2.7/site-packages/theano/gradient.py", line 555, in grad
grad_dict, wrt, cost_name) File
"/Library/Python/2.7/site-packages/theano/gradient.py", line 1317, in
_populate_grad_dict rval = [access_grad_cache(elem) for elem in wrt]
File "/Library/Python/2.7/site-packages/theano/gradient.py", line 1272, in
access_grad_cache term = access_term_cache(node)[idx] File
"/Library/Python/2.7/site-packages/theano/gradient.py", line 967, in
access_term_cache output_grads = [access_grad_cache(var) for var in
node.outputs] File "/Library/Python/2.7/site-packages/theano/gradient.py",
line 1272, in access_grad_cache term = access_term_cache(node)[idx]
File "/Library/Python/2.7/site-packages/theano/gradient.py", line 967, in
access_term_cache output_grads = [access_grad_cache(var) for var in
node.outputs] File "/Library/Python/2.7/site-packages/theano/gradient.py",
line 1272, in access_grad_cache term = access_term_cache(node)[idx]
File "/Library/Python/2.7/site-packages/theano/gradient.py", line 967, in
access_term_cache output_grads = [access_grad_cache(var) for var in
node.outputs] File "/Library/Python/2.7/site-packages/theano/gradient.py",
line 1272, in access_grad_cache term = access_term_cache(node)[idx]
File "/Library/Python/2.7/site-packages/theano/gradient.py", line 967, in
access_term_cache output_grads = [access_grad_cache(var) for var in
node.outputs] File "/Library/Python/2.7/site-packages/theano/gradient.py",
line 1272, in access_grad_cache term = access_term_cache(node)[idx]
File "/Library/Python/2.7/site-packages/theano/gradient.py", line 967, in
access_term_cache output_grads = [access_grad_cache(var) for var in
node.outputs] File "/Library/Python/2.7/site-packages/theano/gradient.py",
line 1272, in access_grad_cache term = access_term_cache(node)[idx]
File "/Library/Python/2.7/site-packages/theano/gradient.py", line 1108, in
access_term_cache new_output_grads) File
"/Library/Python/2.7/site-packages/theano/gof/op.py", line 711, in L_op
return self.grad(inputs, output_grads)AttributeError: 'EighGrad' object has
no attribute 'grad'*
--
---
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 theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...