# 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.601695 -0.934194 0.653773 -0.205518 1 -0.774099 -0.043234 0.849342 0.071294 2 -0.615049 -0.179733 -0.646783 -0.608451 3 -0.884077 0.826561 -0.534024 0.370063 4 -0.130680 -0.513415 0.302674 0.230553 5 -0.562261 0.349272 0.635123 -0.584136 6 -0.833806 -0.753765 0.506007 -0.599539 7 0.032850 -0.399415 0.727299 0.103442 8 0.944060 -0.804807 -0.472628 0.035451 9 -0.128686 0.094946 0.352237 0.166231 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 ```