I have several different blocks in my Python-based program, with each block representing a non-linear function f(x, l) with x representing a class containing several different parameters (here labeled as k, l and m). The function is acting on those parameters. Those functions (here called A, B, C etc.) can be chained to each other, such that I can get constructions such as
x_0->A(l_1)->B(l_2)->C(l_3)->x_1
i.e. I take an initial class x_0, put it into A together with a specific value l_1, use the modified class x_A as input in B, obtain a new result class x_B, and so on, until I get x_1 as final result. Of course, I also can re-use those functions, creating structures like
x_0->A(l_1)->B(l_2)->A(l_3)->C(l_4)->x_1
Due to the nonlinearities involved I can not change the order in this arrangement.
Now my aim is to optimize one (or several, depending on my aim) of the parameters in class x. I now could try around by changing the order of the involved function blocks, the amount of the used function blocks and the additional parameters l_n, but this is quite cumbersome due to the nature of brute-forcing. Moreover, as soon as one or more of the input parameters k, l or m changes, I have to repeat that process.
Therefore, are there functions/methods which are already available in Python which I could use here?
A short example could be:
def function_A(x_0, l_0):
return x_0 * np.exp(-l_0)
def function_B(x_0, l_0):
return x_0 * np.cos(l_0)
def function_C(x_0, l_0):
return np.power(x_0, l_0)
def fit_functions(init_val, function_list, l_list):
cur_val = init_val
for i, elem in enumerate(function_list):
cur_val = elem(cur_val, l_list[i])
return cur_val
init_val = 1
ret_val = fit_functions(init_val, [function_A, function_C, function_B, function_A], [1.1, 2.4, 0.2, 1]) #Example call of fit_functions
Now I would like to maximize ret_val while using between 1 and 5 function blocks, consisting of function_A to function_C. Neither the order nor the amount of blocks is fixed, ideally this should be up to the optimization approach