vendredi 26 juillet 2019

randomly flip elements of a Sparse Tensor representing an adjacency matrix

I have a sparse matrix named my_mat. It represents an adjacency matrix, which is symmetrical. It is a sparse tensor

print(type(my_mat))

<class 'tensorflow.python.framework.sparse_tensor.SparseTensor'>

print(my_mat)

SparseTensor(indices=Tensor("Placeholder_11:0", shape=(?, ?), dtype=int64),
values=Tensor("Placeholder_10:0", shape=(?,), dtype=float32),
dense_shape=Tensor("Placeholder_9:0", shape=(?,), dtype=int64))

I want to randomly flip 30% of its elements. For example, if the original value is 1, change it into 0; if the original value is 0, change it into 1. The new matrix should still be symmetrical, because it still should be an adjacency matrix. In addition, I do not want to flip the elements on the main diagonal.

Could you please suggest any ideas?




Aucun commentaire:

Enregistrer un commentaire