Chris Gorman - 1 year ago 118

Python Question

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 to get the very simple

`If net[i] < 0, output[i] = 0, else output[i] = 1`

For example, I tried casting

`tf.less()`

`float`

`tf.maximum(tf.minimum(net, 0) + 1, 0)`

but I forgot about small decimal values. Finally I did

`tf.maximum(tf.floor(tf.minimum(net, 0) + 1), 0)`

but

`tf.floor`

Any suggestions on what I could do?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

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.select(cond, tf.zeros(tf.shape(x)), tf.ones(tf.shape(x)))
return out
```

with x being a tensor

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**