From f594be873f716867a7c1e968a1c54c0c9f2ba0f4 Mon Sep 17 00:00:00 2001 From: Simon Blanke Date: Sat, 16 Mar 2024 02:01:34 +0100 Subject: [PATCH] add new search-space method to nd-test-functions --- .../test_functions_nd/rastrigin_function.py | 19 ++----------------- .../test_functions_nd/rosenbrock_function.py | 3 +++ .../test_functions_nd/sphere_function.py | 3 +++ .../styblinski_tang_function.py | 3 +++ 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/surfaces/mathematical_functions/test_functions_nd/rastrigin_function.py b/surfaces/mathematical_functions/test_functions_nd/rastrigin_function.py index 90a4c20..8396c4d 100644 --- a/surfaces/mathematical_functions/test_functions_nd/rastrigin_function.py +++ b/surfaces/mathematical_functions/test_functions_nd/rastrigin_function.py @@ -54,20 +54,5 @@ def objective_function_dict(self, params): return self.return_metric(loss) - def search_space(self, value_types="array", steps=100): - min_x0 = -6 - min_x1 = -6 - - max_x0 = 6 - max_x1 = 6 - - step_size_x0 = (max_x0 - min_x0) / steps - step_size_x1 = (max_x1 - min_x1) / steps - - return super().search_space_from_blank( - search_space_blank={ - "x0": (min_x0, max_x0, step_size_x0), - "x1": (min_x1, max_x1, step_size_x1), - }, - value_types=value_types, - ) + def search_space(self, min=-5, max=5, step=0.1, value_types="array"): + return super().create_n_dim_search_space(min, max, step, value_types) diff --git a/surfaces/mathematical_functions/test_functions_nd/rosenbrock_function.py b/surfaces/mathematical_functions/test_functions_nd/rosenbrock_function.py index 1d9bea6..f1f7d46 100644 --- a/surfaces/mathematical_functions/test_functions_nd/rosenbrock_function.py +++ b/surfaces/mathematical_functions/test_functions_nd/rosenbrock_function.py @@ -37,3 +37,6 @@ def objective_function_dict(self, params): loss = (self.A - x) ** 2 + self.B * (y - x**2) ** 2 return self.return_metric(loss) + + def search_space(self, min=-5, max=5, step=0.1, value_types="array"): + return super().create_n_dim_search_space(min, max, step, value_types) diff --git a/surfaces/mathematical_functions/test_functions_nd/sphere_function.py b/surfaces/mathematical_functions/test_functions_nd/sphere_function.py index 6f2c886..5e206c4 100644 --- a/surfaces/mathematical_functions/test_functions_nd/sphere_function.py +++ b/surfaces/mathematical_functions/test_functions_nd/sphere_function.py @@ -34,3 +34,6 @@ def objective_function_dict(self, params): loss += self.A * x * x return self.return_metric(loss) + + def search_space(self, min=-5, max=5, step=0.1, value_types="array"): + return super().create_n_dim_search_space(min, max, step, value_types) diff --git a/surfaces/mathematical_functions/test_functions_nd/styblinski_tang_function.py b/surfaces/mathematical_functions/test_functions_nd/styblinski_tang_function.py index a97ea26..bb0b9c1 100644 --- a/surfaces/mathematical_functions/test_functions_nd/styblinski_tang_function.py +++ b/surfaces/mathematical_functions/test_functions_nd/styblinski_tang_function.py @@ -40,3 +40,6 @@ def objective_function_dict(self, params): loss = loss / 2 return self.return_metric(loss) + + def search_space(self, min=-5, max=5, step=0.1, value_types="array"): + return super().create_n_dim_search_space(min, max, step, value_types)