add test for moving on 0 robustness
This commit is contained in:
parent
5970c77cb9
commit
47967b462b
2 changed files with 8 additions and 8 deletions
10
synth.py
10
synth.py
|
|
@ -1,3 +1,5 @@
|
|||
import operator as op
|
||||
|
||||
from stl.utils import set_params, param_lens
|
||||
from stl.robustness import pointwise_robustness
|
||||
|
||||
|
|
@ -11,15 +13,11 @@ def binsearch(stleval, *, tol=1e-3, lo, hi, polarity):
|
|||
elif not polarity and stleval(hi) > 0:
|
||||
return hi
|
||||
|
||||
test = op.le if polarity else op.gt
|
||||
while hi - lo > tol:
|
||||
mid = lo + (hi - lo) / 2
|
||||
r = stleval(mid)
|
||||
if not polarity: # swap direction
|
||||
r *= -1
|
||||
if r < 0:
|
||||
lo, hi = mid, hi
|
||||
else:
|
||||
lo, hi = lo, mid
|
||||
lo, hi = (mid, hi) if test(r, 0) else (lo, mid)
|
||||
|
||||
# Want satisifiable formula
|
||||
return hi if polarity else lo
|
||||
|
|
|
|||
|
|
@ -17,13 +17,15 @@ ex4 = ("G[0, b?](A < 0)", ("b?",), {"b?": (0.1, 5)},
|
|||
{"b?": False}, {"b?": 0.1})
|
||||
ex5 = ("F[0, b?](A > 0)", ("b?",), {"b?": (0.1, 5)},
|
||||
{"b?": True}, {"b?": 0.1})
|
||||
ex6 = ("(A > a?) or (A > b?)", ("a?", "b?",), {"a?": (0, 2), "b?": (0, 2)},
|
||||
{"a?": False, "b?": False}, {"a?": 2, "b?": 1})
|
||||
|
||||
x = pd.DataFrame([[1,2], [1,4], [4,2]], index=[0,0.1,0.2],
|
||||
columns=["A", "B"])
|
||||
|
||||
|
||||
class TestSTLRobustness(unittest.TestCase):
|
||||
@params(ex1, ex2, ex3, ex4, ex5)
|
||||
@params(ex1, ex2, ex3, ex4, ex5, ex6)
|
||||
def test_lex_synth(self, phi_str, order, ranges, polarity, val):
|
||||
phi = stl.parse(phi_str)
|
||||
val2 = stl.synth.lex_param_project(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue