def test_Poly_func_array(self): deg = 3 p1d = self._make_random_poly1d(deg) poly = cf.Poly_Original(self._make_poly_args(), 'poly{0}'.format(deg)) poly._set_poly(p1d.c) x = range(5) np.testing.assert_array_equal(poly.func(x), p1d(x))
def test_Poly__set_poly(self): deg = self._get_random_degree() f = self._make_random_poly1d(deg) df = np.polyder(f) poly = cf.Poly_Original(self._make_poly_args(), 'poly{0}'.format(deg)) poly._set_poly(f) np.testing.assert_array_equal(poly._f.c, f.c) np.testing.assert_array_equal(poly._der.c, df.c) np.testing.assert_array_equal(poly._scnd_der.c, np.polyder(df).c) np.testing.assert_array_equal(poly._int.c, np.polyint(f).c)
def test_Poly5_fit_to_points_noisy(self): deg = 5 actual_f, pts = self._make_poly_and_points(deg, num_pts=200) # add ~2% noise to the y values of the points noisy_pts = [(x, y * n) for ((x, y), n) in zip(pts, np.random.normal(1, .01, len(pts)))] poly5 = cf.Poly_Original(self._make_poly_args(), 'poly{0}'.format(deg)) poly5.fit_to_points(noisy_pts) np.testing.assert_array_almost_equal(poly5._f.c, actual_f.c, decimal=0)
def test_Poly5_fit_to_points(self): deg = 5 actual_f, pts = self._make_poly_and_points(deg) poly5 = cf.Poly_Original(self._make_poly_args(), 'poly{0}'.format(deg)) poly5.fit_to_points(pts) np.testing.assert_array_almost_equal(poly5._f.c, actual_f.c, decimal=2)
def test_Poly_name_prefix_obj(self): deg = self._get_random_degree() p = cf.Poly_Original(self._make_poly_args(), 'poly{0}'.format(deg)) self.assertEqual(p.name_prefix, 'poly')