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

Improve error message for probability constraint #545

Open
ChristianZimpelmann opened this issue Oct 29, 2024 · 0 comments
Open

Improve error message for probability constraint #545

ChristianZimpelmann opened this issue Oct 29, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ChristianZimpelmann
Copy link
Member

  • optimagic version used, if any: 0.5.0

What would you like to enhance and why? Is it related to an issue/problem?

The following code fails with the message TypeError: only integer scalar arrays can be converted to a scalar index.

import numpy as np
import optimagic as om


def fun(params):
    offset = np.linspace(1, 0, params.shape[0])
    x = params["value"] - offset
    return x @ x


params = pd.DataFrame(
    {
        "value": [0.3, 0.2, 0.5],
        "lower_bound": [0, 0, 0],
        "upper_bound": [1, 1, 1],
    },
    index=["pi_1", "pi_2", "pi_3"],
)
res = om.minimize(
    fun=fun,
    params=params,
    algorithm="scipy_lbfgsb",
    constraints=om.ProbabilityConstraint(selector=lambda params: params[:3]),
)

The problem seems to be that the bounds in the params DataFrame are not allowed (although they are also implemented by ProbabilityConstraint).

Building params as follows works fine:

params = pd.DataFrame(
    {
        "value": [0.3, 0.2, 0.5],
        "lower_bound": [np.nan, np.nan, np.nan],
        "upper_bound": [np.nan, np.nan, np.nan],
    },
    index=["pi_1", "pi_2", "pi_3"],
)

Describe the solution you'd like

Catch exception and improve error message.

Alternative: allow for specifying the bounds. This would require some thought on how to handle cases in which other bounds than 0, 1 are specified in the DataFrame.

@ChristianZimpelmann ChristianZimpelmann added the enhancement New feature or request label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant