-1

I have a data set X which i need to use to maximise the parameters by MLE. I have the log likelihood function

def llh(alpha, beta):
  a = [0]*999
  for i in range(1, 1000):
    a[i-1] = (-0.5)*(((1/beta)*(X[i]-np.sin((alpha)*X[i-1])))**2)
  return sum(a)

I need to maximise this but i have no idea how. I can only think of plotting 3d graphs to find the maximum point but that gives me weird answers that are not what I want.

This is the plot I got

enter image description here

Is there any other possible way to get my maximum parameters or am I going about this the wrong way? My dataset model function is Xk = sin(alphaXk-1) + betaWk where Wk is normally distributed with mean 0 and sigma 1. Any help would be appreciated.Thank you!

hello
  • 37
  • 9

1 Answers1

1

You have to find the maximum of your likelihood numerically. In practice this is done by computing the negative (log) likelihood and using numerical minimization to find the most likely parameters of your model to describe your data. Make use of scipy.optimize.minimize to minimize your likelihood.

I implemented a short example for normal distributed data.

import numpy as np

from scipy.stats import norm
from scipy.optimize import minimize

def neg_llh(popt, X):
    return -np.log(norm.pdf(X, loc = popt[0], scale = popt[1])).sum()

# example data
X = np.random.normal(loc = 5, scale = 2, size = 1000)

# minimize log likelihood
res = minimize(neg_llh, x0 = [2, 2], args = (X))

print(res.x)
array([5.10023503, 2.01174199])

Since you are using sum I suppose the likelihood you defined above is already a (negative?) log-likelihood.

def neg_llh(popt, X):
    alpha = popt[0]
    beta = popt[1]

    return np.sum((-0.5)*(((1 / beta)*(X - np.sin((alpha) * X)))**2))

Try minimizing your negative likelihood. Using your plot you can make a good initial guess (x0) about the values of alpha and beta.

lrsp
  • 1,213
  • 10
  • 18