title: Implementing the Square Non-linearity (SQNL) activation function in Keras
body: <p>I have been trying to implement the square non-linearity activation function function as a custom activation function for a keras model. It's the 10'th function on this list <a href="https://en.wikipedia.org/wiki/Activation_function" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Activation_function</a>. </p>
  
  <p>I tried using the keras backend but i got nowhere with the multiple if else statements i require so i also tried using the following:</p>
  
  <pre class="lang-py prettyprint-override"><code>import tensorflow as tf
  def square_nonlin(x):
      orig = x
      x = tf.where(orig &gt;2.0, (tf.ones_like(x)) , x)
      x = tf.where(0.0 &lt;= orig &lt;=2.0, (x - tf.math.square(x)/4), x)
      x = tf.where(-2.0 &lt;= orig &lt; 0, (x + tf.math.square(x)/4), x)
      return tf.where(orig &lt; -2.0, -1, x)
  </code></pre>
  
  <p>As you can see there's 4 different clauses i need to evaluate. But when i try to compile the Keras model i still get the error:</p>
  
  <pre class="lang-py prettyprint-override"><code>Using a `tf.Tensor` as a Python `bool` is not allowed
  </code></pre>
  
  <p>Could anyone help me to get this working in Keras? Thanks a lot. </p>