# 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.184832 0.005348 -0.706812 0.186633 1 0.790052 0.792900 -0.720528 0.824114 2 -0.551268 -0.943288 -0.340380 0.447687 3 -0.888001 -0.261984 0.808173 0.060061 4 -0.506423 0.868892 -0.495761 -0.939145 5 -0.925973 -0.111182 0.792783 -0.734339 6 0.485637 -0.809896 -0.859195 -0.218443 7 0.363565 0.440093 -0.440328 -0.535968 8 -0.580427 -0.734504 -0.364797 0.783661 9 0.975841 -0.722036 0.432780 -0.941887 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 ```