You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I optimize my model with two parameters, one is RangeParameter and the other is ChoiceParameter. parameters = [ {"name": "radius", "type": "range", "value_type": "int", "bounds": [1, 7]}, {"name": "nb_filter", "type": "choice", "is_ordered": True, "value_type": "int", "values": [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32]}, {"name": "dilatation", "type":"range", "value_type": "int", "bounds": [1,3]}, ],
Optimization worked and I can plot the response surface between radius and dilatation parameters which are interger RangeParameters.
Now, I try to plot the response surface between the RangeParameter radius and the Choice parameter nb_filter but when I run code there is an error with Choice parameter because it is not a RangeParameter. Then, I modified code to use a ChoiceParameter as y_param. I modified _get_contour_predictions as:
`def _get_contour_predictions(
model: ModelBridge,
x_param_name: str,
y_param_name: str,
metric: str,
generator_runs_dict: TNullableGeneratorRunsDict,
density: int,
slice_values: Optional[Dict[str, Any]] = None,
fixed_features: Optional[ObservationFeatures] = None,
) -> ContourPredictions:
"""
slice_values is a dictionary {param_name: value} for the parameters that
are being sliced on.
"""
x_param = get_range_parameter(model, x_param_name)
y_param = get_choice_parameter(model, y_param_name) # modified
In helper.py I modified get_grid_for_parameter and get_range_parameter as:
def get_choice_parameter(model: ModelBridge, param_name:str) -> ChoiceParameter: """ Get the choice parameter with the given name from the model. Throws if parameter doesn't exist or is not a choice parameter. Args: model: The model. param_name: The name of the ChoiceParameter to be found. Returns: The ChoiceParameter named param_name`.
"""
choice_param = model.model_space.parameters.get(param_name)
if choice_param is None:
raise ValueError(f"Parameter `{param_name}` does not exist.")
if not isinstance(choice_param, ChoiceParameter):
raise ValueError(f"{param_name} is not a ChoiceParameter")
return choice_param`
and
def get_grid_for_choice_parameter(parameter: RangeParameter, density: int) -> np.ndarray: """Get a grid of points along the range of the parameter. Will be a log-scale grid if parameter is log scale. Args: parameter: Parameter for which to generate grid. density: Number of points in the grid. """ grid = np.linspace(start = 2, stop = 32, num = density) return grid
And when I look at Obsf I have this:
I see that the KeyError occurs the first time that my ChoiceParameter nb_filter is different from two, but all my parameters are integer and there is no problem when in Obsf there are equal to float numbers for other parameters, so I don't know what is the problem.
Please, can you help me ?
Thank you in advance!
The text was updated successfully, but these errors were encountered:
Hello,
I optimize my model with two parameters, one is RangeParameter and the other is ChoiceParameter.
parameters = [ {"name": "radius", "type": "range", "value_type": "int", "bounds": [1, 7]}, {"name": "nb_filter", "type": "choice", "is_ordered": True, "value_type": "int", "values": [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32]}, {"name": "dilatation", "type":"range", "value_type": "int", "bounds": [1,3]}, ],
Optimization worked and I can plot the response surface between radius and dilatation parameters which are interger RangeParameters.
Now, I try to plot the response surface between the RangeParameter radius and the Choice parameter nb_filter but when I run code there is an error with Choice parameter because it is not a RangeParameter. Then, I modified code to use a ChoiceParameter as y_param. I modified _get_contour_predictions as:
`def _get_contour_predictions(
model: ModelBridge,
x_param_name: str,
y_param_name: str,
metric: str,
generator_runs_dict: TNullableGeneratorRunsDict,
density: int,
slice_values: Optional[Dict[str, Any]] = None,
fixed_features: Optional[ObservationFeatures] = None,
) -> ContourPredictions:
"""
slice_values is a dictionary {param_name: value} for the parameters that
are being sliced on.
"""
x_param = get_range_parameter(model, x_param_name)
y_param = get_choice_parameter(model, y_param_name) # modified
In helper.py I modified get_grid_for_parameter and get_range_parameter as:
def get_choice_parameter(model: ModelBridge, param_name:str) -> ChoiceParameter: """ Get the choice parameter with the given name from the model. Throws if parameter doesn't exist or is not a choice parameter. Args: model: The model. param_name: The name of the ChoiceParameter to be found. Returns: The ChoiceParameter named
param_name`."""
and
def get_grid_for_choice_parameter(parameter: RangeParameter, density: int) -> np.ndarray: """Get a grid of points along the range of the parameter. Will be a log-scale grid if parameter is log scale. Args: parameter: Parameter for which to generate grid. density: Number of points in the grid. """ grid = np.linspace(start = 2, stop = 32, num = density) return grid
When I run code, I obtain this error:
error_obsf.pdf
And when I look at Obsf I have this:
I see that the KeyError occurs the first time that my ChoiceParameter nb_filter is different from two, but all my parameters are integer and there is no problem when in Obsf there are equal to float numbers for other parameters, so I don't know what is the problem.
Please, can you help me ?
Thank you in advance!
The text was updated successfully, but these errors were encountered: