def X_testHODLHD(): ''' Make sure that the powerspectra `specmulator.onlyhod.X_testHODLHD` are sensible. ''' # read in theta_i's of the LHD lhd = onlyHOD.HOD_LHD(prior='sinha2017prior_narrow', method='mdu', samples=40) lhd_test = onlyHOD.testHOD_LHD(prior='sinha2017prior_narrow', samples=20) # read P(k|theta_i) for theta_i in LHD average over # 10 realizations to make less noisy X_pk = [] for i in range(1, 11): k, X_pk_i = onlyHOD.X_HODLHD(i, prior='sinha2017prior_narrow', samples=40, karr=True) X_pk.append(X_pk_i) X_pk = np.mean(X_pk, axis=0) # read P(k|theta_i) for theta_i in LHD test sample # average over 10 realization to make less noisy X_pk_test = [] for i in range(1, 11): X_pk_test_i = onlyHOD.X_testHODLHD(i, prior='sinha2017prior_narrow', samples=20) X_pk_test.append(X_pk_test_i) X_pk_test = np.mean(X_pk_test, axis=0) fig = plt.figure(figsize=(12, 6)) sub1 = fig.add_subplot(121) sub2 = fig.add_subplot(122) sub1.scatter(lhd[:, 3], lhd[:, 4], c='k') for i in range(X_pk.shape[0]): sub2.plot(k, k * X_pk[i, :], c='k', ls='--', lw=1) for i in range(X_pk_test.shape[0]): sub1.scatter([lhd_test[i, 3]], [lhd_test[i, 4]]) sub2.plot(k, k * X_pk_test[i, :]) sub1.set_xlabel('log $M_1$', fontsize=20) sub1.set_xlim([12., 14.]) sub1.set_ylabel(r'$\alpha$', fontsize=20) sub1.set_ylim([0.5, 1.5]) sub2.set_xlabel('$k$', fontsize=20) sub2.set_xscale('log') sub2.set_xlim([0.01, 0.5]) sub2.set_ylabel(r'$k P_0(k|\theta_i^{LHD})$', fontsize=20) sub2.set_yscale('log') f = ''.join([UT.fig_dir(), 'tests/test.X_testHODLHD.png']) fig.savefig(f, bbox_inches='tight') plt.close() return None
def thetaLHD(): ''' ***TESTED*** Test thetaLHD using the HOD parameter priors ''' # from Sinha et al (2017) prior theta_lbl = [ 'log $M_\mathrm{min}$', '$\sigma_{\mathrm{log}\,M}$', 'log $M_0$', 'log $M_1$', r'$\alpha$' ] HOD_range_min = [11., 0.001, 6., 12., 0.001] HOD_range_max = [12.2, 1., 14., 14., 2.] samples = 17 m_list = ['maximin', 'centermaximin', 'mdu', 'nohl'] for meth in m_list: lhcube = lhd.thetaLHD([HOD_range_min, HOD_range_max], samples=samples, method=meth) fig = plt.figure(figsize=(9, 9)) for i in range(lhcube.shape[1]): for j in range(lhcube.shape[1]): if i < j: sub = fig.add_subplot(lhcube.shape[1], lhcube.shape[1], lhcube.shape[1] * j + i + 1) sub.scatter(lhcube[:, i], lhcube[:, j]) sub.set_xlim([HOD_range_min[i], HOD_range_max[i]]) if j == lhcube.shape[1] - 1: sub.set_xlabel(theta_lbl[i], fontsize=20) else: sub.set_xticks([]) sub.set_ylim([HOD_range_min[j], HOD_range_max[j]]) if i == 0: sub.set_ylabel(theta_lbl[j], fontsize=20) else: sub.set_yticks([]) elif i == j: sub = fig.add_subplot(lhcube.shape[1], lhcube.shape[1], lhcube.shape[1] * j + i + 1) sub.hist(lhcube[:, i], range=[HOD_range_min[i], HOD_range_max[i]], normed=True) sub.set_xlim([HOD_range_min[i], HOD_range_max[i]]) if i != 0: sub.set_yticks([]) else: sub.set_ylabel(theta_lbl[j], fontsize=20) if i != lhcube.shape[1] - 1: sub.set_xticks([]) else: sub.set_xlabel(theta_lbl[i], fontsize=20) f = ''.join([ UT.fig_dir(), 'tests/test.thetaLHD.HOD.', meth, '.', str(samples), '.samples.png' ]) fig.savefig(f, bbox_inches='tight') return None
def theta_test(HODrange='sinha2017prior_narrow', ): ''' Test the theta_test parameters ''' if HODrange == 'sinha2017prior_narrow': # narrow alpha range range_descrip = "Sinha et al (2017) prior with narrow alpha range" HOD_range_min = [11., 0.001, 6., 12., 0.5] HOD_range_max = [12.2, 1., 14., 14., 1.5] theta_lbl = [ 'log $M_\mathrm{min}$', '$\sigma_{\mathrm{log}\,M}$', 'log $M_0$', 'log $M_1$', r'$\alpha$' ] elif HODrange == 'sinha2017prior': range_descrip = "Sinha et al (2017) prior" HOD_range_min = [11., 0.001, 6., 12., 0.001] HOD_range_max = [12.2, 1., 14., 14., 2.] theta_lbl = [ 'log $M_\mathrm{min}$', '$\sigma_{\mathrm{log}\,M}$', 'log $M_0$', 'log $M_1$', r'$\alpha$' ] else: raise NotImplementedError # LHD thetas theta_lhd = lhd.HOD_LHD(HODrange=HODrange, samples=40, method='mdu') # test thetas theta_test = lhd.HOD_LHD_test(HODrange=HODrange, samples=20, seed=1) fig = plt.figure(figsize=(4 * theta_test.shape[1], 4 * theta_test.shape[1])) for i in range(theta_test.shape[1]): for j in range(theta_test.shape[1]): sub = fig.add_subplot(theta_test.shape[1], theta_test.shape[1], 1 + j + theta_test.shape[1] * i) if i != j: sub.scatter(theta_lhd[:, j], theta_lhd[:, i], c='k') sub.scatter(theta_test[:, j], theta_test[:, i], c='C1') sub.set_xlim([HOD_range_min[j], HOD_range_max[j]]) sub.set_ylim([HOD_range_min[i], HOD_range_max[i]]) if i != theta_test.shape[1] - 1: sub.set_xticklabels([]) else: sub.set_xlabel(theta_lbl[j], fontsize=20) if j != 0: sub.set_yticklabels([]) else: sub.set_ylabel(theta_lbl[i], fontsize=20) f = ''.join([UT.fig_dir(), 'tests/theta_test.png']) fig.savefig(f, bbox_inches='tight') plt.close() return None
def LHD(): ''' *** TESTED *** Testing the different methods of LHD ''' dim = 5 samples = 17 m_list = ['maximin', 'centermaximin', 'mdu', 'nohl'] for meth in m_list: lhcube = lhd.LHD(dim, samples=samples, method=meth, niter=1000) fig = plt.figure(figsize=(9, 9)) for i in range(lhcube.shape[1]): for j in range(lhcube.shape[1]): if i < j: sub = fig.add_subplot(lhcube.shape[1], lhcube.shape[1], lhcube.shape[1] * j + i + 1) sub.scatter(lhcube[:, i], lhcube[:, j]) sub.set_xlim([0., 1.]) if j == lhcube.shape[1] - 1: sub.set_xticks([0., 0.5, 1.]) sub.set_xlabel(r'$\theta_' + str(i) + '$', fontsize=20) else: sub.set_xticks([]) sub.set_ylim([0., 1.]) if i == 0: sub.set_yticks([0., 0.5, 1.]) sub.set_ylabel(r'$\theta_' + str(j) + '$', fontsize=20) else: sub.set_yticks([]) elif i == j: sub = fig.add_subplot(lhcube.shape[1], lhcube.shape[1], lhcube.shape[1] * j + i + 1) sub.hist(lhcube[:, i], range=[0., 1], normed=True) sub.set_xlim([0., 1.]) if i != 0: sub.set_yticks([]) if i != lhcube.shape[1] - 1: sub.set_xticks([]) f = ''.join([ UT.fig_dir(), 'tests/test.LHD.', meth, '.', str(dim), 'dim.', str(samples), '.samples.png' ]) fig.savefig(f, bbox_inches='tight') return None
def HOD_LHD(prior='sinha2017prior_narrow', samples=17): ''' test parameter values in the LHD and the test samples ''' hodprior = LHDhod.HODprior(prior) # HOD prior hodrange = hodprior.range() # parameter values of the LHD theta_lhd = LHDhod.HOD_LHD(prior=prior, samples=samples, method='mdu', overwrite=False) assert theta_lhd.shape[0] == samples assert theta_lhd.shape[1] == len(hodprior.labels) # parameter values of the test sample theta_test = LHDhod.testHOD_LHD(prior=prior, samples=20, overwrite=False) assert theta_test.shape[1] == len(hodprior.labels) fig = plt.figure(figsize=(4 * theta_lhd.shape[1], 4 * theta_lhd.shape[1])) for i in range(theta_lhd.shape[1]): for j in range(theta_lhd.shape[1]): sub = fig.add_subplot(theta_lhd.shape[1], theta_lhd.shape[1], 1 + j + theta_lhd.shape[1] * i) if i != j: sub.scatter(theta_lhd[:, j], theta_lhd[:, i], c='k') sub.scatter(theta_test[:, j], theta_test[:, i], c='C1') sub.set_xlim(np.array(hodrange)[:, j]) sub.set_ylim(np.array(hodrange)[:, i]) if i != theta_lhd.shape[1] - 1: sub.set_xticklabels([]) else: sub.set_xlabel(hodprior.labels[j], fontsize=20) if j != 0: sub.set_yticklabels([]) else: sub.set_ylabel(hodprior.labels[i], fontsize=20) f = ''.join([UT.fig_dir(), 'tests/thetaHOD_lhd.png']) fig.savefig(f, bbox_inches='tight') plt.close() return None