def MEStep(alpha, rfac, Aw, temp, Ker, sxt, Gt, model, f0, Asteps, itt, reset=True): if (reset): temp = 0.001 rfac = 0.05 print 'Restarting maxent with rfac=', rfac, 'alpha=', alpha iseed = random.randint(0, maxint) me.maxent(Aw, rfac, alpha, temp, Ker, sxt, Gt, model, f0, Asteps, iseed) S = me.entropy(Aw, model, f0) Trc = me.lambdac(alpha, Aw, omega, dlda) ratio = -2 * S * alpha / Trc print 'Finished maxent with alpha=', alpha, '-2*alpha*S=', -2 * alpha * S, 'Trace=', Trc print ' ratio=', ratio savetxt('dos_' + str(itt), vstack((omega, Aw)).transpose()) return ratio
def MaximumEntropy(p, tau, Gt): beta = tau[-1] random.seed(1) # seed for random numbers omega = linspace(-p['L'], p['L'], 2 * p['Nw'] + 1) f0, f1, f2 = me.initf0(omega) fsg = 1 if p['statistics'] == 'fermi': Gt = -Gt fsg = -1 normalization = Gt[0] + Gt[-1] Ker = me.initker_fermion(omega, beta, tau) elif p['statistics'] == 'bose': normalization = integrate.trapz(Gt, x=tau) Ker = me.initker_boson(omega, beta, tau) print 'beta=', beta print 'normalization=', normalization # Set error if p['idg']: sxt = ones(len(tau)) / (p['deltag']**2) else: sxt = Gt * p['deltag'] for i in range(len(sxt)): if sxt[i] < 1e-5: sxt[i] = 1e-5 sxt = 1. / sxt**2 # Set model if p['iflat'] == 0: model = normalization * ones(len(omega)) / sum(f0) elif p['iflat'] == 1: model = exp(-omega**2 / p['gwidth']) model *= normalization / dot(model, f0) else: dat = loadtxt('model.dat').transpose() fm = interpolate.interp1d(dat[0], dat[1]) model = fm(omega) model *= normalization / dot(model, f0) #savetxt('brisi_test', vstack((tau, fsg*dot(model,Ker))).transpose()) print 'Model normalization=', dot(model, f0) # Set starting Aw(omega) Aw = random.rand(len(omega)) Aw = Aw * (normalization / dot(Aw, f0)) print 'Aw normalization=', dot(Aw, f0) dlda = me.initdlda(omega, Ker, sxt) temp = 10. rfac = 1. alpha = p['alpha0'] for itt in range(p['Nitt']): print itt, 'Restarting maxent with rfac=', rfac, 'alpha=', alpha iseed = random.randint(0, maxint) me.maxent(Aw, rfac, alpha, temp, Ker, sxt, Gt, model, f0, p['Asteps'], iseed) S = me.entropy(Aw, model, f0) Trc = me.lambdac(alpha, Aw, omega, dlda) ratio = -2 * S * alpha / Trc print 'Finished maxent with alpha=', alpha, '-2*alpha*S=', -2 * alpha * S, 'Trace=', Trc print ' ratio=', ratio savetxt('dos_' + str(itt), vstack((omega, Aw)).transpose()) temp = 0.001 rfac = 0.05 if abs(ratio - 1) < p['min_ratio']: break if (abs(ratio) < 0.05): alpha *= 0.5 else: alpha *= (1. + 0.001 * (random.rand() - 0.5)) / ratio for itt in range(p['Nr']): print 'Smoothing itt ', itt Aw = Broad(p['bwdth'], omega, Aw) Aw *= (normalization / dot(Aw, f0)) # Normalizing Aw savetxt('dos_' + str(p['Nitt']), vstack((omega, Aw)).transpose()) temp = 0.005 rfac = 0.005 iseed = random.randint(0, maxint) me.maxent(Aw, rfac, alpha, temp, Ker, sxt, Gt, model, f0, p['Asteps'], iseed) S = me.entropy(Aw, model, f0) Trc = me.lambdac(alpha, Aw, omega, dlda) ratio = -2 * S * alpha / Trc print 'Finished smoothing run with alpha=', alpha, '-2*alpha*S=', -2 * alpha * S, 'Trace=', Trc print ' ratio=', ratio savetxt('gtn', vstack((tau, fsg * dot(Aw, Ker))).transpose()) Aw = Broad(p['bwdth'], omega, Aw) savetxt('dos.out', vstack((omega, Aw)).transpose()) return (Aw, omega)