# Creating Continuous Search Spaces This example illustrates several ways to create continuous spaces space. ## Imports ```python import numpy as np ``` ```python from baybe.parameters import NumericalContinuousParameter from baybe.searchspace import SearchSpace, SubspaceContinuous ``` ## Settings We begin by defining the continuous parameters that span our space: ```python DIMENSION = 4 BOUNDS = (-1, 1) ``` ```python parameters = [ NumericalContinuousParameter(name=f"x_{k + 1}", bounds=BOUNDS) for k in range(DIMENSION) ] ``` From these parameter objects, we can now construct a continuous subspace. Let us draw some samples from it and verify that they are within the bounds: ```python subspace = SubspaceContinuous(parameters) samples = subspace.sample_uniform(10) print(samples) assert np.all(samples >= BOUNDS[0]) and np.all(samples <= BOUNDS[1]) ``` x_1 x_2 x_3 x_4 0 0.522272 -0.513139 0.442870 -0.207688 1 0.553190 -0.648405 -0.513100 0.391422 2 -0.479559 -0.298807 0.870955 0.155970 3 0.407092 0.121744 -0.099437 0.589661 4 0.448636 0.758785 0.386590 -0.705582 5 -0.342511 -0.544703 0.438188 -0.769221 6 -0.027594 -0.850321 0.492551 0.862558 7 -0.638042 0.869763 0.075943 -0.970749 8 -0.035967 0.537571 0.048337 0.875565 9 0.902882 -0.483462 -0.472715 -0.493270 There are several ways we can turn the above objects into a search space. This provides a lot of flexibility depending on the context: ```python # Using conversion: searchspace1 = SubspaceContinuous(parameters).to_searchspace() ``` ```python # Explicit attribute assignment via the regular search space constructor: searchspace2 = SearchSpace(continuous=SubspaceContinuous(parameters)) ``` ```python # Using an alternative search space constructor: searchspace3 = SearchSpace.from_product(parameters=parameters) ``` No matter which version we choose, we can be sure that the resulting search space objects are equivalent: ```python assert searchspace1 == searchspace2 == searchspace3 ```