Skip to content

Commit b2b084a

Browse files
committed
ENH: Added damp option to complete polynomial object.
1 parent 6dc5486 commit b2b084a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

interpolation/complete_poly.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,14 @@ def __init__(self, n, d):
280280
self.n = n
281281
self.d = d
282282

283-
def fit_values(self, s, x):
283+
def fit_values(self, s, x, damp=0.0):
284284
Phi = complete_polynomial(s.T, self.d).T
285285
self.Phi = Phi
286-
self.coefs = np.ascontiguousarray(lstsq(Phi, x)[0])
286+
if damp == 0.0:
287+
self.coefs = np.ascontiguousarray(lstsq(Phi, x)[0])
288+
else:
289+
new_coefs = np.ascontiguousarray(lstsq(Phi, x)[0])
290+
self.coefs = (1 - damp) * new_coefs + damp * self.coefs
287291

288292
def __call__(self, s):
289293

interpolation/tests/test_complete.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def f(x, y): return x
1818
assert(evals.shape == vals.shape)
1919
assert(abs(evals - vals).max() < 1e-10)
2020

21+
cp.fit_values(points, vals, damp=0.5)
22+
23+
2124

2225
def test_complete_vector():
2326

@@ -38,6 +41,8 @@ def f2(x, y): return x**3 - y
3841
assert(evals.shape == vals.shape)
3942
assert(abs(evals - vals).max() < 1e-10)
4043

44+
cp.fit_values(points, vals, damp=0.5)
45+
4146

4247
if __name__ == '__main__':
4348
test_complete_scalar()

0 commit comments

Comments
 (0)