def load_scf_coefficients(coeff_files, cov_files, nmax, lmax, mmax, min_sample, max_sample, pmass, sn): """ Load coefficients. TODO : REMOVE THIS FUNCTION WHEN SCRIPT IS FULLY WORKING """ ncoeff_sample = max_sample - min_sample print(pmass) S, T = coefficients_smoothing.read_coeff_matrix(coeff_files, ncoeff_sample, nmax, lmax, mmax, min_sample, max_sample, snaps=90) SS, TT, ST = coefficients_smoothing.read_cov_elements(cov_files, ncoeff_sample, nmax, lmax, mmax, min_sample, max_sample, snaps=90) S_smooth, T_smooth, N_smooth = coefficients_smoothing.smooth_coeff_matrix( S, T, SS, TT, ST, pmass, nmax, lmax, mmax, sn, sn_out=0) return S_smooth, T_smooth
def smooth_coeff(coeff_path, cov_path, ni, nf, nmax, lmax, mmax, sn, pmass, snap, sn_out=0): nfiles = nf-ni S, T = coefficients_smoothing.read_coeff_matrix(coeff_path, nfiles, nmax, \ lmax, mmax, n_min=ni,\ n_max=nf, snaps=snap) SS, TT, ST = coefficients_smoothing.read_cov_elements(cov_path, nfiles, nmax,\ lmax, mmax, n_min=ni,\ n_max=nf, snaps=snap) if sn_out==0: S_smooth, T_smooth, N_smooth = coefficients_smoothing.smooth_coeff_matrix(S, T, SS, TT, ST, pmass, nmax, lmax, mmax, sn, sn_out) return S_smooth, T_smooth, N_smooth elif sn_out==1: S_smooth, T_smooth, N_smooth, SN_coeff = coefficients_smoothing.smooth_coeff_matrix(S, T, SS, TT, ST, pmass, nmax, lmax, mmax, sn, sn_out) return S_smooth, T_smooth, N_smooth, SN_coeff
def rho_square(i, sn): """ Computes the `True' density square as defined in equation 5 of the companion doc. It use the coefficients computed with the particle distribution in each particle batch i. """ path = '/home/u9/jngaravitoc/codes/Kullback-Leibler/data/' t1 = time_now() S, T = coefficients_smoothing.read_coeff_matrix( path + 'mwlmc_hal_sn_test_coeff_sample_', 1, nmax, lmax, lmax, i, i + 1, snaps=1) SS, TT, ST = coefficients_smoothing.read_cov_elements( path + 'mwlmc_hal_sn_test_covmat_sample_', 1, nmax, lmax, lmax, i, i + 1, snaps=1) S_smooth, T_smooth, N_coeff = coefficients_smoothing.smooth_coeff_matrix( S, T, SS, TT, ST, mass, nmax, lmax, lmax, sn_range[sn]) rho2 = coefficients_sum_fast(S_smooth, T_smooth, rs) t2 = time_now() time_diff(t1, t2) return rho2
def kpq_sn_estimator(i): pos = np.loadtxt('./MW_100M_b1_dm_part_1e6_300.txt') N_particles = len(pos) n_batches = 100 particles_in_batch = int(N_particles / n_batches) sn_range = np.arange(0, 11, 0.2) Hp = np.zeros(len(sn_range)) Kpq = np.zeros(len(sn_range)) Kpq_rho = np.zeros(len(sn_range)) N_part = 990000 # len(pos_grid) m_p = 1 / N_part rho_factor = 1e4 / N_part m_p_sim = 1E-4 N_coeff = np.zeros(len(sn_range)) path = '/home/xzk/work/github/MW-LMC-SCF/code/data_KL_SN/' S, T = coefficients_smoothing.read_coeff_matrix( path + 'mwlmc_hal_sn_test_coeff_sample_', i + 1, 20, 20, 20, 0, i + 1, snaps=1) SS, TT, ST = coefficients_smoothing.read_cov_elements( path + 'mwlmc_hal_sn_test_covmat_sample_', i + 1, 20, 20, 20, 0, i + 1, snaps=1) S_0, T_0, N_smooth_0 = coefficients_smoothing.smooth_coeff_matrix( S, T, SS, TT, ST, m_p_sim, 20, 20, 20, 0) # sn xyz1 = np.array([ pos[:i * (particles_in_batch), 0], pos[:i * (particles_in_batch), 1], pos[:i * (particles_in_batch), 2] ]).T xyz2 = np.array([ pos[(i + 1) * (particles_in_batch):, 0], pos[(i + 1) * (particles_in_batch):, 1], pos[(i + 1) * (particles_in_batch):, 2] ]).T xyz = np.concatenate((xyz1, xyz2)) assert (len(xyz == 990000)) rho_reference = biff.density(np.ascontiguousarray(xyz.astype(float)), S_0, T_0, M=1, r_s=40.85) print('Here') """ for sn in range(len(sn_range)): S_smooth, T_smooth, N_coeff[sn] = coefficients_smoothing.smooth_coeff_matrix(S, T, SS, TT, ST, m_p_sim, 20, 20, 20, sn_range[sn]) rho_estimate = biff.density(np.ascontiguousarray(xyz.astype(float)), S_smooth, T_smooth, M=1, r_s=40.85) Hp[sn] = np.sum(m_p*np.log(rho_factor*np.abs(rho_estimate))) Kpq[sn] = np.sum(m_p*np.log(rho_factor*np.abs(rho_reference))) - Hp[sn] Kpq_rho[sn] = np.sum(rho_factor*rho_reference*np.log(np.abs(rho_reference/rho_estimate))) """ return Hp, Kpq, Kpq_rho, N_coeff
ylabel('z[kpc]') cb_ax = fig.add_axes([0.93, 0.1, 0.02, 0.8]) cbar = colorbar(im, cax=cb_ax) fig.suptitle( 'Relative density of MW + LMC unbound particles {}'.format(title_name), y=0.93) cbar.set_label(r'$\Delta \rho$') savefig(figname + '.pdf', bbox_inches='tight') savefig(figname + '.png', bbox_inches='tight') if __name__ == "__main__": S_2T_V, T_2T_V = coefficients_smoothing.read_coeff_matrix( '../data/MW/MW_lmc_unbound/mwlmc_unbound_BFE_2T_V_1e6_300_coeff_sample_0', 40, 20, 20, 20, 0, 40) SS_2T_V, TT_2T_V, ST_2T_V = coefficients_smoothing.read_cov_elements( '../data/MW/MW_lmc_unbound/mwlmc_unbound_BFE_2T_V_1e6_300_covmat_sample_0', 40, 20, 20, 20, 0, 40) S_T_V, T_T_V = coefficients_smoothing.read_coeff_matrix( '../data/MW/MW_lmc_unbound/mwlmc_unbound_BFE_T_V_1e6_300_coeff_sample_0', 40, 20, 20, 20, 0, 40) SS_T_V, TT_T_V, ST_T_V = coefficients_smoothing.read_cov_elements( '../data/MW/MW_lmc_unbound/mwlmc_unbound_BFE_T_V_1e6_300_covmat_sample_0', 40, 20, 20, 20, 0, 40) S_T_2V, T_T_2V = coefficients_smoothing.read_coeff_matrix( '../data/MW/MW_lmc_unbound/mwlmc_unbound_BFE_T_2V_1e6_300_coeff_sample_0', 40, 20, 20, 20, 0, 40)