Error Implementing the Correlation Coefficient Matrix in Tensorflow -


i trying implement correlation coefficient in tensorflow according solution posted on tensorflow equivalent of np.corrcoef on specific axis. have a set of features in, in case, 100, , batch of 32. , purpose find correlation coefficient of matrix. is, correlation coefficient among 100 different features. here code:

with tf.name_scope('decorrelation_loss'):     diagonal_matrix = tf.diag(tf.ones([latent_dim]))     mean = tf.reduce_mean(latent_var, axis=0, keep_dims=true)     # compute covariance matrix. size is: [100, 100].     cov_t = (tf.transpose(latent_var - mean) @ (latent_var - mean)) / (batch_size - 1)     cov2_t = tf.diag(1 / tf.sqrt(tf.diag_part(cov_t)))     cor = cov2_t @ cov_t @ cov2_t     decorrelation_loss = tf.reduce_mean(tf.abs(tf.subtract(cor, diagonal_matrix)))     tf.summary.scalar('decor_loss', decorrelation_loss) 

finally within session have following:

np.testing.assert_allclose(np.corrcoef(np.array(latent_var_).t), cor.eval()) 

finally, after running, find there mismatch:

assertionerror:  not equal tolerance rtol=1e-07, atol=0  (mismatch 99.48%)  x: array([[ 1.      ,  0.16559 , -0.357179, ..., -0.280257,  0.300368,          0.198601],        [ 0.16559 ,  1.      ,  0.328356, ..., -0.466264,  0.601933,...  y: array([[ 1.      , -0.340174, -0.341527, ...,  0.61798 , -0.704325,          0.443919],        [-0.340174,  1.      ,  0.14862 , ..., -0.469017,  0.449724,... 

so not sure mistake in above code.

any appreciated!!


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -