From cc887e91edc40447f58d8790a3e6522ec4fdee36 Mon Sep 17 00:00:00 2001 From: Toru Tamaki Date: Sat, 6 Sep 2025 16:19:23 +0900 Subject: [PATCH 1/2] fix the Box indicator function - old: (x > self.lower) & (x < self.upper): this is an open set, which violates the assumption of the convex projection - fix (x >= self.lower) & (x <= self.upper): this is a closed convex set. also add a test for this logic. --- pyproximal/proximal/Box.py | 2 +- pytests/test_projection.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproximal/proximal/Box.py b/pyproximal/proximal/Box.py index 9f52cf3..7adc82d 100644 --- a/pyproximal/proximal/Box.py +++ b/pyproximal/proximal/Box.py @@ -38,7 +38,7 @@ def __init__( self.box = BoxProj(self.lower, self.upper) def __call__(self, x: NDArray) -> bool: - return bool(np.all((x > self.lower) & (x < self.upper))) + return bool(np.all((x >= self.lower) & (x <= self.upper))) @_check_tau def prox(self, x: NDArray, tau: float) -> NDArray: diff --git a/pytests/test_projection.py b/pytests/test_projection.py index 2b91cca..e3b07f1 100644 --- a/pytests/test_projection.py +++ b/pytests/test_projection.py @@ -35,6 +35,9 @@ def test_Box(par): tau = 2.0 assert moreau(box, x, tau) + x_proj = box.prox(x, tau) + assert box(x_proj) + @pytest.mark.parametrize( "par", From 41e1968afcddb029b828440c2439bbadcd7a3be0 Mon Sep 17 00:00:00 2001 From: Toru Tamaki Date: Mon, 8 Sep 2025 11:58:36 +0900 Subject: [PATCH 2/2] fix test_Box() - move and change lines to be consistent with other tests --- pytests/test_projection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pytests/test_projection.py b/pytests/test_projection.py index e3b07f1..b2d66e4 100644 --- a/pytests/test_projection.py +++ b/pytests/test_projection.py @@ -31,13 +31,15 @@ def test_Box(par): box = Box(-1, 1) x = np.random.normal(0.0, 1.0, par["nx"]).astype(par["dtype"]) + # evaluation + assert box(x) is False + xp = box.prox(x, 1.0) + assert box(xp) is True + # prox / dualprox tau = 2.0 assert moreau(box, x, tau) - x_proj = box.prox(x, tau) - assert box(x_proj) - @pytest.mark.parametrize( "par",