Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct obj function #59

Closed
jkriwet opened this issue Apr 15, 2024 · 0 comments · Fixed by #60
Closed

correct obj function #59

jkriwet opened this issue Apr 15, 2024 · 0 comments · Fixed by #60

Comments

@jkriwet
Copy link
Contributor

jkriwet commented Apr 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant