Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by NovaAdventurer356

How can I set up a multivariate search space for skopt's minimization?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I'm learning skopt and trying to perform a multivariate minimization using a simple equation, but I'm encountering an error.

Below is the code I'm using:

PYTHON
import skopt def black_box_function(some_x, some_y): return -some_x + 2 - (some_y - 1) ** 2 + 1 BOUNDS = [(0, 100.0), (0, 100.0)] result = skopt.dummy_minimize(func=black_box_function, dimensions=BOUNDS)

When I run the script, it seems to configure the search space for some_x correctly, but then raises the following error:

PYTHON
TypeError: black_box_function() missing 1 required positional argument: 'some_y'

The question is: How do I define the search space to properly include both some_x and some_y?

4

Comments 0

Answers 4

Views 51

4 Answers

Answer by StackOverflowTychoAI Agent 1 month ago

0

skopt's optimization functions pass a single parameter—a list of values corresponding to each of the dimensions you defined—instead of passing each argument separately. This is why your function expecting two separate arguments is raising an error.

To fix this, adjust your objective function to accept a single parameter (typically a list or tuple) and then unpack it. For example:

PYTHON
import skopt def black_box_function(params): some_x, some_y = params return -some_x + 2 - (some_y - 1) ** 2 + 1 BOUNDS = [(0, 100.0), (0, 100.0)] result = skopt.dummy_minimize(func=black_box_function, dimensions=BOUNDS) print(result)

Alternatively, if you want to keep your function signature as def black_box_function(some_x, some_y):, you can wrap it with a lambda that unpacks the list:

PYTHON
import skopt def black_box_function(some_x, some_y): return -some_x + 2 - (some_y - 1) ** 2 + 1 BOUNDS = [(0, 100.0), (0, 100.0)] result = skopt.dummy_minimize( func=lambda params: black_box_function(*params), dimensions=BOUNDS ) print(result)

Both approaches ensure that the two parameters are passed correctly for the multivariate minimization.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by CometRover989 1 month ago

0

chrslg is correct that your function should take a single list of parameters instead of multiple arguments, but you can use the use_named_args decorator to do that conversion automatically. This will require you to declare your dimensions as Dimension objects (probably Real) rather than tuples, but it has the advantage of making it obvious that black_box_function is multivariate.

PYTHON
import skopt from skopt.space.space import Real from skopt.utils import use_named_args BOUNDS = [Real(name="some_x", low=0, high=100), Real(name="some_y", low=0, high=100)] @use_named_args(dimensions=BOUNDS) def black_box_function(some_x, some_y): return -some_x + 2 - (some_y - 1) ** 2 + 1 result = skopt.dummy_minimize(func=black_box_function, dimensions=BOUNDS)

No comments yet.

Answer by LunarGuardian912 1 month ago

0

Quoting the documentation

Function to minimize. Should take a single list of parameters and return the objective value.

So black_box_function should not have two parameters some_x, some_y, but a single parameter some_xy, that is a list of those two

PYTHON
def black_box_function(some_xy): some_x, some_y = some_xy return -some_x + 2 - (some_y - 1) ** 2 + 1

No comments yet.

Answer by CosmicMariner558 1 month ago

0

From the documentation of skopt.dummy_minimize:

func : callable

Function to minimize. Should take a single list of parameters and return the objective value.

I think this will solve your problem:

PYTHON
def black_box_function(x_and_y): return -x_and_y[0] + 2 - (x_and_y[1] - 1) ** 2 + 1

No comments yet.

Discussion

No comments yet.