I am working on an Optimization problem in Python, which is defined like this:
import numpy as np import scipy as sci from numpy import fabs as fabs t_step_h = 0.25 def g_costFunc(P_f,P_g): P_f = np.asarray(fabs(P_f)/1000) P_g = np.asarray(fabs(P_g)/1000) energy_cost_in = np.trapz(P_f,dx=t_step_h,axis=0)*fit # trapziodal integral energy_cost_out = np.trapz(P_g,dx=t_step_h,axis=0)*Ep energy_cost_tot = energy_cost_in - energy_cost_out energy_cost_tot = np.float64(energy_cost_tot) return energy_cost_tot def a_costFunc(A_tot): a_cost = -1*A_tot*50 return a_cost def objective(x, sign=1.0): P_max = x P_min = x s_max = x s_min = x s_data, P_f, P_g = PG(a,b,P_max,P_min,P_f_max,s_max,s_min) A_tot = AM(s_data,c,d) a_cost_opt = a_costFunc(A_tot) g_cost_opt = g_costFunc(P_f,P_g) res_max = -(a_cost_opt + g_cost_opt) print((a_cost_opt + g_cost_opt)) return res_max x0 = (2.5,2.5,.8,.2) # Starting points bd0 = (1,5) bd1 = (1,5) bd2 = (0.7,0.9) bd3 = (0.1,0.3) bnds = (bd0,bd1,bd2,bd3) # bounds minimizer_kwargs = dict(method="L-BFGS-B", bounds=bnds) sol = sci.optimize.basinhopping(objective, x0, minimizer_kwargs=minimizer_kwargs, niter=2, niter_success=5, T=0.5, stepsize=.1, disp=True) print(sol.x)
As you see in my code, due to the complexity of my objective function, I am using basinhopping algorithm and so far it is giving me a good result. That negative sign in my res_max is to find the maximum indeed (maximum interest), so I thought a negative minimum is a maximum. The functions which are being called inside my objective function, have non-linear calculations, and all of their parameters are numpy array. But there are some points unclear for me about this optimization:
- Is my objective function convex, differentiable, non-linear, discrete?
- How can I find that my result is a global minimum, not a local minimum? (I want the global minimum)
- Which algorithm is actually minimizing my function, basinhopping or L-BFGS-B?
- Is scipy.optimize.basinhopping the best framework which I need?
Your help is really appreciated.
Thank you, Masoud