Skip to content

Commit

Permalink
change default sampling points and example folder
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-sp committed Apr 30, 2024
1 parent d90120c commit 6f8b5d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 0 additions & 2 deletions scripts/example_residual.py → examples/example_residual.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
@author: Fabian Schaipp
Implements Example 5.3 in
Frank E. Curtis and Michael L. Overton, A sequential quadratic programming
Expand Down
19 changes: 9 additions & 10 deletions example_rosenbrock.py → examples/example_rosenbrock.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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}")
Expand All @@ -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)

Expand All @@ -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")
4 changes: 2 additions & 2 deletions src/ncopt/sqpgs/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6f8b5d0

Please sign in to comment.