Hard limiting / threshold activation function in TensorFlow

前端 未结 2 1344
走了就别回头了
走了就别回头了 2021-01-05 11:59

I\'m trying to implement a basic, binary Hopfield Network in TensorFlow 0.9. Unfortunately I\'m having a very hard time getting the activation function working. I\'m looking

相关标签:
2条回答
  • 2021-01-05 12:41

    a bit late, but if anyone needs it, I used this definition

    def binary_activation(x):
    
        cond = tf.less(x, tf.zeros(tf.shape(x)))
        out = tf.where(cond, tf.zeros(tf.shape(x)), tf.ones(tf.shape(x)))
    
        return out
    

    with x being a tensor

    0 讨论(0)
  • 2021-01-05 13:01

    Just for the record, one can get the sign function via tf.sign. It outputs a float or integer (depending on the input) indicating the sign with -1 or 1. However, note that tf.sign(0) == 0!

    For a hard limiting activation function, binary threshold activation function, Heaviside step function, see the other answer.

    0 讨论(0)
提交回复
热议问题