def test_against_orginal_implementation(self): for problem in [ Ackley(n_var=2), Rosenbrock(n_var=2), Sphere(n_var=10), ]: print(problem.__class__.__name__) x0 = FloatRandomSampling().do(problem, 1)[0].X problem.xl = None problem.xu = None rho = 0.5 pop = run(problem, x0, rho=rho)[1:] delta = np.zeros(problem.n_var) for i in range(0, problem.n_var): if (x0[i] == 0.0): delta[i] = rho else: delta[i] = rho * abs(x0[i]) algorithm = PatternSearch(x0=x0, explr_delta=delta) ret = minimize(problem, algorithm, verbose=True) X, _X = pop.get("X"), ret.pop.get("X") F, _F = pop.get("F"), ret.pop.get("F") n = min(len(X), len(_X)) X, _X, F, _F = X[:n], _X[:n], F[:n], _F[:n]
def test_sphere_with_constraints(self): problem = SphereWithConstraints() for algorithm in [GA(), NelderMead(), PatternSearch(), CuckooSearch()]: f, f_opt = test(problem, algorithm) self.assertAlmostEqual(f, f_opt, places=3) print(problem.__class__.__name__, algorithm.__class__.__name__, "Yes")
def test_sphere(self): problem = Sphere() for algorithm in [NelderMead(), PatternSearch(), PSO(), GA()]: f, f_opt = test(problem, algorithm) self.assertAlmostEqual(f, f_opt, places=5) print(problem.__class__.__name__, algorithm.__class__.__name__, "Yes")
def test_sphere_no_bounds(self): problem = SphereNoBounds() x0 = np.random.random(problem.n_var) for algorithm in [NelderMead(x0=x0), PatternSearch(x0=x0)]: f, f_opt = test(problem, algorithm) self.assertAlmostEqual(f, f_opt, places=5) print(problem.__class__.__name__, algorithm.__class__.__name__, "Yes")
from pymoo.algorithms.so_pattern_search import PatternSearch from pymoo.factory import get_problem from pymoo.optimize import minimize problem = get_problem("ackley", n_var=30) algorithm = PatternSearch() res = minimize(problem, algorithm, seed=1, verbose=False) print("Best solution found: \nX = %s\nF = %s" % (res.X, res.F))
# elementwise_evaluation=True ) def _evaluate(self, X, out, *args, **kwargs): w, sigma_max = function(X) sysMass = np.prod(X, axis=1) * MaterialDensity out["F"] = np.column_stack([w, sysMass]) out["G"] = np.column_stack([-w, -sysMass]) problem = MyProblem() algorithm = PatternSearch(explr_delta=0.1, explr_rho=0.3, pattern_step=2, eps=1e-08) from pymoo.util.termination.default import MultiObjectiveDefaultTermination termination = MultiObjectiveDefaultTermination(x_tol=1e-8, cv_tol=1e-6, f_tol=0.0025, nth_gen=5, n_last=30, n_max_gen=1000, n_max_evals=100000) from pymoo.optimize import minimize res = minimize(problem,