Я пытаюсь найти значения для четырех различных параметров (kc, tauI, tauC, tauD), чтобы оптимизировать производительность контроллера. Я хочу, чтобы моя программа тестировала как можно больше комбинаций в течение разумного периода времени в заданном диапазоне чисел. Мне нужна помощь с выяснением, как попробовать все комбинации параметров в заданном диапазоне.
Я пытался использовать itertools.combinsk, но, похоже, он не работает с массивами. Это не столько вопрос синтаксиса, сколько вопрос о том, какой подход использовать для решения этой проблемы.
kc = np.linspace (0.1 , 1, 10)
tauI = np.linspace (0.1 , 1, 10)
tauD = np.linspace (0.1 , 1, 10)
tauC = np.linspace (0.1 , 1, 10)
def performance(kc, tauI, tauD, tauC):
# defining s
s = control.tf([1, 0], [0, 1])
# defining all combinations of parameters to test for controller
performance
possible_combinations = itertools.combinations([kc, tauI, tauD, tauC])
index = 0
best_performance = 1000
for i in possible_combinations:
kc = possible_combinations[index][0]
tauI = possible_combinations[index][1]
tauD = possible_combinations[index][2]
tauC = possible_combinations[index][3]
# defining the transfer functions
Gp = 1/(s**2 + s + 1)
Gd = (s + 1)/(s**2 + s + 1)
Gc = Kc * (1 + 1/(tauI*s) + (tauD * s)/(tauC * s + 1))
# defining the system
sys_D = Gd/(1 + Gp * Gc)
sys_U = Gc/(1 + Gp * Gc)
# calculate the performance
total_performance = 0.
# loop through csv files and calculate performance
for filename in all_files:
# import disturbance from csv
T_i = pd.read_csv(filename, header = 0)
T_i = T_i.values.reshape(1,60)
# calculate output response
Y = Y_func(sys_D, time_array, T_i)
# calculate input response
U = U_func(sys_U, time_array, Y)
# calculate performance for this csv file
perfect = perf(Y, U)
# add the performance for this csv to the total performance
total_performance += perfect
# calculate the average performance
average_perf = total_performance/len(all_files)
# check if the performance for these parameters were better than
# previously run tests
if average_perf < best_performance:
best_performance = average_perf
kept_kc = kc
kept_tauI = tauI
kept_tauD = tauD
kept_tauC = tauC