def test_fit_complex(self): log = logging.getLogger('TestFitZern.test_fit_complex') z = CZern(4) F = FitZern(z, self.L, self.K) theta_i = F.theta_i rho_j = F.rho_j c = normal(size=z.nk) + 1j*normal(size=z.nk) time1 = time() Phi = [z.eval_a(c, rh, th) for rh in rho_j for th in theta_i] time2 = time() log.debug('eval Phi {:.4f}'.format(time2 - time1)) time1 = time() ce = F._fit_slow(Phi) time2 = time() log.debug('elapsed time {:.4f}'.format(time2 - time1)) err1 = np.sqrt(sum([abs(c[i] - ce[i])**2 for i in range(z.nk)])) max1 = max([abs(c[i] - ce[i]) for i in range(z.nk)]) log.debug('err1 {:e} max1 {:e} max {:e}'.format( err1, max1, self.max_fit_norm)) self.assertTrue(err1 < self.max_fit_norm)
def test_fit_complex_numpy(self): log = logging.getLogger('TestFitZern.test_fit_complex_numpy') z = CZern(4) F = FitZern(z, self.L, self.K) theta_i = F.theta_i rho_j = F.rho_j c = normal(size=z.nk) + 1j*normal(size=z.nk) Phi = [z.eval_a(c, rh, th) for rh in rho_j for th in theta_i] time1 = time() ce = F._fit_slow(Phi) time2 = time() log.debug('elapsed FIT_LIST {:.6f}'.format(time2 - time1)) PhiN = np.array(Phi, order='F') time1 = time() ce2 = F.fit(PhiN) time2 = time() log.debug('elapsed FIT_NUMPY {:.6f}'.format(time2 - time1)) enorm = norm(ce2 - np.array(ce, order='F')) log.debug('enorm {:e}'.format(enorm)) self.assertTrue(enorm < self.max_enorm)
def test_normalisations_complex(self): log = logging.getLogger('TestZern.test_normalisations_complex') n_beta = 6 L, K = 400, 393 # polar grid pol = CZern(n_beta) fitBeta = FitZern(pol, L, K) t1 = time() pol.make_pol_grid(fitBeta.rho_j, fitBeta.theta_i) t2 = time() log.debug('make pol grid {:.6f}'.format(t2 - t1)) # cartesian grid cart = CZern(n_beta) dd = np.linspace(-1.0, 1.0, max(L, K)) xx, yy = np.meshgrid(dd, dd) t1 = time() cart.make_cart_grid(xx, yy) t2 = time() log.debug('make cart grid {:.6f}'.format(t2 - t1)) smap = np.isfinite(cart.eval_grid(np.zeros(cart.nk))) scale = (1.0/np.sum(smap)) log.debug('') log.debug('{} modes, {} x {} grid'.format(n_beta, L, K)) for i in range(pol.nk): a = np.zeros(pol.nk) a[i] = 1.0 Phi_a = cart.eval_grid(a) for j in range(pol.nk): b = np.zeros(pol.nk) b[j] = 1.0 Phi_b = cart.eval_grid(b) ip = scale*np.sum(Phi_a[smap]*(Phi_b[smap].conj())) if i == j: eip = 1.0 else: eip = 0.0 iperr = abs(ip - eip) log.debug('<{:02},{:02}> = {:+e} {:+e}'.format( i + 1, j + 1, ip, iperr)) self.assertTrue(iperr < self.max_ip_err)