diff --git a/scripts/example_residual.py b/examples/example_residual.py similarity index 98% rename from scripts/example_residual.py rename to examples/example_residual.py index d4affc4..ba37e33 100644 --- a/scripts/example_residual.py +++ b/examples/example_residual.py @@ -1,6 +1,4 @@ """ -@author: Fabian Schaipp - Implements Example 5.3 in Frank E. Curtis and Michael L. Overton, A sequential quadratic programming diff --git a/example_rosenbrock.py b/examples/example_rosenbrock.py similarity index 83% rename from example_rosenbrock.py rename to examples/example_rosenbrock.py index eb84109..ef16ec0 100755 --- a/example_rosenbrock.py +++ b/examples/example_rosenbrock.py @@ -1,5 +1,10 @@ """ -@author: Fabian Schaipp +Implements Example 5.1 in + + Frank E. Curtis and Michael L. Overton, A sequential quadratic programming + algorithm for nonconvex, nonsmooth constrained optimization, + SIAM Journal on Optimization 2012 22:2, 474-500, https://doi.org/10.1137/090780201. + """ import matplotlib.pyplot as plt @@ -12,8 +17,6 @@ from ncopt.functions.rosenbrock import NonsmoothRosenbrock from ncopt.sqpgs import SQPGS -np.random.seed(1234) - # %% Setup f = ObjectiveOrConstraint(NonsmoothRosenbrock(a=8.0), dim=2) @@ -37,7 +40,7 @@ # %% How to use the solver -problem = SQPGS(f, gI, gE, x0=None, tol=1e-6, max_iter=100, verbose=True) +problem = SQPGS(f, gI, gE, x0=None, tol=1e-10, max_iter=100, verbose=True) x = problem.solve() print("Distance to solution:", f"{np.linalg.norm(x - xstar):.9f}") @@ -60,15 +63,11 @@ # Plot contour and solution ax.contourf(X, Y, Z, cmap="gist_heat", levels=20, alpha=0.7, antialiased=True, lw=0, zorder=0) -# ax.contourf(X, Y, Z, colors='lightgrey', levels=20, alpha=0.7, -# antialiased=True, lw=0, zorder=0) -# ax.contour(X, Y, Z, cmap='gist_heat', levels=8, alpha=0.7, -# antialiased=True, linewidths=4, zorder=0) ax.scatter(xstar[0], xstar[1], marker="*", s=200, c="gold", zorder=1) for i in range(7): x0 = np.random.randn(2) - problem = SQPGS(f, gI, gE, x0, tol=1e-6, max_iter=100, verbose=False, store_history=True) + problem = SQPGS(f, gI, gE, x0, tol=1e-10, max_iter=100, verbose=False, store_history=True) x_k = problem.solve() print(x_k) @@ -90,4 +89,4 @@ ax.legend(handles=legend_elements, ncol=3, fontsize=8) fig.tight_layout() -fig.savefig("data/img/rosenbrock.png") +fig.savefig("../data/img/rosenbrock.png") diff --git a/src/ncopt/sqpgs/defaults.py b/src/ncopt/sqpgs/defaults.py index 377c77c..0c880bb 100644 --- a/src/ncopt/sqpgs/defaults.py +++ b/src/ncopt/sqpgs/defaults.py @@ -29,8 +29,8 @@ class Dotdict(dict): "xi_y": 1e3, "xi_sy": 1e-6, "iter_H": 10, - "num_points_obj": 2, - "num_points_gI": 3, + "num_points_obj": 4, + "num_points_gI": 4, "num_points_gE": 4, "qp_solver": "osqp", "reg_H": 1e-03,