0

I am trying to make an approximation of a noisy data with scipy, but it seems it doesn't work at this specific function. Applying the smoothing factor "s" does not change anything. I end up with interpolation instead of approximation. Oddly it approximates the same type of function (x^-2) normaly. How can it be changed ?

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import UnivariateSpline as unis

h = 11
data = {'d':12, 'f':0.22, 'h':11, 'G':250}

HA = np.linspace(data['d']*data['f'], h, 50)
FA = (data['G'] * ((np.arcsin((data['d']*data['f'])/(2*HA)))))+np.random.normal(scale=1, size=len(HA))

app = unis(HA, FA, s=2)
HA2 = np.linspace(np.min(HA), np.max(HA), 1000)
plt.plot(HA, FA, 'ro')
plt.plot(HA2, app(HA2))
KeVal
  • 351
  • 1
  • 4
  • 15
  • 2
    How did you come up with s=2? What range of s have you tried? Note that if you provide weights for spline fitting, the default value for s is len(w), which should be equal to len(x). Vary s over a larger range, and look at how it impacts the smoothing. – Jon Custer Jan 19 '16 at 20:38
  • I started with `s=0.` which gives interpolation and proceeded with `0.1, 0.5, ..., 1, 2` thats where the 2 stayed. If I use a larger s (ex. `s=len(HA2)`) it works but I don't know why does it need to be so large, given that on all other functions up until now `s=2` had big impact. Even if my function for `FA` is substituted with `FA=EA^(-2)` s=2 sufices, even that `len(HA)` and `len(HA2)` remain unchanged. – KeVal Jan 20 '16 at 11:07
  • Well, that comes down to looking deeper into the algorithm and a particular function. Generally, one has to tune numerical routines for your particular problem. Given that how 'smooth' something is will be a human aesthetic choice, well, there is not definitive programmatic answer. – Jon Custer Jan 20 '16 at 15:10

0 Answers0