python - Why does a very small number return 'inf' instead of the real number? -
i run update of 2 variables (h1 , h2) expected give similar result 1 of them (h2) encounter runtimewarning: overflow encountered in double_scalars 35th iteration. tracked , found there part in h equation can return 1.48219693752e-323 while h2 return inf causes equation error @ iteration .
1.48219693752e-323 in range between (-1.79769313486e+308, 1.79769313486e+308). why 1 of them return inf? happened here?
extra info:
for in xrange(36): # 35 iterations k in xrange(kk): j in xrange(jj): # update auxiliary gamma = h gamma2 = h2 # update h h[k,j] = (gamma[k,j]/(2*lagrange)) * \ (( np.sqrt((sum(w[:,k]))**2 + \ (4*lagrange)*sum(v[:,j]*w[:,k]/np.dot(w[:,:],h[:,j]))) ) - \ sum(w[:,k])) h2[k,j] = (gamma2[k,j]/(2*lagrange)) * \ (( np.sqrt((sum(w[:,k]))**2 + \ ((4*lagrange/h2[k,j])*sum(gamma2[k,j]*v[:,j]*w[:,k]/np.dot(w[:,:],h2[:,j])))) ) - \ sum(w[:,k])) print h == h2 print "for h: ", it, gamma[k,j], v[:,j]*w[:,k], sum(gamma[k,j]*v[:,j]*w[:,k]) # gamma2[k,j] changes inf @ 35th iteration gamma[k,j] fine print "for h2: ", gamma2[k,j], v[:,j]*w[:,k], sum(gamma2[k,j]*v[:,j]*w[:,k]) if wonder why should give similar result because h2 has gamma2[k,j] in sum (which should pull out coefficient) , should divided h2[k,j](the term in front of sum) h2=gamma2.
Comments
Post a Comment