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) * 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]
# the slope of the line us related to the 2X rate of transmitter count # Here there is only 1 layer, the "input" layer doesn't count # the only job the input layer is to keep track of the input size print(model.layers) print('\n') print(model.layers[0].get_weights()) # model.layers[0].get_weights() returns [w, b] = [array([[0.33895805]], dtype=float32), array([17.783209], dtype=float32)] # given that D=input size and M=output size # W.shape =(D,M) # b.shape = (M,) # here M and D are of size 1 # the slope of the line a = model.layers[0].get_weights()[0][0, 0] #%% print("Time to double:", np.og(2) / a) # If you know the analytical solution # np.array(X).shape = (162, 1) # np.array(X).flatten().shape = Return a copy of the array collapsed into one dimension = (162,) X = np.array(X).flatten() Y = np.array(Y) denominator = X.dot(X) - X.mean() * X.sum() a = (X.dot(Y) - Y.mean() * X.sum()) / denominator b = (Y.mean() * X.dot(X) - X.mean() * X.dot(Y)) / denominator print(a, b) print("Time to double:", np.log(2) / a) #%% # Making Predictions Yhat = model.predict(X).flatten() plt.scatter(X, Y)