def gen_initial_guess(observed_counts, one_sided_prf, Nguess, randscale=1e-3, reg='tv'): """ generate a list of initial guesses based on the RL deconvolution """ M = len(one_sided_prf) symmetric_prf = np.r_[np.zeros(M-1), one_sided_prf] Ndim = len(observed_counts) + M - 1 # pad first to avoid end effects pad0 = np.ones(2*M)*observed_counts[0] pad1 = np.ones(M)*observed_counts[-1] observed_counts_padded = np.r_[pad0, observed_counts, pad1] initial_guess = util.deconvlucy1d(observed_counts_padded, symmetric_prf, iterations=1000, reg=reg) ## smooth the initial guess #from micromet.util import smooth #initial_guess = smooth(initial_guess, 11) initial_guess = initial_guess[M+1:-M] # starting locations for each walker are in a small range around the # Richardson-Lucy starting point p0 = [initial_guess*2**(np.random.randn(Ndim)*randscale) for ii in range(Nguess)] #p0 = [initial_guess + np.random.randn(Ndim)*randscale for # ii in range(Nguess)] return p0
int(itm[1]['month']), int(itm[1]['dom'])), itm[1]['time']) for itm in df_glb.iterrows()] df_glb.index = time #clean up negative values df_glb.lld[df_glb.lld<0] = 500 return df_glb df_glb = load_glb() ## exclude the calibration #df_glb = df_glb.iloc[48*2:-12*2] #rl deconvolution df_glb['lld_rltv'] = util.deconvlucy1d(df_glb.lld, prf30_symmetric, reg='tv', iterations=1000) df_glb['lld_rl'] = util.deconvlucy1d(df_glb.lld, prf30_symmetric, reg=None, iterations=1000) f, ax = plt.subplots() df_glb[['lld', 'lld_rl', 'lld_rltv']].plot(ax=ax) # look at detailed diagnostics if True: #dftmp = df_glb.head(24*2) dftmp = df_glb.iloc[48*2:48*3+1] observed_data = dftmp.lld.values # check out the initial guess ig = util_emcee.gen_initial_guess(dftmp.lld.values, prf30, Nguess=1,