0

I have this function,

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

an is gaussian distributed random noise with σ2 = 1 and p denotes the particular choice of values of free parameters, p = [A,k,φ]

I need to write two functions:

(1)peval - is supplied a set of parameter values, p and the values of the independent variable, x and returns fp(x) and

(2)residuals -is supplied parameter values, the data set and the array of independent variable values, xn and returns the residuals

This is what I have at the moment, however I am not sure how to input "an", the gaussian distributed random noise. This was my guess..

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))     

I have data which looks like this:

0.0003 6.09073051353

0.0006 5.51270817927

0.0009 6.89123564432

0.0012 4.99645189114

0.0015 6.7032515641

0.0018 8.9916107534

Thanks in advance for your help.

mdurant
  • 27,272
  • 5
  • 45
  • 74
  • You are trying to determine the values of the parameters? Doesn't, then, the noise already exist in your data y-values? – mdurant Oct 19 '14 at 02:23
  • @mdurant when the OP writes "p[1]*np.sin(2*(np.pi)*p[2]*x+p[3])+np.random.normal(0,1,100)" this is an attempt to declaratively state the model, with the idea that sophisticated machinery will understand which things are constant vs. parameters vs. noise and use an appropriate procedure to infer parameter values. For example R or SAS might understand models written in notation similar to this. Unfortunately numpy is nowhere near this sophisticated, so instead the OP is simply adding more noise to their data. lol. – identity-m Oct 19 '14 at 20:09
  • One can do such a thing using string declarations in pystatsmodels. – mdurant Oct 19 '14 at 20:35
  • I suppose your right about the noise redundancy. Also I realized I should be using 0-2 not 1-3 array elements. Thanks for the help. – JohnnyLaz Oct 20 '14 at 02:33

0 Answers0