Reputation: 4343
I was wondering if there was a method to fit a Spline directly to a function instead of points. Currently I'm manually creating the points from the function. Following is the code I use (simplified version)
def get_fit_function(self, function, test_range, k=3, **fArgs):
x = np.array(test_range)
y = np.array([function(p, **fArgs)
for p in x]) # my function
u = UnivariateSpline(x, y, k=k)
print('avgError', u.get_residual()**0.5 / len(x_values))
return u
I couldn't find anything in the scipy documentation. Does anybody know if such a method exists? Thanks.
Upvotes: 0
Views: 95
Reputation: 26030
No.
You need to sample your function on some grid. If you have more information than just points, you could use that, too. For one, if you can compute derivatives, you can use those too.
Upvotes: 1