def optimal_test(): def fx(x): return .1*x**2 + 3*x -4 g,h,k = optimal_noise_smoothing(.2) f = GHKFilter(-4,0,0,1,g,h,k) ys = [] zs = [] for i in range(100): z = fx(i) + randn()*10 f.update(z) ys.append(f.x) zs.append(z)
def optimal_test(): def fx(x): return .1 * x**2 + 3 * x - 4 g, h, k = optimal_noise_smoothing(.2) f = GHKFilter(-4, 0, 0, 1, g, h, k) ys = [] zs = [] for i in range(100): z = fx(i) + randn() * 10 f.update(z) ys.append(f.x) zs.append(z) plt.plot(ys) plt.plot(zs)
def test_ghk_formulation(): beta = .6 g = 1-beta**3 h = 1.5*(1+beta)*(1-beta)**2 k = 0.5*(1-beta)**3 f1 = GHKFilter(0,0,0,1, g, h, k) f2 = FadingMemoryFilter(x0=0, dt=1, order=2, beta=beta) def fx(x): return .02*x**2 + 2*x - 3 for i in range(1,100): z = fx(i) f1.update(z) f2.update(z) assert abs(f1.x-f2.x[0]) < 1.e-80
def test_ghk_formulation(): beta = .6 g = 1 - beta**3 h = 1.5 * (1 + beta) * (1 - beta)**2 k = 0.5 * (1 - beta)**3 f1 = GHKFilter(0, 0, 0, 1, g, h, k) f2 = FadingMemoryFilter(x0=0, dt=1, order=2, beta=beta) def fx(x): return .02 * x**2 + 2 * x - 3 for i in range(1, 100): z = fx(i) f1.update(z) f2.update(z) assert abs(f1.x - f2.x[0]) < 1.e-80