title: Gradients of Logical Operators in Tensorflow
body: <p>I'm trying to create a very simple binary classifier in Tensorflow on generated data.</p>
  
  <p>I'm generating random data from two separate normal distributions.  Then I will classify the resulting data to a binary class if it it less than or greater than a number, A.</p>
  
  <p>Ideally, A will be a cutoff in the middle of both normals.  E.g. if my data is generated by N(1,1) + N(-1,1), then A should be approximately 0.</p>
  
  <p>I'm runnning into a "No gradients provided for any variable..." error. Specifically:</p>
  
  <pre><code>No gradients provided for any variable: ((None, &lt;tensorflow.python.ops.variables.Variable object at 0x7fd9e3fae710&gt;),)
  </code></pre>
  
  <p>I think it may have to do with the fact that Tensorflow cannot calculate gradients for logical operators.  My classification for any given A value is supposed to be something like:</p>
  
  <p>Given a data point x and an A value:</p>
  
  <p>[1,0] : if x &lt; A</p>
  
  <p>[0,1] : if x >= A</p>
  
  <p>Given that idea, here is my calculation in Tensorflow for the output:</p>
  
  <pre><code>my_output = tf.concat(0,[tf.to_float(tf.less(x_data, A)), tf.to_float(tf.greater_equal(x_data, A))])
  </code></pre>
  
  <p>Is this the wrong way to implement this output?  Is there a non-logical functional equivalent?</p>
  
  <p>Thanks.  If you want to see my whole code, here is a gist:
  <a href="https://gist.github.com/nfmcclure/46c323f0a55ae1628808f7a58b5d437f" rel="nofollow">https://gist.github.com/nfmcclure/46c323f0a55ae1628808f7a58b5d437f</a></p>
  
  <hr>
  
  <p><strong>Edit</strong>:
  Full Stack Trace:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-182-f8837927493d&gt;", line 1, in &lt;module&gt;
      runfile('/.../back_propagation.py', wdir='/')
  
    File "/usr/local/lib/python3.4/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
  execfile(filename, namespace)
  
    File "/usr/local/lib/python3.4/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile
  exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
  
    File "/.../back_propagation.py", line 94, in &lt;module&gt;
  train_step = my_opt.minimize(xentropy)
  
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/training/optimizer.py", line 192, in minimize
  name=name)
  
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/training/optimizer.py", line 286, in apply_gradients
  (grads_and_vars,))
  
  ValueError: No gradients provided for any variable: ((None, &lt;tensorflow.python.ops.variables.Variable object at 0x7fd9e3fae710&gt;),)
  </code></pre>