Skip to content

Commit

Permalink
Use original space for chebychev center
Browse files Browse the repository at this point in the history
  • Loading branch information
schmoelder committed Jan 24, 2024
1 parent 8c07312 commit c5f20f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
8 changes: 6 additions & 2 deletions CADETProcess/optimization/optimizationProblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2722,15 +2722,19 @@ def get_chebyshev_center(self, include_dependent_variables=True):
# !!! Additional checks in place to handle PolyRound.round()
# removing "small" dimensions.
# Bug reported, Check for future release!
chebyshev_orig = hopsy.compute_chebyshev_center(problem)[:, 0]
chebyshev_orig = hopsy.compute_chebyshev_center(
problem, original_space=True
)[:, 0]

try:
problem_rounded = hopsy.round(problem)
except ValueError:
problem_rounded = problem

if problem_rounded.A.shape[1] == problem.A.shape[1]:
chebyshev_rounded = hopsy.compute_chebyshev_center(problem_rounded)[:, 0]
chebyshev_rounded = hopsy.compute_chebyshev_center(
problem_rounded, original_space=True
)[:, 0]

if np.all(np.greater(chebyshev_rounded, self.lower_bounds)):
problem = problem_rounded
Expand Down
23 changes: 6 additions & 17 deletions tests/test_optimization_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_add_linear_constraints(self):
self.optimization_problem.add_linear_constraint('var_0', [])

def test_initial_values(self):
x0_chebyshev_expected = [0.2928932, 0.7071068]
x0_chebyshev_expected = [1/3, 2/3]
x0_chebyshev = self.optimization_problem.get_chebyshev_center(
include_dependent_variables=True
)
Expand Down Expand Up @@ -847,21 +847,14 @@ def transform():
self.assertEqual(variables_expected, variables)

def test_initial_values_without_dependencies(self):
x0_chebyshev_expected = [0.79289322, 0.20710678, 0.5]
x0_chebyshev_expected = [0.75, 0.5, 0.5]
x0_chebyshev = self.optimization_problem.get_chebyshev_center(
include_dependent_variables=False
)
np.testing.assert_almost_equal(x0_chebyshev, x0_chebyshev_expected)

variables_expected = [
0.7928932188134523,
0.2071067811865475,
0.2071067811865475,
0.4999999999999999
]
variables = self.optimization_problem.get_dependent_values(
x0_chebyshev
)
variables_expected = [0.75, 0.5 , 0.5 , 0.5]
variables = self.optimization_problem.get_dependent_values(x0_chebyshev)
np.testing.assert_almost_equal(variables, variables_expected)

self.assertTrue(
Expand Down Expand Up @@ -914,18 +907,14 @@ def test_initial_values_without_dependencies(self):
np.testing.assert_almost_equal(x0_seed_10_random, x0_seed_10_expected)

def test_initial_values(self):
x0_chebyshev_expected = [0.79289322, 0.20710678, 0.2071068, 0.5]
x0_chebyshev_expected = [0.75, 0.5, 0.5, 0.5]
x0_chebyshev = self.optimization_problem.get_chebyshev_center(
include_dependent_variables=True
)

np.testing.assert_almost_equal(x0_chebyshev, x0_chebyshev_expected)

independent_variables_expected = [
0.7928932188134523,
0.2071067811865475,
0.4999999999999999
]
independent_variables_expected = [0.75, 0.5, 0.5]
independent_variables = self.optimization_problem.get_independent_values(
x0_chebyshev
)
Expand Down

0 comments on commit c5f20f8

Please sign in to comment.