@@ -676,3 +676,93 @@ def fun_random_error(self, X: np.ndarray, fun_control: Optional[Dict] = None) ->
676676 y [nan_mask ] = np .nan
677677
678678 return self ._add_noise (y )
679+
680+ def fun_ackley (self , X : np .ndarray , fun_control : Optional [Dict ] = None ) -> np .ndarray :
681+ """
682+ Ackley function.
683+ Global minimum at x_i = 0 for all i, f(x*) = 0.
684+ Typical domain: x_i in [-32.768, 32.768] for all i.
685+
686+ Args:
687+ X (np.ndarray): Input array of shape (n_samples, n_features).
688+ fun_control (dict, optional): Control dict for noise etc.
689+
690+ Returns:
691+ np.ndarray: Function values of shape (n_samples,).
692+
693+ Examples:
694+ >>> from spotpython.fun.objectivefunctions import Analytical
695+ >>> import numpy as np
696+ >>> X = np.zeros((2, 3))
697+ >>> fun = Analytical()
698+ >>> fun.fun_ackley(X)
699+ array([0., 0.])
700+ """
701+ X = self ._prepare_input_data (X , fun_control )
702+ a = 20
703+ b = 0.2
704+ c = 2 * np .pi
705+ n_dim = X .shape [1 ]
706+ sum_sq = np .sum (X ** 2 , axis = 1 )
707+ sum_cos = np .sum (np .cos (c * X ), axis = 1 )
708+ term1 = - a * np .exp (- b * np .sqrt (sum_sq / n_dim ))
709+ term2 = - np .exp (sum_cos / n_dim )
710+ y = term1 + term2 + a + np .exp (1 )
711+ return self ._add_noise (y )
712+
713+ def fun_michalewicz (self , X : np .ndarray , fun_control : Optional [Dict ] = None ) -> np .ndarray :
714+ """
715+ Michalewicz function.
716+ Global minimum depends on dimension, typical domain: x_i in [0, pi].
717+ Default m=10 as in the reference.
718+
719+ Args:
720+ X (np.ndarray): Input array of shape (n_samples, n_features).
721+ fun_control (dict, optional): Control dict for noise etc. Can set 'm'.
722+
723+ Returns:
724+ np.ndarray: Function values of shape (n_samples,).
725+
726+ Examples:
727+ >>> from spotpython.fun.objectivefunctions import Analytical
728+ >>> import numpy as np
729+ >>> X = np.array([[2.20, 1.57], [2.20, 1.20]])
730+ >>> fun = Analytical()
731+ >>> fun.fun_michalewicz(X)
732+ array([-1.8013..., -1.5274...])
733+ """
734+ X = self ._prepare_input_data (X , fun_control )
735+ m = 10
736+ if fun_control is not None and "m" in fun_control :
737+ m = fun_control ["m" ]
738+ i = np .arange (1 , X .shape [1 ] + 1 )
739+ # Broadcasting: (n_samples, n_features)
740+ y = - np .sum (np .sin (X ) * (np .sin (i * X ** 2 / np .pi )) ** (2 * m ), axis = 1 )
741+ return self ._add_noise (y )
742+
743+ def fun_rosenbrock (self , X : np .ndarray , fun_control : Optional [Dict ] = None ) -> np .ndarray :
744+ """
745+ Rosenbrock function (general n-dim).
746+ Global minimum at x_i = 1 for all i, f(x*) = 0.
747+ Typical domain: x_i in [-5, 10].
748+
749+ Args:
750+ X (np.ndarray): Input array of shape (n_samples, n_features).
751+ fun_control (dict, optional): Control dict for noise etc.
752+
753+ Returns:
754+ np.ndarray: Function values of shape (n_samples,).
755+
756+ Examples:
757+ >>> from spotpython.fun.objectivefunctions import Analytical
758+ >>> import numpy as np
759+ >>> X = np.ones((2, 3))
760+ >>> fun = Analytical()
761+ >>> fun.fun_rosenbrock(X)
762+ array([0., 0.])
763+ """
764+ X = self ._prepare_input_data (X , fun_control )
765+ b = 100
766+ # Rosenbrock sum over d-1 dimensions: sum_{i=1}^{d-1} [b*(x_{i+1} - x_i^2)^2 + (x_i - 1)^2]
767+ y = np .sum (b * (X [:, 1 :] - X [:, :- 1 ] ** 2 ) ** 2 + (X [:, :- 1 ] - 1 ) ** 2 , axis = 1 )
768+ return self ._add_noise (y )
0 commit comments