Skip to content

fix initialize robust noisy points for unconstrained NEI#361

Merged
y0z merged 2 commits intooptuna:mainfrom
hrntsm:main
Mar 17, 2026
Merged

fix initialize robust noisy points for unconstrained NEI#361
y0z merged 2 commits intooptuna:mainfrom
hrntsm:main

Conversation

@hrntsm
Copy link
Contributor

@hrntsm hrntsm commented Mar 17, 2026

Contributor Agreements

Please read the contributor agreements and if you agree, please click the checkbox below.

  • I agree to the contributor agreements.

Motivation

When setting the acquisition function to 'nei', I constantly get the following error:

AttributeError: 'ValueAtRisk' object has no attribute '_robust_X_noisy'.

Description of the changes

Previously, _robust_X_noisy was only initialized when there were constraints.
It has been changed to initialize _robust_X_noisy during the initialization phase of the ValueAtRisk class.

Test code

from __future__ import annotations

import numpy as np
import optuna
import optunahub


def numpy_objective(X: np.ndarray) -> np.ndarray:
    C = np.asarray(
        [[2.0, -12.2, 21.2, -6.4, -4.7, 6.2], [1.0, -11, 43.3, -74.8, 56.9, -10]]
    )
    X_poly = np.zeros_like(X)
    for i in range(C.shape[1]):
        X_poly = X * (X_poly + C[:, i])
    X0X1 = X[..., 0] * X[..., 1]
    out = np.sum(X_poly, axis=-1)
    out += X0X1 * (-4.1 - 0.1 * X0X1 + 0.4 * X[..., 0] + 0.4 * X[..., 1])
    return out


def objective(trial: optuna.Trial) -> float:
    x = trial.suggest_float("x", -1, 4)
    y = trial.suggest_float("y", -1, 4)
    X = np.array([x, y])
    f = numpy_objective(X).item()
    return f


RobustGPSampler = optunahub.load_module("samplers/value_at_risk").RobustGPSampler
sampler = RobustGPSampler(
    seed=0, uniform_input_noise_rads={"x": 0.5, "y": 0.5}, acqf_type="nei"
)
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=50)

Copy link
Member

@y0z y0z left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@y0z y0z added the bug Something isn't working label Mar 17, 2026
@y0z y0z merged commit ee52975 into optuna:main Mar 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants