def mkParameterisations(xmids, ranges, nsignal, order=(3, 0)): import professor2 as prof S = prof.sampling.NDSampler(ranges) X = [S() for _ in range(nsignal)] Y = np.array([mkSignal(x, xmids) for x in X]) MIN = Y.min(axis=0) MAX = Y.max(axis=0) import pyrapp return [pyrapp.Rapp(X, y, order=order) for y in Y.T], MIN, MAX
def getEigentunes(jd, target): nparams = jd["NBINS"] - jd["NDF"] Cinv_tune=np.array(jd["TUNEINVPARAMCOV"]).reshape((nparams, nparams)) Cinv_data=np.array(jd["TUNEINVDATACOV"]).reshape((jd["NBINS"], jd["NBINS"])) T_fwd, S, T_back = eigenDecomposition(Cinv_tune) goftarget=np.percentile(jd["VPHI2"], target) import pyrapp RAPP = [pyrapp.Rapp(r) for r in jd["RAPP"]] ETS, AX = mkEigenTunes(T_fwd, np.array(jd["TUNEPARS"]), lambda x:chi2wCov(jd["YVALS"], RAPP, Cinv_data, x), goftarget, prefix="toy-ets-%i-%s"%(jd["NBINS"], jd["CORRMODE"])) return ETS, AX
def plotEigenTuneHist(jd, ETS): import pyrapp R = [pyrapp.Rapp(r) for r in jd["RAPP"]] TUNED = [r(jd["TUNEPARS"]) for r in R ] ETD=[] for ET in ETS: ETD.append([[r(e) for r in R ] for e in ET]) phibest=jd["WINNERPHI2"] phibestpars = jd["WINNERPARS"] W = [r(phibestpars) for r in R] ERR = np.sqrt(1./np.array(jd["TUNEINVDATACOV"]).reshape((jd["NBINS"],jd["NBINS"])).diagonal()) YV = jd["YVALS"] from matplotlib import pyplot as plt import matplotlib as mpl plt.style.use('ggplot') plt.figure(figsize=(8,8)) # X = np.array(range(len(YV)))+0.5 plt.errorbar(X, YV, yerr=ERR, marker="o", linestyle="none", color="k") plt.yscale("log") plt.xlabel("# Bin") plt.ylabel("Entries") plt.plot(X, TUNED, "r-", label="Central tune (%f)"%jd["TUNECHI2"]) etcols=["b", "m"] for num, ET in enumerate(ETD): plt.plot(X, ET[0], "%s-"%etcols[num], label="ET%i+"%(num+1)) plt.plot(X, ET[1], "%s--"%etcols[num], label="ET%i-"%(num+1)) plt.plot(X, W, "g--", label="Phi best(%f)"%phibest) plt.legend() plt.ylim((100, 580)) # plt.savefig("toy-et-dist-%i-%s.pdf"%(jd["NBINS"], jd["CORRMODE"]))
def mkRes(X_train, X_test, order, fn): import pyrapp if fn == 1: Y_train = [f1(x) for x in X_train] Y_test = [f1(x) for x in X_test] elif fn == 2: Y_train = [f2(x) for x in X_train] Y_test = [f2(x) for x in X_test] elif fn == 3: Y_train = [f3(x) for x in X_train] Y_test = [f3(x) for x in X_test] elif fn == 4: Y_train = [f4(x) for x in X_train] Y_test = [f4(x) for x in X_test] elif fn == 5: Y_train = [f5(x) for x in X_train] Y_test = [f5(x) for x in X_test] elif fn == 6: Y_train = [f6(x) for x in X_train] Y_test = [f6(x) for x in X_test] elif fn == 7: Y_train = [f7(x) for x in X_train] Y_test = [f7(x) for x in X_test] elif fn == 8: Y_train = [f8(x) for x in X_train] Y_test = [f8(x) for x in X_test] elif fn == 9: Y_train = [f9(x) for x in X_train] Y_test = [f9(x) for x in X_test] elif fn == 10: Y_train = [f10(x) for x in X_train] Y_test = [f10(x) for x in X_test] elif fn == 12: Y_train = [f12(x) for x in X_train] Y_test = [f12(x) for x in X_test] elif fn == 13: Y_train = [f13(x) for x in X_train] Y_test = [f13(x) for x in X_test] elif fn == 14: Y_train = [f14(x) for x in X_train] Y_test = [f14(x) for x in X_test] elif fn == 15: Y_train = [f15(x) for x in X_train] Y_test = [f15(x) for x in X_test] elif fn == 16: Y_train = [f16(x) for x in X_train] Y_test = [f16(x) for x in X_test] elif fn == 17: Y_train = [f17(x) for x in X_train] Y_test = [f17(x) for x in X_test] elif fn == 18: Y_train = [f18(x) for x in X_train] Y_test = [f18(x) for x in X_test] elif fn == 19: Y_train = [f19(x) for x in X_train] Y_test = [f19(x) for x in X_test] elif fn == 20: Y_train = [f20(x) for x in X_train] Y_test = [f20(x) for x in X_test] elif fn == 21: Y_train = [f21(x) for x in X_train] Y_test = [f21(x) for x in X_test] elif fn == 22: Y_train = [f22(x) for x in X_train] Y_test = [f22(x) for x in X_test] elif fn == 23: Y_train = [f23(x) for x in X_train] Y_test = [f23(x) for x in X_test] elif fn == 24: Y_train = [f24(x) for x in X_train] Y_test = [f24(x) for x in X_test] else: raise Exception("function {} not implemented, exiting".format(fn)) R = pyrapp.Rapp(X_train, Y_train, order=order) return [abs(R(x) - Y_test[num]) for num, x in enumerate(X_test)]