Issue
I want to create a symmetric matrix of n*n
and train this matrix in TensorFlow. Effectively I should only train (n+1)*n/2
parameters. How should I do this?
I saw some previous threads which suggest do the following:
X = tf.Variable(tf.random_uniform([d,d], minval=-.1, maxval=.1, dtype=tf.float64))
X_symm = 0.5 * (X + tf.transpose(X))
However, this means I have to train n*n
variables, not n*(n+1)/2
variables.
Even there is no function to achieve this, a patch of self-written code would help!
Thanks!
Solution
You can use tf.matrix_band_part(input, 0, -1)
to create an upper triangular matrix from a square one, so this code would allow you to train on n(n+1)/2
variables although it has you create n*n
:
X = tf.Variable(tf.random_uniform([d,d], minval=-.1, maxval=.1, dtype=tf.float64))
X_upper = tf.matrix_band_part(X, 0, -1)
X_symm = 0.5 * (X_upper + tf.transpose(X_upper))
Answered By - gdelab
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.