applecider
applecider

Reputation: 2471

Theano ~ most efficient way to flatten then build back a matrix?

I am trying to compute the hessian on a neural network using theano.

However, I cannot compute the hessian on my loss function with respect to a weight matrix W. The hessian needs to be computed with respect to a vector v.

So, a way around this is to flatten the weight matrix into a vector, then compute the hessian, etc.

Once I am done updating my weight matrix in flattened form, I need to rebuild my weight matrix with the original dimensions, say m x n

What is the most efficient way to do this using theano syntax?

Upvotes: 0

Views: 760

Answers (1)

Joe Munoz
Joe Munoz

Reputation: 21

It sounds like your looking for "reshape", like @Pushkin mentioned.

You can use reshape in Theano just like Numpy, but it's with their custom tensor object.

  1. Save weight matrix shape to variable.
  2. Flatten and compute.
  3. Call reshape with the previously saved shape variable.

"Theano - Reshape Tensor"

Upvotes: 2

Related Questions