The objective functions of the calibrator returns a tuple: (total_res, unweighted objective).
ebcpy needs the obj function to return only a float, because the optimization algorithms need this.
Interestingly, this is almost not noticable. See the following code as an example:
from scipy.optimize import differential_evolution
def black_box_function(x, *args):
"""Function with unknown internals we wish to maximize.
This is just serving as an example, for all intents and
purposes think of the internals of this function, i.e.: the process
which generates its output values, as unknown.
"""
obj = -x[0] ** 2 - (x[1] - 1) ** 2 + 1
print(f"Objective Value: {obj}")
return (obj, 'Test')
# Bounded region of parameter space
pbounds = [(2, 4), (-3, 3)]
res = differential_evolution(
func=black_box_function,
bounds=pbounds,
strategy="best1bin")
print(res)
The "black_box_function" is the equivalent of the obj function. When beeing evaluated during the optimization, this evaluates correctly (Observable prints of the values). Only at a specific time (in this case when a new population is to be created) there will be an error:
RuntimeError: func(x, *args) must return a scalar value
It is though noticable when implementing different optimization algorithms, which immediately cant handle tuple returns of the obj function. Therefore this has to be changed.
The objective functions of the calibrator returns a tuple: (total_res, unweighted objective).
ebcpy needs the obj function to return only a float, because the optimization algorithms need this.
Interestingly, this is almost not noticable. See the following code as an example:
The "black_box_function" is the equivalent of the obj function. When beeing evaluated during the optimization, this evaluates correctly (Observable prints of the values). Only at a specific time (in this case when a new population is to be created) there will be an error:
It is though noticable when implementing different optimization algorithms, which immediately cant handle tuple returns of the obj function. Therefore this has to be changed.