def show(data, arg_dict): """Display the mean value, estimated auto-correlaton and error thereof.""" for label in sorted(data.keys()): print "* label:", label for o in arg_dict["orders"]: print " * order:", o mean, delta, tint, dtint = tauint(data[label].data, o, plots=arg_dict["uwplot"]) print " mean:", pretty_print(mean, delta) print " tint:", pretty_print(tint, dtint)
def show(data, arg_dict): """Display the mean value, estimated auto-correlaton and error thereof.""" for label in sorted(data.keys()): print "* label:", label for o in arg_dict["orders"]: print " * order:", o mean, delta, tint, dtint = tauint(data[label].data, o, plots=arg_dict['uwplot']) print " mean:", pretty_print(mean, delta) print " tint:", pretty_print(tint, dtint)
def therm(data, arg_dict): """Estimate thermalization effects, make a plot.""" for label in sorted(data.keys()): print "* label:", label for o in arg_dict["orders"]: ydata = [] dydata = [] print " * order:", o for nc in arg_dict["cutoffs"]: mean, delta, tint, dtint = tauint(data[label].data[:, :, nc:], o) ydata.append(mean) dydata.append(delta) plt.errorbar(arg_dict["cutoffs"], ydata, yerr=dydata) plt.show()
def therm(data, arg_dict): """Estimate thermalization effects, make a plot.""" for label in sorted(data.keys()): print "* label:", label for o in arg_dict["orders"]: ydata = [] dydata = [] print " * order:", o for nc in arg_dict['cutoffs']: mean, delta, tint, dtint = \ tauint(data[label].data[:,:,nc:], o) ydata.append(mean) dydata.append(delta) plt.errorbar(arg_dict['cutoffs'], ydata, yerr=dydata) plt.show()
def test_with_correlated_data_single_replicum(self): r"""Check the :class:`puwr.tauint` method with the :class:`puwr.correlated_data` method. Note that this is a statistical test with random numbers. We test for a :math:`3\sigma` deviation here, which is unlikely but not impossible. If this test fails, re-run a few times before making any conclusions.""" fails = 0 for known_tau in np.linspace(2, 20, 20): data = correlated_data(known_tau) mean, err, tau, dtau = tauint(data, 0) if tau - 3*dtau > known_tau or \ tau + 3*dtau < known_tau: print tau - known_tau, dtau fails += 1 self.assertGreaterEqual(1, fails)
def test_secondary_multiple_replica_product(self): """Test using the product of two observables.""" fails = 0 for known_tau in np.linspace(2,20,10): data = [[correlated_data(known_tau)[0][0], correlated_data(known_tau)[0][0], correlated_data(known_tau)[0][0]], [correlated_data(known_tau)[0][0], correlated_data(known_tau)[0][0], correlated_data(known_tau)[0][0]]] mean, err, tau, dtau = tauint(data, lambda x, y: x * y) if tau - 3*dtau > known_tau or \ tau + 3*dtau < known_tau: print tau - known_tau, dtau fails += 1 self.assertGreaterEqual(0, fails)
def test_with_correlated_data_single_replicum(self): r"""Check the :class:`puwr.tauint` method with the :class:`puwr.correlated_data` method. Note that this is a statistical test with random numbers. We test for a :math:`3\sigma` deviation here, which is unlikely but not impossible. If this test fails, re-run a few times before making any conclusions.""" fails = 0 for known_tau in np.linspace(2,20,20): data = correlated_data(known_tau) mean, err, tau, dtau = tauint(data, 0) if tau - 3*dtau > known_tau or \ tau + 3*dtau < known_tau: print tau - known_tau, dtau fails += 1 self.assertGreaterEqual(1, fails)
def extrapolate(data, arg_dict, f=(lambda x: 1., lambda x: x)): """Extrapolate data. Optionally make a plot.""" # check if target lattice sizes are given # if not, do the extrapolation for all lattice sizes if not arg_dict['L_sizes']: arg_dict['L_sizes'] = sorted(set([d.L for d in data.values()])) for o in arg_dict["orders"]: print " * order = g^" + str(o) x, y, dy, cl, dcl, ffn = [], [], [], [], [], [] for L in arg_dict['L_sizes']: print " * L =", L [i.append([]) for i in x, y, dy] for label in data: if data[label].L != L: continue print " ** label:", label mean, delta, tint, dtint = \ tauint(data[label].data, o, plots=arg_dict['uwplot']) x[-1].append(data[label].tau) y[-1].append(mean) dy[-1].append(delta) print " mean:", pretty_print(mean, delta) print " tint:", pretty_print(tint, dtint) print " ** tau -> 0 limit" coeffs, errors = extrapolate_cl(f, x[-1], y[-1], dy[-1]) ffn.append( lambda x: np.sum(c[0, 0] * f(x) for c, f in zip(coeffs, f))) cl.append(coeffs[0, 0]) dcl.append(errors[0, 0]**0.5) sxsq = sum(xx**2 for xx in x[-1]) sx = sum(x[-1]) sa = np.sqrt( sum(((sxsq - sx * xx) / (3 * sxsq - sx**2))**2 * yy**2 for xx, yy in zip(x[-1], dy[-1]))) assert (abs((dcl[-1] - sa) / sa) < 1e-12) print " cl:", pretty_print(cl[-1], dcl[-1]) print " " + "*" * 50 for plt in (p for p in arg_dict["mk_plots"] if L in p.L and o in p.orders): plt.data.append((x[-1], y[-1], dy[-1])) plt.cl.append((cl[-1], dcl[-1])) fnx = np.linspace(0, max(x[-1]), 100) plt.fit.append((fnx, [ffn[-1](i) for i in fnx])) plt.labels.append("$L = {0}$".format(L)) for plt in arg_dict["mk_plots"]: mk_plot(plt)
def extrapolate(data, arg_dict, f=(lambda x: 1.0, lambda x: x)): """Extrapolate data. Optionally make a plot.""" # check if target lattice sizes are given # if not, do the extrapolation for all lattice sizes if not arg_dict["L_sizes"]: arg_dict["L_sizes"] = sorted(set([d.L for d in data.values()])) for o in arg_dict["orders"]: print " * order = g^" + str(o) x, y, dy, cl, dcl, ffn = [], [], [], [], [], [] for L in arg_dict["L_sizes"]: print " * L =", L [i.append([]) for i in x, y, dy] for label in data: if data[label].L != L: continue print " ** label:", label mean, delta, tint, dtint = tauint(data[label].data, o, plots=arg_dict["uwplot"]) x[-1].append(data[label].tau) y[-1].append(mean) dy[-1].append(delta) print " mean:", pretty_print(mean, delta) print " tint:", pretty_print(tint, dtint) print " ** tau -> 0 limit" coeffs, errors = extrapolate_cl(f, x[-1], y[-1], dy[-1]) ffn.append(lambda x: np.sum(c[0, 0] * f(x) for c, f in zip(coeffs, f))) cl.append(coeffs[0, 0]) dcl.append(errors[0, 0] ** 0.5) sxsq = sum(xx ** 2 for xx in x[-1]) sx = sum(x[-1]) sa = np.sqrt(sum(((sxsq - sx * xx) / (3 * sxsq - sx ** 2)) ** 2 * yy ** 2 for xx, yy in zip(x[-1], dy[-1]))) assert abs((dcl[-1] - sa) / sa) < 1e-12 print " cl:", pretty_print(cl[-1], dcl[-1]) print " " + "*" * 50 for plt in (p for p in arg_dict["mk_plots"] if L in p.L and o in p.orders): plt.data.append((x[-1], y[-1], dy[-1])) plt.cl.append((cl[-1], dcl[-1])) fnx = np.linspace(0, max(x[-1]), 100) plt.fit.append((fnx, [ffn[-1](i) for i in fnx])) plt.labels.append("$L = {0}$".format(L)) for plt in arg_dict["mk_plots"]: mk_plot(plt)
def test_secondary_multiple_replica_product(self): """Test using the product of two observables.""" fails = 0 for known_tau in np.linspace(2, 20, 10): data = [[ correlated_data(known_tau)[0][0], correlated_data(known_tau)[0][0], correlated_data(known_tau)[0][0] ], [ correlated_data(known_tau)[0][0], correlated_data(known_tau)[0][0], correlated_data(known_tau)[0][0] ]] mean, err, tau, dtau = tauint(data, lambda x, y: x * y) if tau - 3*dtau > known_tau or \ tau + 3*dtau < known_tau: print tau - known_tau, dtau fails += 1 self.assertGreaterEqual(0, fails)
if alpha < np.random.random(1): # reject Z[i + 1, :] = Z[i, :] lPex[i + 1] = lPex[i] lPz[i + 1] = lPz[i] num_of_rejects = num_of_rejects + 1 print('rejection rate = ' + repr((num_of_rejects * 100.0) / M)) # QoI = Quantile function q = 0.05 theta1 = np.exp(Z[:, 0]) theta2 = Z[:, d + 1] q_post = theta1 * ((-np.log(q))**(1.0 / theta2)) # IACT -- only works in python 2.7 due to bad print try: dumpmean, delta, tint, d_tint = puwr.tauint( np.reshape(Z.T, [d + 2, 1, M]), 0) tau[irun] = tint * 2.0 except: pass print('tau = ' + repr(tau[irun])) q_post = np.mean(q_post) print('Mean quantile = ' + repr(q_post)) Q_py[irun] = q_post print('') print('TT Shock absorber completed. Some average values:') print('Q_py = ' + repr(np.mean(Q_py)) + ' +- ' + repr(np.sqrt(np.sum((Q_py - np.mean(Q_py))**2) / (runs - 1)))) try: print('tau = ' + repr(np.mean(tau)) + ' +- ' +