def repelling_regularizer(bottleneck):
"""
pulling away, repelling regularizer.
bottleneck:
the bottlenect layer in the autoencoder.
"""
s = tf.contrib.layers.flatten(bottleneck)
n = tf.cast(tf.shape(s)[0], tf.float32)
sxst = tf.matmul(s, s, transpose_b=True)
sn = tf.norm(s, 1, axis=1, keep_dims=True)
snxsnt = tf.matmul(sn, sn, transpose_b=True)
total = tf.square(sxst / snxsnt)
total = tf.reduce_sum(total)
return 0.1 * (total - n) / (n * (n - 1.0))
评论列表
文章目录