Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using np.minimum instead of default min #162

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pounders/py/pounders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def _default_model_par_values(n):
par = np.zeros(4)
par[0] = np.sqrt(n)
par[1] = max(10, np.sqrt(n))
par[1] = np.maximum(10, np.sqrt(n))
par[2] = 10**-3
par[3] = 0.001

Expand Down Expand Up @@ -129,8 +129,8 @@ def pounders(Ffun, X_0, n, nf_max, g_tol, delta_0, m, Low, Upp, Prior=None, Opti
nfs = Prior["nfs"]
delta = delta_0
spsolver = Options.get("spsolver", 2)
delta_max = Options.get("delta_max", min(0.5 * np.min(Upp - Low), (10**3) * delta))
delta_min = Options.get("delta_min", min(delta * (10**-13), g_tol / 10))
delta_max = Options.get("delta_max", np.minimum(0.5 * np.min(Upp - Low), (10**3) * delta))
delta_min = Options.get("delta_min", np.minimum(delta * (10**-13), g_tol / 10))
gamma_dec = Options.get("gamma_dec", 0.5)
gamma_inc = Options.get("gamma_inc", 2)
eta_1 = Options.get("eta1", 0.05)
Expand Down Expand Up @@ -243,7 +243,7 @@ def pounders(Ffun, X_0, n, nf_max, g_tol, delta_0, m, Low, Upp, Prior=None, Opti
# input("Enter a key and press Enter to continue\n") - Don't uncomment when using Pytest with test_pounders.py
# 2. Critically test invoked if the projected model gradient is small
if ng < g_tol:
delta = max(g_tol, np.max(np.abs(X[xk_in])) * eps)
delta = np.maximum(g_tol, np.max(np.abs(X[xk_in])) * eps)
[Mdir, _, valid, _, _, _] = formquad(X[: nf + 1, :], F[: nf + 1, :], delta, xk_in, Model["np_max"], Model["Par"], 1)
if not valid:
[Mdir, mp] = bmpts(X[xk_in], Mdir, Low, Upp, delta, Model["Par"][2])
Expand Down Expand Up @@ -326,7 +326,7 @@ def pounders(Ffun, X_0, n, nf_max, g_tol, delta_0, m, Low, Upp, Prior=None, Opti
xk_in = nf # Change current center
# 4b. Update the trust-region radius:
if (rho >= eta_1) and (step_norm > delta_inact * delta):
delta = min(delta * gamma_inc, delta_max)
delta = np.minimum(delta * gamma_inc, delta_max)
elif valid:
delta = delta * gamma_dec
if delta <= delta_min:
Expand Down
1 change: 1 addition & 0 deletions pounders/py/tests/test_emittance_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def call_beamline_simulation(x):
return np.squeeze(out)


X_0 = np.random.seed(8675309)
# Adjust these:
n = 4 # Number of parameters to be optimized
X_0 = np.random.uniform(0, 1, (1, n)) # starting parameters for the optimizer
Expand Down
Loading