Reputation: 153
I am trying to optimize the following function in python. My goal is to obtain the parameters which minimize this function.
def lik(parameters):
r, alpha, a, b = parameters[0], parameters[1], parameters[2], parameters[3]
delta_x = np.where(df['x'].values > 0,1,0)
a_1 = gammaln(r + df['x'].values)-gammaln(r)+r*np.log(alpha)
a_2 = gammaln(a+b)+gammaln(b+df['x'].values)-gammaln(b)-gammaln(a+b+df['x'].values)
a_3 = -(r+df['x'].values)*np.log(alpha+df['T'].values)
a_4 = delta_x * np.log(a)-np.log(b+df['x'].values-1)-(r+df['x'].values)*np.log(alpha+df['t_x'].values)
ll = a_1 +a_2 + np.log(np.exp(a_3)+delta_x*(np.exp(a_4)))
return -np.sum(ll)
In order to identify the parameters i use the following function:
bounds = Bounds([0.01,0.01,0.01,0.01],[1000,1000,1000,1000])
mle = minimize(lik, [1.01,1.01,1.01,1.01],method = 'L-BFGS-B',bounds=bounds)
mle.x
The problem I am facing is, however, that for large numbers of a_3
in lik()
I am geting giant values, would anyone know how I could approach this problem in order to obtain good parameters for the problem above?
Upvotes: 1
Views: 105