python中参数值的非线性搜索

2024-05-15 09:51:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个功能

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

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

我需要写两个函数:

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

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

这是我目前拥有的,但是我不知道如何输入“an”,高斯分布的随机噪声。这是我的猜测。。你知道吗

安=np.随机.正态(0.1100)

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

事先谢谢你的帮助。你知道吗


Tags: the数据anmodelreturnisdefnp