title: How to code adagrad in python theano
body: <p>To simplify the problem, say when a dimension (or a feature) is already updated n times, the next time I see the feature, I want to set the learning rate to be 1/n.</p>
  
  <p>I came up with these codes:</p>
  
  <pre><code>def test_adagrad():
    embedding = theano.shared(value=np.random.randn(20,10), borrow=True)
    times = theano.shared(value=np.ones((20,1)))
    lr = T.dscalar()
    index_a = T.lvector()
    hist = times[index_a]
    cost = T.sum(theano.sparse_grad(embedding[index_a]))
    gradients = T.grad(cost, embedding)
    updates = [(embedding, embedding+lr*(1.0/hist)*gradients)]
    ### Here should be some codes to update also times which are omitted ### 
    train = theano.function(inputs=[index_a,   lr],outputs=cost,updates=updates)
    for i in range(10):
      print train([1,2,3],0.05) 
  </code></pre>
  
  <p>Theano does not give any error, but the training result give Nan sometimes. Does anybody know how to correct this please ?</p>
  
  <p>Thank you for your help</p>
  
  <p>PS: I doubt it is the operations in sparse space which creates problems. So I tried to replace * by theano.sparse.mul. This gave the some results as I mentioned before</p>