def plotScalingFactor(): r=2*1e-8 l = 5e4 dpi = 300 j = 0 for nu0 in [0.005, 0.1]: for s in [0.025, 0.1]: t = np.arange(0, 2 * (utl.logit(0.995) - utl.logit(nu0)) / s + 1., 1) fig, ax = plt.subplots(2, 1, figsize=(5.5, 2.5), dpi=dpi, sharex=True); nu(t, s=s, nu0=nu0).plot(color='k', legend=False, ax=ax[0]) pplt.annotate(r'$s$={}, $\nu_0=${} ({} Sweep)'.format(s, nu0, ('Soft', 'Hard')[nu0 == 0.005]), fontsize=7, ax=ax[0]) pplt.setSize(ax=ax[0], fontsize=6) ax[0].set_ylabel(r'$\nu_t$') # H0 = H(t[0], s=s, nu0=nu0) Ht = H(t, s=s, nu0=nu0) df = pd.DataFrame([np.log(Ht / H0), -2 * r * t * l], columns=t, index=['log(Growth)', r'log(Decay)']).T df['log(Growth) + log(Decay)'] = df.sum(1) df.plot(ax=ax[1], grid=True, linewidth=2); ax[1].set_xlabel('Generations'); ax[1].set_ylabel('Log(Scaling Factor)') ax[1].axvline(df.iloc[1:, 2].abs().idxmin(), color='k', linestyle='--', linewidth=0.5) # if j != 3: # ax[1].legend_.remove() # else: ax[1].legend(['log(Growth)', r'log(Decay)', 'log(Growth) + log(Decay)'], bbox_to_anchor=(1.45, .75), prop={'size': 6}) pplt.setSize(ax[1], fontsize=6) plt.tight_layout(pad=0.1, rect=[0, 0, 0.7, 1]) plt.gcf().subplots_adjust(bottom=0.15) pplt.savefig('decayFactors{}'.format(j), dpi=dpi) j += 1
def nu(t, s=0.025, nu0=0.005): return pd.Series(utl.sig(0.5 * s * t + utl.logit(nu0)), index=t) def plotLDDecayTheoretical(sim):
def H(t, s=0.025, nu0=0.005): return 2 * utl.sig(0.5 * s * t + utl.logit(nu0)) * ( 1 - utl.sig(0.5 * s * t + utl.logit(nu0))) def nu(t, s=0.025, nu0=0.005): return pd.Series(utl.sig(0.5 * s * t + utl.logit(nu0)), index=t)
def estimateS(y): eps=1e-3 y[0]=y[0].apply(lambda x: min(1-eps,max(x,eps))) y[59]=y[59].apply(lambda x: min(1-eps,max(x,eps))) s=(2./59 * (utl.logit(y[59])-utl.logit(y[0]))).rename('s') return s