def gradcheck(model, times=None, *args):
    param = model.paramVec()
    if (times == None or times > len(param)): times = len(param)
    ind = sample(xrange(len(param)), times)
    epsilon = 1e-4

    print "Iter\tIndex\tNumGrad\t\tGrad\t\tDiff"

    for time in range(times):
        index = ind[time]
        _,grad = model.costAndGradVec(param,*args)
        grad = grad[index]

        param_p = np.array(param)
        param_p[index] += epsilon
        cost_p,_ = model.costAndGradVec(param_p,*args)

        param_m = np.array(param)
        param_m[index] -= epsilon
        cost_m,_ = model.costAndGradVec(param_m,*args)

        numgrad = (cost_p - cost_m) / epsilon / 2

        diff = abs(numgrad - grad)

        print "%d\t%d\t%1.5e\t%1.5e\t%1.5e" % (time+1,index,numgrad,grad,diff)

        if (diff > 1e-4):
            print ("GradCheck failed, returning early. Check the last line of output for details.")
            return
Fetches a dictionary of valid entities for a list of references.
dataset/ETHPy150Open amaas/stanford-ctc/ctc/gradcheck.py/gradcheck--crossover with--dataset/ETHPy150Open AppScale/appscale/AppDB/groomer.py/DatastoreGroomer.fetch_entity_dict_for_references