offsets = np.linspace(0, 20, 10) in_mesh = np.linspace(0, 1, 100) test_mesh = np.linspace(np.min(in_mesh), np.max(in_mesh), 2000) rescale = False m = 4 bf = basisfunctions.ThinPlateSplines() df = pd.DataFrame() df.index.name = "y0" for y0 in offsets: f = functools.partial(func, y0=y0) in_vals = f(in_mesh) separated = rbf.SeparatedConsistent(bf, in_mesh, in_vals, rescale) integrated = rbf.IntegratedConsistent(bf, in_mesh, in_vals) no_poly = rbf.NoneConsistent(bf, in_mesh, in_vals, rescale) s = pd.Series( data={ "RMSE_NoPoly": no_poly.RMSE(f, test_mesh), "RMSE_Integrated": integrated.RMSE(f, test_mesh), "RMSE_Separated": separated.RMSE(f, test_mesh) }) # Condition remains unchanged, input function as generally no effect on condition s.name = y0 df = df.append(s)
for tf in tfs: in_vals = tf(in_mesh) sepfit = rbf.SeparatedConsistentFitted(bf, in_mesh, in_vals, degree=deg) err0 = norm(sepfit(test_mesh0) - tf(test_mesh0)) err1 = norm(sepfit(test_mesh1) - tf(test_mesh1)) df.loc[deg][str(tf) + "_InfError"] = err0 df.loc[deg][str(tf) + "_InfErrorLargerMesh"] = err1 print("Degree =", deg, ", TF =", str(tf)) print("deg1 - e0 =", df.loc[1][str(tf) + "_InfError"] - err0) print("deg1 - e1 =", df.loc[1][str(tf) + "_InfErrorLargerMesh"] - err1) sep = rbf.SeparatedConsistent(bf, in_mesh, in_vals) sepfit = rbf.SeparatedConsistentFitted(bf, in_mesh, in_vals, degree=8) print() print("Sep Inf Error =", norm(sep(test_mesh0) - tf(test_mesh0))) print("Sep FitInf Error =", norm(sepfit(test_mesh0) - tf(test_mesh0))) for c in df: print(c, df[c].idxmin()) # plt.plot(test_mesh1, tf(test_mesh1), label = "TF") # plt.plot(test_mesh1, sep(test_mesh1), label = "Sep") # plt.plot(test_mesh1, sepfit(test_mesh1), label = "SepFit") # plt.plot(test_mesh, sep(test_mesh) - tf(test_mesh), label ="Error Sep") # plt.plot(test_mesh, sepfit(test_mesh) - tf(test_mesh), label ="Error SepFit") # plt.legend()
plt.plot(plot_mesh, func(plot_mesh), "-", label="Testfunction") df["f"] = func(plot_mesh) none_consistent = rbf.NoneConsistent(bf, in_mesh, in_vals, rescale=False) plt.plot(plot_mesh, none_consistent(plot_mesh), "-", label="No Polynomial Interpolant") df["NoneConsistent"] = none_consistent(plot_mesh) for i, gamma, vertex in zip(range(len(in_mesh)), none_consistent.gamma, in_mesh): plt.plot(plot_mesh, bf(plot_mesh - vertex) * gamma, "--") df["None_BF_" + str(i)] = bf(plot_mesh - vertex) * gamma sep_consistent = rbf.SeparatedConsistent(bf, in_mesh, in_vals, rescale=False) plt.plot(plot_mesh, sep_consistent(plot_mesh), "-", label="Polynomial Interpolant") df["SeparatedConsistent"] = sep_consistent(plot_mesh) plt.plot(plot_mesh, sep_consistent.polynomial(plot_mesh), "-", label="Polynomial") df["Polynomial"] = sep_consistent.polynomial(plot_mesh) for i, gamma, vertex in zip(range(len(in_mesh)), sep_consistent.gamma, in_mesh): plt.plot(plot_mesh, bf(plot_mesh - vertex) * gamma, "--") df["Separated_BF_" + str(i)] = bf(plot_mesh - vertex) * gamma