title: Using a custom layer to define connectivity in tensorflow / tflearn
body: <p>Instead of a fully connected layer, I would like to specify the connectivity between activation nodes using a matrix. For example:</p>
  
  <p>I have a 20 node layer that is connected to a 10 node layer. Using a typical fully connected layer, my <code>W</code> matrix is 20 x 10, with a <code>b</code> vector of size 10. </p>
  
  <p>My activation looks something like <code>relu(Wx + b)</code></p>
  
  <p>If I had a matrix of ones and zeros that was the same size as <code>W</code>, lets call it <code>F</code>, I could do a pairwise multiply between <code>W</code> and <code>F</code> to remove connections between my first layer (20 nodes) and my second layer (10 nodes)</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>F.shape
  # (20, 10)
  import tflearn
  import tensorflow as tf
  
  input = tflearn.input_data(shape=[None, num_input])
  
  first = tflearn.fully_connected(input, 20, activation='relu')
  # Here is where I want to use a custom function, that uses my F matrix
  # I dont want the second layer to be fully connected to the first, 
  # I want only connections that are ones (and not zeros) in F
  
  # Currently:
  second = tflearn.fully_connected(first, 10, activation='relu')
  # What I want:
  second = tflearn.custom_layer(first, my_fun)
  </code></pre>
  
  <p>Where my_fun gives me: <code>relu( (FW)X + b)</code> and <code>FW</code> is a pairwise multiplication</p>
  
  <p>How do I create this function? I cant seem to find tflearn examples on how it is done, but I also know that tflearn allows for base tensorflow functions as well</p>