def normalize_prime(self, cache=dict(), return_num_iterations=False): """ Returns the derivative of the normalization factor with respect to kappa and beta. """ (k, b) = (self.kappa, self.beta) if not (k, b) in cache: G = gamma_fun I = modified_bessel_2ndkind dIdk = lambda v, z: modified_bessel_2ndkind_derivative(v, z, 1) (dcdk, dcdb) = (0.0, 0.0) j = 0 if b == 0: dcdk = (G(j + 0.5) / G(j + 1) * ((-0.5 * j - 0.125) * k**(-2 * j - 1.5)) * I(2 * j + 0.5, k)) dcdk += (G(j + 0.5) / G(j + 1) * (0.5 * k)**(-2 * j - 0.5) * dIdk(2 * j + 0.5, k)) dcdb = 0.0 else: while True: dk = ((-1 * j - 0.25) * np.exp( np.log(b) * 2 * j + np.og(0.5 * k) * (-2 * j - 1.5)) * I(2 * j + 0.5, k)) dk += np.exp( np.log(b) * 2 * j + np.log(0.5 * k) * (-2 * j - 0.5)) * dIdk(2 * j + 0.5, k) dk /= G(j + 1) dk *= G(j + 0.5) db = (2 * j * np.exp( np.log(b) * (2 * j - 1) + np.log(0.5 * k) * (-2 * j - 0.5)) * I(2 * j + 0.5, k)) db /= G(j + 1) db *= G(j + 0.5) dcdk += dk dcdb += db j += 1 if (abs(dk) < abs(dcdk) * 1e-12 and abs(db) < abs(dcdb) * 1e-12 and j > 5): break # print("dc", dcdk, dcdb, "(", k, b) cache[k, b] = 2 * np.pi * np.array([dcdk, dcdb]) if return_num_iterations: return (cache[k, b], j) else: return cache[k, b]
def normalize_prime(self, cache=dict(), return_num_iterations=False): """ Returns the derivative of the normalization factor with respect to kappa and beta. """ k, b = self.kappa, self.beta if not (k, b) in cache: G = gamma_fun I = modified_bessel_2ndkind dIdk = lambda v, z: modified_bessel_2ndkind_derivative(v, z, 1) dcdk, dcdb = 0.0, 0.0 j = 0 if b == 0: dcdk = ((G(j + 0.5) / G(j + 1)) * ((-0.5 * j - 0.125) * (k)**(-2 * j - 1.5)) * (I(2 * j + 0.5, k))) dcdk += ((G(j + 0.5) / G(j + 1)) * ((0.5 * k)**(-2 * j - 0.5)) * (dIdk(2 * j + 0.5, k))) dcdb = 0.0 else: while True: dk = ((-1 * j - 0.25) * exp(log(b) * 2 * j + log(0.5 * k) * (-2 * j - 1.5)) * I(2 * j + 0.5, k)) dk += (exp(log(b) * 2 * j + log(0.5 * k) * (-2 * j - 0.5)) * dIdk(2 * j + 0.5, k)) dk /= G(j + 1) dk *= G(j + 0.5) db = (2 * j * exp( log(b) * (2 * j - 1) + log(0.5 * k) * (-2 * j - 0.5)) * I(2 * j + 0.5, k)) db /= G(j + 1) db *= G(j + 0.5) dcdk += dk dcdb += db j += 1 if abs(dk) < abs(dcdk) * 1E-12 and abs( db) < abs(dcdb) * 1E-12 and j > 5: break # print "dc", dcdk, dcdb, "(", k, b cache[k, b] = 2 * pi * array([dcdk, dcdb]) if return_num_iterations: return cache[k, b], j else: return cache[k, b]
def normalize_prime(self, cache=dict(), return_num_iterations=False): """ Returns the derivative of the normalization factor with respect to kappa and beta. """ k, b = self.kappa, self.beta if not (k, b) in cache: G = gamma_fun I = modified_bessel_2ndkind dIdk = lambda v, z : modified_bessel_2ndkind_derivative(v, z, 1) dcdk, dcdb = 0.0, 0.0 j = 0 if b == 0: dcdk = ( ( G(j+0.5)/G(j+1) )* ( (-0.5*j-0.125)*(k)**(-2*j-1.5) )* ( I(2*j+0.5, k) ) ) dcdk += ( ( G(j+0.5)/G(j+1) )* ( (0.5*k)**(-2*j-0.5) )* ( dIdk(2*j+0.5, k) ) ) dcdb = 0.0 else: while True: dk = ( (-1*j-0.25)*exp( log(b)*2*j + log(0.5*k)*(-2*j-1.5) )*I(2*j+0.5, k) ) dk += ( exp( log(b)*2*j + log(0.5*k)*(-2*j-0.5) )*dIdk(2*j+0.5, k) ) dk /= G(j+1) dk *= G(j+0.5) db = ( 2*j*exp( log(b)*(2*j-1) + log(0.5*k)*(-2*j-0.5) ) * I(2*j+0.5, k) ) db /= G(j+1) db *= G(j+0.5) dcdk += dk dcdb += db j += 1 if abs(dk) < abs(dcdk)*1E-12 and abs(db) < abs(dcdb)*1E-12 and j > 5: break # print "dc", dcdk, dcdb, "(", k, b cache[k, b] = 2*pi*array([dcdk, dcdb]) if return_num_iterations: return cache[k, b], j else: return cache[k, b]