3

Possibly a dumb question so forgive me but,

From here:

N = 10000
x = 10 + 2*np.random.randn(N)
y = 5 + x + np.random.randn(N)

def neg_loglike(const,coef,std):
    mu = const + coef*x
    print(mu.shape)
    return -1*stats.norm(mu, std).logpdf(y).sum()

seed = np.array([1,1,1])
res = minimize(neg_loglike, seed, method = 'Nelder-Mead', 
            options={'disp': True})

mu is an array/vector in this case - so is stats.norm generating a normal distribution for each value of x? What does it mean for a normal distribution to have multiple means... (clearly I'm not getting this)

Lastly, is a correct interpretation of the optimal values in res.x that these parameters generate a set of normal distributions that maximize the probability of seeing y in the distribution..?

RSHAP
  • 2,337
  • 3
  • 28
  • 39

1 Answers1

3

Yes, norm accepts a vector of loc and scale parameters, and treats each input as its own distribution. Note that it's fine to input a vector for one parameter and a scalar for the other, as is the case in the link you've referenced (where scale is 1 and loc is the vector x).

For example:

from scipy.stats import norm

norm(loc=[1,2,3], scale=1).logpdf([4,5,6])

Output:

array([-5.41893853, -5.41893853, -5.41893853])
andrew_reece
  • 20,390
  • 3
  • 33
  • 58
  • sorry and last part of the question - is how to interpret the results of the optimizer – RSHAP Oct 22 '17 at 23:22
  • That's a substantively different question, and isn't really related to coding. Understanding the results of the Nelder-Mead Simplex in the context of maximum likelihood is a topic better suited for [Cross Validated](https://stats.stackexchange.com/). – andrew_reece Oct 22 '17 at 23:28
  • Glad to help. If this answer resolved your original question, please mark it resolved by clicking the checkmark next to the answer. Good luck with MLE! – andrew_reece Oct 22 '17 at 23:58