0

我有这个功能,

dn =fp(xn)+an =Asin(2π k xn +φ)+an

an是高斯分布的随机噪声,σ2 = 1p表示自由参数值的特定选择,p = [A,k,φ]

我需要编写两个函数:

(1) peval - 提供一组参数值 p 和自变量 x 的值并返回 fp(x) 和

(2)残差- 提供参数值、数据集和自变量值数组,xn 并返回残差

这就是我目前所拥有的,但是我不确定如何输入“an”,即高斯分布的随机噪声。这是我的猜测..

an = np.random.normal(0,1,100)

def peval(x, p):

  #Evaluate the model at the points in x for model parameter values in p.   
  # return a numpy array containing the set  of points y(x)

    return p[1]*np.sin(2*(np.pi)*p[2]*x+p[3])+an


def residuals(p, y, x):

 #  Evaluate the function at for the particular parameter set p,
 #  find the and return residuals.  
 #  p is the set of parameters
 #  y is the measured data set
 #  x is the independent variable.

    return (y-peval(x,p))     

我有看起来像这样的数据:

0.0003 6.09073051353

0.0006 5.51270817927

0.0009 6.89123564432

0.0012 4.99645189114

0.0015 6.7032515641

0.0018 8.9916107534

在此先感谢您的帮助。

4

0 回答 0