0

i'm trying to maximize the log-likelihood function with python, using the funcion "minimize" from scipy.optimize.

declaring the log-likelihood function this way:

def like(mu,sigma,x):
l = -(len(x)/2)*np.log(2*np.pi) - (len(x)/2)*np.log(sigma)-(1/2*sigma)*np.dot((x-mu).T,(x-mu))
return -l

then trying to use "minimize" with method = "BFGS":

param = minimize(like,start_params,method="BFGS")

I get this error:

TypeError: like() missing 2 required positional arguments: 'sigma' and 'x'

Obviously i need to optimize w.r.t mu and sigma, given an x input vector.

Could somebody help with this ?

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
  • The documentation seems to indicate that x is required to be the first variable in your function. You have it as the third variable. Does that fix the issue? – Bobby Ocean Feb 09 '21 at 23:52
  • 2
    It seems i needed to pack the parameters to be optimized into a vector: par = mu, sigma and then defining the function: like(par,x): mu,sigma=par .... Thank you anyway – Pasquale Russo Feb 10 '21 at 00:04

0 Answers0