MCPcopy Index your code
hub / github.com/numpy/numpy / test_fit

Function test_fit

numpy/polynomial/tests/test_classes.py:150–191  ·  view source on GitHub ↗
(Poly)

Source from the content-addressed store, hash-verified

148
149
150def test_fit(Poly):
151
152 def f(x):
153 return x * (x - 1) * (x - 2)
154 x = np.linspace(0, 3)
155 y = f(x)
156
157 # check default value of domain and window
158 p = Poly.fit(x, y, 3)
159 assert_almost_equal(p.domain, [0, 3])
160 assert_almost_equal(p(x), y)
161 assert_equal(p.degree(), 3)
162
163 # check with given domains and window
164 d = Poly.domain + random((2,)) * .25
165 w = Poly.window + random((2,)) * .25
166 p = Poly.fit(x, y, 3, domain=d, window=w)
167 assert_almost_equal(p(x), y)
168 assert_almost_equal(p.domain, d)
169 assert_almost_equal(p.window, w)
170 p = Poly.fit(x, y, [0, 1, 2, 3], domain=d, window=w)
171 assert_almost_equal(p(x), y)
172 assert_almost_equal(p.domain, d)
173 assert_almost_equal(p.window, w)
174
175 # check with class domain default
176 p = Poly.fit(x, y, 3, [])
177 assert_equal(p.domain, Poly.domain)
178 assert_equal(p.window, Poly.window)
179 p = Poly.fit(x, y, [0, 1, 2, 3], [])
180 assert_equal(p.domain, Poly.domain)
181 assert_equal(p.window, Poly.window)
182
183 # check that fit accepts weights.
184 w = np.zeros_like(x)
185 z = y + random(y.shape) * .25
186 w[::2] = 1
187 p1 = Poly.fit(x[::2], z[::2], 3)
188 p2 = Poly.fit(x, z, 3, w=w)
189 p3 = Poly.fit(x, z, [0, 1, 2, 3], w=w)
190 assert_almost_equal(p1(x), p2(x))
191 assert_almost_equal(p2(x), p3(x))
192
193
194def test_equal(Poly):

Callers

nothing calls this directly

Calls 7

assert_almost_equalFunction · 0.90
assert_equalFunction · 0.90
linspaceMethod · 0.80
fitMethod · 0.80
degreeMethod · 0.80
zeros_likeMethod · 0.80
fFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…