import tensorflow as tf

        for state in states:
            dJr = tf.matmul(tf.nn.relu(state),
                      tf.matmul(tf.abs(self.W_rec) * self.rec_Connectivity, self.Dale_rec))
            reg += tf.reduce_sum(tf.square(dJr))

        return reg / (self.N_steps * self.N_batch)

    # train the model using Adam
    def train(self, sess, generator,
              learning_rate=.001, training_iters=50000,
              batch_size=64, display_step=10,weight_save_step=100, save_weights_path= None,
              generator_function= None, training_weights_path = None):


        # train with gradient clipping
        optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)
        grads = optimizer.compute_gradients(self.loss)
        clipped_grads = [(tf.clip_by_norm(grad, 1.0), var)
                         if grad is not None else (grad, var)
                        for grad, var in grads]

        # add vanishing gradient regularizer
        #out, test = self.dOmega_dWrec()
        #clipped_grads[0] = (tf.add(out[0], clipped_grads[0][0]), clipped_grads[0][1])
        #clipped_grads[0] = (tf.Print(clipped_grads[0][0], [clipped_grads[0][0]], "gw_rec"), clipped_grads[0][1])

        optimize = optimizer.apply_gradients(clipped_grads)

        # run session
        sess.run(tf.global_variables_initializer())
