Parameter Optimization in python with differential_evolution or minimize from scipy.optimize

104 views Asked by At

I have a function ,calculate_array, which returns a list of values (for e.g 10 values). I want to optimize two input parameters a,b, in this function so that the first element of the list to be maximum (compare to the other 9 elements; for example [9, 1.2 , 3.3 5.0 , 4.2 ,2.5,6,3.9 , 5.4,2] ).

The main function would be like this:

from scipy.optimize import differential_evolution

def calculate_array(a,b):

 #some calculation
 return ListValue

For optimization part :

def objective(Evo):
    a , b = Evo  
    array = calculate_array(a, b)   
    return -array[0]   

# define range for input
r_min, r_max = 0, 10
# define the bounds on the search
bounds = [(r_min, r_max), (r_min, r_max)]


# Perform differential evolution optimization
result = differential_evolution(objective, bounds)

# Extract the optimized values
optimal_a, optimal_b = result.x

# Calculate the optimized array
optimized_array = calculate_array(optimal_a, optimal_b)

Now I have some questions! Is it a correct way of doing that?! and Is it different from the case that we use minimize function from scipy.optimize ? I actually tried the minimize for a simple example and sometimes I get slightly different result depending on the initial_guess that I choose. And when I try differential_evolution for my main code it doesn't converged and is in running state for long time and I am not sure if it is a problem with the way I implement it or even due to the nature of the equation that I am calculate this array with? I would be thankful to hear any feedback from you.

0

There are 0 answers