Commit 741b2f62 authored by Dr.李's avatar Dr.李

modified constraints

parent a6557ea9
......@@ -57,7 +57,6 @@ class BoundaryImpl(object):
elif self.b_type == BoundaryType.MAXABSREL:
abs_threshold = self.val[0]
rel_threshold = self.val[1]
pyFinAssert(rel_threshold >= 0., ValueError, "relative bounds only support positive value")
if self.direction == BoundaryDirection.LOWER:
rel_bound = center - abs(center) * rel_threshold
abs_bound = center - abs_threshold
......@@ -69,7 +68,6 @@ class BoundaryImpl(object):
elif self.b_type == BoundaryType.MINABSREL:
abs_threshold = self.val[0]
rel_threshold = self.val[1]
pyFinAssert(rel_threshold >= 0., ValueError, "relative bounds only support positive value")
if self.direction == BoundaryDirection.LOWER:
rel_bound = center - abs(center) * rel_threshold
abs_bound = center - abs_threshold
......
......@@ -78,6 +78,34 @@ class TestConstraints(unittest.TestCase):
self.assertAlmostEqual(l, 1.76)
self.assertAlmostEqual(u, 2.42)
def test_max_abs_relative_boundary(self):
lower = BoundaryImpl(BoundaryDirection.LOWER,
BoundaryType.MAXABSREL,
(0.02, 0.2))
upper = BoundaryImpl(BoundaryDirection.UPPER,
BoundaryType.MAXABSREL,
(0.02, 0.2))
bound = BoxBoundary(lower, upper)
center = 2.2
l, u = bound.bounds(center)
self.assertAlmostEqual(l, 1.76)
self.assertAlmostEqual(u, 2.64)
def test_min_abs_relative_boundary(self):
lower = BoundaryImpl(BoundaryDirection.LOWER,
BoundaryType.MINABSREL,
(0.02, 0.2))
upper = BoundaryImpl(BoundaryDirection.UPPER,
BoundaryType.MINABSREL,
(0.02, 0.2))
bound = BoxBoundary(lower, upper)
center = 2.2
l, u = bound.bounds(center)
self.assertAlmostEqual(l, 2.18)
self.assertAlmostEqual(u, 2.22)
def test_create_box_bounds_single_value(self):
names = ['a', 'b', 'c']
b_type = BoundaryType.RELATIVE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment