Reputation: 1
I am trying to fit a wind data set v=v1,.....,vm
using a two component mixture weibull distribution.
I found a paper suggesting to use the Maximum Likelihood method and in particular to maximize the following equation:
Omega
, a1
, a2
, b1
and b2
are the parameters I want to change in order to maximize the function and v=v1,.....,vm
is a series of known wind speeds.
I have been trying to use the SciPy minimization algorithm but without success.
Here is what I have so far:
def minimizer_function(v,omega,a1,b1,a2,b2):
return np.reciprocal(np.sum((omega*(a1/b1)*((v/b1)**(a1-1))*(np.exp(-((v/b1)**a1)))+(1-omega)*(a2/b2)*((v/b2)**(a2-1))*(np.exp(-((v/b2)**a2))))))
x0 = np.array([0.5,1.0,1.0,1.0,1.0])
res = optimization.minimize(minimizer_function, x0, method='nelder-mead',options={'xtol': 1e-8, 'disp': True})
However I keep on getting the following error:
minimizer_function() missing 5 required positional arguments: 'omega', 'a1', 'b1', 'a2', and 'b2'
I am pretty sure I am missing something.
Upvotes: 0
Views: 1533
Reputation: 114921
The scipy minimizers expect the variables to be stored in a single one-dimensional array. In your case, the objective function should be something like minimizer_function(x, v)
, where x
is an array of five elements containing omega, a1, b1, a2 and b2. That is, something like
def minimizer_function(x, v):
omega, a1, b1, a2, b2 = x
return np.reciprocal(np.sum((omega*(a1/b1)*((v/b1)**(a1-1))*(np.exp(-((v/b1)**a1)))+(1-omega)*(a2/b2)*((v/b2)**(a2-1))*(np.exp(-((v/b2)**a2))))))
The call to minimize
would be something like
x0 = np.array([0.5,1.0,1.0,1.0,1.0])
res = optimization.minimize(minimizer_function, x0, args=(v,), method='nelder-mead',options={'xtol': 1e-8, 'disp': True})
Upvotes: 1