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

[feature] wrapping cost function to return best value explored #33

Merged
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8d8cf99
[feature] wrapping cost function to return best value explored
VolodyaCO Jan 2, 2023
ff18230
[fix] complying with minimize signature
VolodyaCO Jan 2, 2023
4ce8bd7
[feature] saving best value and params only if params are bounded and…
VolodyaCO Jan 3, 2023
0a5ce54
Merge branch 'main' into fix/#29/wrap-cost-function-to-return-best-va…
VolodyaCO Jan 3, 2023
29fa0a3
[fix] correct way of checking bounds
VolodyaCO Jan 3, 2023
03e016f
[test] testing edge case of the langermann function
VolodyaCO Jan 3, 2023
0bb0216
[fix] fixes test
VolodyaCO Jan 3, 2023
a7bfb2b
[fix] inequality constraint fails if function is less than 0 only
VolodyaCO Jan 3, 2023
7026892
[style] length of comment
VolodyaCO Jan 3, 2023
c2311d0
[feature] expose argument to control if best parameters are stored
VolodyaCO Jan 16, 2023
3c84347
[feature] typing
VolodyaCO Jan 16, 2023
fa7da9b
[feature] wrapping cost function to return best value explored
VolodyaCO Jan 2, 2023
718322c
[fix] complying with minimize signature
VolodyaCO Jan 2, 2023
b015210
[feature] saving best value and params only if params are bounded and…
VolodyaCO Jan 3, 2023
f0afb09
[fix] correct way of checking bounds
VolodyaCO Jan 3, 2023
a4ff2a7
[test] testing edge case of the langermann function
VolodyaCO Jan 3, 2023
f17b02d
[fix] fixes test
VolodyaCO Jan 3, 2023
de20411
[fix] inequality constraint fails if function is less than 0 only
VolodyaCO Jan 3, 2023
e46d423
[style] length of comment
VolodyaCO Jan 3, 2023
c878851
[feature] expose argument to control if best parameters are stored
VolodyaCO Jan 16, 2023
9818a7a
[feature] typing
VolodyaCO Jan 16, 2023
3ee4bad
[test] asserting that the opt value is the minimum of the history
VolodyaCO Jun 2, 2023
3905209
Merge branch 'fix/#29/wrap-cost-function-to-return-best-val-scipy-opt…
VolodyaCO Jun 2, 2023
8192721
[style] mypy corrections
VolodyaCO Jun 2, 2023
6e6a611
[fix] seeding ttopt
VolodyaCO Jun 2, 2023
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
Prev Previous commit
Next Next commit
[test] testing edge case of the langermann function
  • Loading branch information
VolodyaCO committed Jan 3, 2023
commit 03e016fbf628a4fa2a163d86c17a2489f32bf049
28 changes: 28 additions & 0 deletions tests/orquestra/opt/optimizers/scipy_optimizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{"method": "L-BFGS-B"},
{"method": "Nelder-Mead"},
{"method": "SLSQP"},
{"method": "Powell"},
{"method": "COBYLA", "options": {"maxiter": 50000, "tol": 1e-7}},
]
)
Expand Down Expand Up @@ -107,3 +108,30 @@ def test_SLSQP_with_inequality_constraints(self):
results_with_constraints.opt_value, abs=1e-1
)
assert results_with_constraints.opt_params.sum() >= 3

# https://github.com/scipy/scipy/issues/17673 reports a function and that is minimised
# with an initial point that has a given cost function value which is lower than the
# optimised value by the Powell optimizer. This test is to ensure that our solution
# over scipy is not affected by this issue.
@pytest.mark.parametrize("method", ["Powell", "L-BFGS-B", "Nelder-Mead", "SLSQP"])
def test_Langermann_function(self, method):
# Definition of the function
langer_c = np.array([6, 1, 4, 4, 8])
langer_A = np.array(
[[4, 6, 3, 5], [8, 7, 9, 9], [2, 7, 8, 8], [9, 2, 6, 9], [5, 4, 1, 4]]
)

def langermann(parameters: np.ndarray) -> float:
# This function is bounded in the [0, 10] box
sum_ = np.sum(np.subtract(langer_A, parameters) ** 2, axis=1)
vec = np.exp(-1 / np.pi * sum_) * np.cos(np.pi * sum_)
result = np.dot(langer_c, vec)
return result

# Initial point
x0 = np.array([4.65116802, 4.42985893, 1.74720157, 4.29727392])
y0 = langermann(x0)

optimiser = ScipyOptimizer(method=method, bounds=[(0, 10)] * 4)
result = optimiser.minimize(langermann, x0)
assert result.opt_value <= y0