code: def test_lsq():
      """implements alternative version of first order Least Squares filter
      using g-h filter formulation and uses it to check the output of the
      LeastSquaresFilter class."""
  
      global lsq, lsq2, xs, lsq_xs
  
      gh = GHFilter(x=0, dx=0, dt=1, g=0.5, h=0.02)
      lsq = LeastSquaresFilterOriginal(dt=1, order=1)
      lsq2 = LeastSquaresFilter(dt=1, order=1)
      zs = [x + random.randn() * 10 for x in range(0, 10000)]
  
      # test __repr__ at least doesn't crash
      try:
          str(lsq2)
      except:
          assert False, "LeastSquaresFilter.__repr__ exception"
  
      xs = []
      lsq_xs = []
      for i, z in enumerate(zs):
          g = 2 * (2 * i + 1) / ((i + 2) * (i + 1))
          h = 6 / ((i + 2) * (i + 1))
  
          x, dx = gh.update(z, g, h)
          lx = lsq(z)
          lsq_xs.append(lx)
  
          x2 = lsq2.update(z)
          assert near_equal(x2[0], lx, 1.0e-10), "{}, {}, {}".format(
              i, x2[0], lx
          )
          xs.append(x)
  
      plt.plot(xs)
      plt.plot(lsq_xs)
  
      for x, y in zip(xs, lsq_xs):
          r = x - y
          assert r < 1.0e-8
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  from math import sqrt
  import matplotlib.pyplot
  import numpy
  from numpy import dot
  import numpy.random
  from scipy.linalg import inv
  from filterpy.gh import GHFilter
  from filterpy.leastsq import LeastSquaresFilter
label_desc: Use image node_id 2 for calling a global function with example usage: test_lsq() without return types