def test_n_eigen_circular_01(self): mseed = 2963416 ce = Circular() e_cue = ce._n_eigen_circular( seed=mseed, N=5, size=1, ensemble='CUE', set_seed=True ) e_coe = ce._n_eigen_circular( seed=mseed, N=10, size=1, ensemble='COE', set_seed=True ) e_cse = ce._n_eigen_circular( seed=mseed, N=15, size=1, ensemble='CSE', set_seed=True ) n_cue = np.imag(e_cue['c_eigen']).sum() n_coe = np.imag(e_coe['c_eigen']).sum() n_cse = np.imag(e_cse['c_eigen']).sum() self.assertTrue(n_cue-1.198459165065781 < self.epsilon) self.assertTrue(n_coe+0.068033777217730 < self.epsilon) self.assertTrue(np.abs(n_cse)< self.epsilon)
def test_unit_anti2(self): N = 4 ce = Circular() z_l = ce.unit_anti(N) z_u = ce.unit_anti(N, adir='upper') self.assertTrue(z_l[3, ].sum() + 3.0 < self.epsilon) self.assertTrue(z_u[3, ].sum() - 3.0 < self.epsilon)
def test_n_eigen_circular_02(self): mseed = 2963416 ce = Circular() e_cue = ce._n_eigen_circular( seed=mseed, N=5, size=3, ensemble='CUE', set_seed=True ) e_coe = ce._n_eigen_circular( seed=mseed, N=10, size=3, ensemble='COE', set_seed=True ) e_cse = ce._n_eigen_circular( seed=mseed, N=15, size=3, ensemble='CSE', set_seed=True ) n_cue = np.imag(e_cue['c_eigen']).sum() n_coe = np.imag(e_coe['c_eigen']).sum() n_cse = np.imag(e_cse['c_eigen']).sum() self.assertTrue(n_cue-3.595377495197345 < self.epsilon) self.assertTrue(n_coe+0.204101331653192 < self.epsilon) self.assertTrue(np.abs(n_cse) < self.epsilon)
def test_unit_anti1(self): ce = Circular() z_l = ce.unit_anti() z_u = ce.unit_anti(adir='upper') self.assertTrue((z_l[1, 0] + z_l[0, 1]) < self.epsilon) self.assertTrue((z_l[1, 0] + 1.0) < self.epsilon) self.assertTrue((z_u[0, 1] + z_u[0, 1]) < self.epsilon) self.assertTrue((z_u[0, 1] + 1.0) < self.epsilon)
def test_unit_symplectic1(self): N = 4 ce = Circular() u_l = ce.unit_symplectic(N) u_u = ce.unit_symplectic(N, adir='upper') r_l = u_l[1, 0] + u_l[3, 2] + u_l[5, 4] + u_l[7, 6] + 4.0 r_u = u_l[1, 0] + u_l[3, 2] + u_l[5, 4] + u_l[7, 6] - 4.0 self.assertTrue(r_l < self.epsilon) self.assertTrue(r_u < self.epsilon)
def test_gen_cue_01(self): ce = Circular() mseed = 2963416 Hcue0 = ce.gen_cue(8, seed=mseed, set_seed=True) Hcue1 = ce.gen_cue(8, seed=mseed, set_seed=True) n0 = float(np.imag(Hcue0[0, :].sum())) + 0.1445812268759293 n1 = float(np.real(Hcue1[6, :].sum())) - 0.0445623361854815 self.assertTrue(n0 < self.epsilon) self.assertTrue(n1 < self.epsilon)
def test_gen_coe_01(self): ce = Circular() mseed = 2963416 Hcoe0 = ce.gen_coe(8, seed=mseed, set_seed=True) Hcoe1 = ce.gen_coe(8, seed=mseed, set_seed=True) n0 = float(np.imag(Hcoe0[0, :].sum())) - 0.2712959924904533 n1 = float(np.real(Hcoe1[6, :].sum())) + 0.4453698237585775 self.assertTrue(n0 < self.epsilon) self.assertTrue(n1 < self.epsilon)
def test_gen_coe_01(self): N = 8 ce = Circular() mseed = 2963416 Hcoe0 = ce.gen_coe(8, seed=mseed, set_seed=True) Hcoe1 = ce.gen_coe(8, seed=mseed, set_seed=True) n0 = float(np.imag(Hcoe0[0, :].sum())) - 0.17970248404618488 n1 = float(np.real(Hcoe1[6, :].sum())) + 0.31684016971120316 self.assertTrue(n0 < self.epsilon) self.assertTrue(n1 < self.epsilon)
def test_gen_cse_01(self): N = 8 ce = Circular() mseed = 2963416 Hcse0 = ce.gen_cse(8, seed=mseed, set_seed=True) Hcse1 = ce.gen_cse(8, seed=mseed, set_seed=True) n0 = float(np.imag(Hcse0[0,:].sum()))-0.001106565421140888 n1 = float(np.real(Hcse1[6,:].sum()))-0.021065228262225025 self.assertTrue(n0 < self.epsilon) self.assertTrue(n1 < self.epsilon)
def test_gen_cue_01(self): N = 8 ce = Circular() mseed = 2963416 Hcue0 = ce.gen_cue(8, seed=mseed, set_seed=True) Hcue1 = ce.gen_cue(8, seed=mseed, set_seed=True) n0 = float(np.imag(Hcue0[0, :].sum())) + 0.8937685305710769 n1 = float(np.real(Hcue1[6, :].sum())) - 0.1639869102814931 self.assertTrue(n0 < self.epsilon) self.assertTrue(n1 < self.epsilon)
def test_eigen_circular_01(self): ce = Circular() mseed = 2963416 e_cue = ce.eigen_circular(5, ensemble='CUE', set_seed=True, seed=mseed) e_coe = ce.eigen_circular(10, ensemble='COE', set_seed=True, seed=mseed) e_cse = ce.eigen_circular(15, ensemble='CSE', set_seed=True, seed=mseed) n_cue = np.imag(e_cue).sum() n_coe = np.imag(e_coe).sum() n_cse = np.imag(e_cse).sum() self.assertTrue(n_cue+0.702464040915249 < self.epsilon) self.assertTrue(n_coe-0.023881520674723 < self.epsilon) self.assertTrue(np.abs(n_cse) < self.epsilon)
def test_spectral_density_01(self): N = 10 ce = Circular() mseed = 2963416 e_cue = ce.eigen_circular(N=N, ensemble='CUE', set_seed=True, seed=mseed) ergo = Ergodicity() sdensity = ergo.spectral_density(e_cue, ensemble_size=1, N=N) self.assertTrue(sdensity.shape == (31, 2)) self.assertTrue(sdensity[5:15, 1].sum() - 4.0 < self.epsilon) self.assertTrue( sdensity[15:27, 0].sum() - 12.700888156922527 < self.epsilon)
def test_eigen_circular_01(self): ce = Circular() mseed = 2963416 e_cue = ce.eigen_circular(5, ensemble='CUE', set_seed=True, seed=mseed) e_coe = ce.eigen_circular(10, ensemble='COE', set_seed=True, seed=mseed) e_cse = ce.eigen_circular(15, ensemble='CSE', set_seed=True, seed=mseed) n_cue = np.imag(e_cue).sum() n_coe = np.imag(e_coe).sum() n_cse = np.imag(e_cse).sum() self.assertTrue(n_cue - 1.198459165065781 < self.epsilon) self.assertTrue(n_coe + 0.068033777217730 < self.epsilon) self.assertTrue(np.abs(n_cse) < self.epsilon)
def test_spectral_density_01(self): ce = Circular() mseed = [123,125,124] Ns = [5, 10, 15] cSize = 2 nChunks = 3 eigen_data5 = ce.eigen_circular_ensemble( Ns[0], cSize=cSize, nchunks=nChunks, seeds=mseed, parallel=False ) eigen_data10 = ce.eigen_circular_ensemble( Ns[1], cSize=cSize, nchunks=nChunks, seeds=mseed, parallel=False ) eigen_data15 = ce.eigen_circular_ensemble( Ns[2], cSize=cSize, nchunks=nChunks, seeds=mseed, parallel=False ) ensemble_size = cSize*nChunks eigen_data = { "N5":eigen_data5, "N10":eigen_data10, "N15":eigen_data15 } ergo = Ergodicity() Dse = ergo.approach_se( Ns=Ns, ensemble_size=ensemble_size, eigen_data=eigen_data ) self.assertTrue(len(Dse) == 2) d0 = -12.287133235052062 d1 = -8.3998021593200445 self.assertTrue(Dse[0]+d0 < self.epsilon) self.assertTrue(Dse[1]+d1 < self.epsilon)
def test_test_thirumalai_mountain_01(self): ce = Circular() mseed = 2963416 # 5, 10x10 matrices from CUE N = 10 cSize = 2 nchunks = 5 ensemble_size = cSize * nchunks eseeds = [978712, 34687, 43124, 67831, 1234] e_cue = ce.eigen_circular_ensemble(N=N, ensemble='CUE', seeds=eseeds, cSize=cSize, nchunks=nchunks) c_eigen_ensemble = e_cue['c_eigen'] ergo = Ergodicity() tm = ergo.thirumalai_mountain(c_eigen_ensemble, ensemble_size, N) self.assertTrue(tm.shape == (31, )) self.assertTrue(tm[6:11].sum() - 0.104 < self.epsilon)
def test_eigen_circular_ensemble_02(self): mseeds = [2963416, 235124, 786134] ce = Circular() e_cue = ce.eigen_circular_ensemble(seeds=mseeds, N=5, nchunks=3, ensemble='CUE', parallel=True) e_coe = ce.eigen_circular_ensemble(seeds=mseeds, N=5, nchunks=3, ensemble='COE', parallel=True) e_cse = ce.eigen_circular_ensemble(seeds=mseeds, N=5, nchunks=3, ensemble='CSE', parallel=True) e_cse2 = ce.eigen_circular_ensemble(seeds=mseeds, N=5, nchunks=3, ensemble='CSE', parallel=True, adir="upper") n_cue = np.imag(e_cue['c_eigen']).sum() n_coe = np.imag(e_coe['c_eigen']).sum() n_cse = np.imag(e_cse['c_eigen']).sum() n_cse2 = np.imag(e_cse2['c_eigen']).sum() self.assertTrue(n_cue - 62.284496117511054 < self.epsilon) self.assertTrue(n_coe + 21.810798433338746 < self.epsilon) self.assertTrue(np.abs(n_cse) < self.epsilon) self.assertTrue(np.abs(n_cse2) < self.epsilon)
def test_n_eigen_circular_01(self): mseed = 2963416 ce = Circular() e_cue = ce._n_eigen_circular(seed=mseed, N=5, size=1, ensemble='CUE', set_seed=True) e_coe = ce._n_eigen_circular(seed=mseed, N=10, size=1, ensemble='COE', set_seed=True) e_cse = ce._n_eigen_circular(seed=mseed, N=15, size=1, ensemble='CSE', set_seed=True) n_cue = np.imag(e_cue['c_eigen']).sum() n_coe = np.imag(e_coe['c_eigen']).sum() n_cse = np.imag(e_cse['c_eigen']).sum() self.assertTrue(n_cue - 0.70246404091524939 < self.epsilon) self.assertTrue(n_coe - 0.02388152067472389 < self.epsilon) self.assertTrue(np.abs(n_cse) < self.epsilon)
def test_n_eigen_circular_02(self): mseed = 2963416 ce = Circular() e_cue = ce._n_eigen_circular(seed=mseed, N=5, size=3, ensemble='CUE', set_seed=True) e_coe = ce._n_eigen_circular(seed=mseed, N=10, size=3, ensemble='COE', set_seed=True) e_cse = ce._n_eigen_circular(seed=mseed, N=15, size=3, ensemble='CSE', set_seed=True) n_cue = np.imag(e_cue['c_eigen']).sum() n_coe = np.imag(e_coe['c_eigen']).sum() n_cse = np.imag(e_cse['c_eigen']).sum() self.assertTrue(n_cue + 2.1073921227457482 < self.epsilon) self.assertTrue(n_coe - 0.0716445620241715 < self.epsilon) self.assertTrue(np.abs(n_cse) < self.epsilon)
def test_eigen_circular_ensemble_02(self): mseeds = [2963416, 235124, 786134] ce = Circular() e_cue = ce.eigen_circular_ensemble( seeds=mseeds, N=5, nchunks=3, ensemble='CUE', parallel=True ) e_coe = ce.eigen_circular_ensemble( seeds=mseeds, N=5, nchunks=3, ensemble='COE', parallel=True ) e_cse = ce.eigen_circular_ensemble( seeds=mseeds, N=5, nchunks=3, ensemble='CSE', parallel=True ) e_cse2 = ce.eigen_circular_ensemble( seeds=mseeds, N=5, nchunks=3, ensemble='CSE', parallel=True, adir="upper" ) n_cue = np.imag(e_cue['c_eigen']).sum() n_coe = np.imag(e_coe['c_eigen']).sum() n_cse = np.imag(e_cse['c_eigen']).sum() n_cse2 = np.imag(e_cse2['c_eigen']).sum() self.assertTrue(n_cue-234.6608021786007 < self.epsilon) self.assertTrue(n_coe+61.25284251132706 < self.epsilon) self.assertTrue(np.abs(n_cse) < self.epsilon) self.assertTrue(np.abs(n_cse2) < self.epsilon)
def spectra_ce( range_N=[64, 128], cSize=5, nchunks=2, seeds=[997123, 1091645], ensemble='all', parallel=False, ): """ Generate eigenvalues of matrices of different size drawn from a circular ensemble. Author: M.Suzen params: range_N set of Size of the rectangular matrix, NxN. cSize Number of random matrices to generate in a chunk. nchunks number of cSize chunks. ensemble One of the circular ensemble 'CUE', 'COE', 'CSE', defaults to 'all' seeds List of integer to use in random seed in every chunk. parallel Run in multicore, number of cores as nchunks, defaults to False output: Dictionary of dictionaries. * Highest level keys for ensemble `CUE`, `COE` or `CSE`. * Then, dictionary with keys describing size, such as 'N16. * Values will be an another dictionary with keys `local_seed` integers for seeds used in the chunk, `c_eigen` numpy array of eigenvalues, `N` matrix size, `M` number of matrices used to generate `c_eigen`. Note that `c_eigen` will be length NxM. Example: """ ce = Circular() data_ce = {'CUE': {}, 'COE': {}, 'CSE': {}} for N in range_N: if (ensemble in ['CUE', 'all']): e_dict = ce.eigen_circular_ensemble(N=N, cSize=cSize, nchunks=nchunks, ensemble='CUE', seeds=seeds, parallel=parallel) data_ce['CUE']['N' + str(N)] = e_dict if (ensemble in ['COE', 'all']): e_dict = ce.eigen_circular_ensemble(N=N, cSize=cSize, nchunks=nchunks, ensemble='COE', seeds=seeds, parallel=parallel) data_ce['COE']['N' + str(N)] = e_dict if (ensemble in ['CSE', 'all']): e_dict = ce.eigen_circular_ensemble(N=N, cSize=cSize, nchunks=nchunks, ensemble='CSE', seeds=seeds, parallel=parallel) data_ce['COE']['N' + str(N)] = e_dict return data_ce
def test_unit_symplectic2(self): N = 3 ce = Circular() u_l = ce.unit_symplectic(N) u_u = ce.unit_symplectic(N, adir='upper') self.assertTrue(np.sum(u_l + u_u) < self.epsilon)
# # Generate Data for CUE, COE, CSE # N= 64, 128, 256, 512, 768, 1024 # M=40 # N matrix sizes, M number of matrices # # Output data files: # data_cue.obj, data_coe.obj and data_cse.obj # are dictionaries of dictionary # keys are : ['N64', 'N128', 'N256', 'N512', 'N768', 'N1024'] # values are dictionaries with keys: ['local_seeds', 'matrix_size', 'number_of_matrices', 'c_eigen'] # import os import pickle from bristol.ensembles import Circular ce = Circular() # seed for 4 cpu cores (or chunks if not parallel) seed_v = [997123, 1091645, 1352, 32718] data_cue = {} data_coe = {} data_cse = {} range_n = [64, 128, 256, 512, 768, 1024] for N in range_n: print("cue N=", N) tic() data_cue['N' + str(N)] = ce.eigen_circular_ensemble(N, cSize=10, nchunks=4, seeds=seed_v, ensemble='CUE') toc()