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
12
synth.py
12
synth.py
|
|
@ -1,3 +1,5 @@
|
||||||
|
import operator as op
|
||||||
|
|
||||||
from stl.utils import set_params, param_lens
|
from stl.utils import set_params, param_lens
|
||||||
from stl.robustness import pointwise_robustness
|
from stl.robustness import pointwise_robustness
|
||||||
|
|
||||||
|
|
@ -11,16 +13,12 @@ def binsearch(stleval, *, tol=1e-3, lo, hi, polarity):
|
||||||
elif not polarity and stleval(hi) > 0:
|
elif not polarity and stleval(hi) > 0:
|
||||||
return hi
|
return hi
|
||||||
|
|
||||||
|
test = op.le if polarity else op.gt
|
||||||
while hi - lo > tol:
|
while hi - lo > tol:
|
||||||
mid = lo + (hi - lo) / 2
|
mid = lo + (hi - lo) / 2
|
||||||
r = stleval(mid)
|
r = stleval(mid)
|
||||||
if not polarity: # swap direction
|
lo, hi = (mid, hi) if test(r, 0) else (lo, mid)
|
||||||
r *= -1
|
|
||||||
if r < 0:
|
|
||||||
lo, hi = mid, hi
|
|
||||||
else:
|
|
||||||
lo, hi = lo, mid
|
|
||||||
|
|
||||||
# Want satisifiable formula
|
# Want satisifiable formula
|
||||||
return hi if polarity else lo
|
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})
|
{"b?": False}, {"b?": 0.1})
|
||||||
ex5 = ("F[0, b?](A > 0)", ("b?",), {"b?": (0.1, 5)},
|
ex5 = ("F[0, b?](A > 0)", ("b?",), {"b?": (0.1, 5)},
|
||||||
{"b?": True}, {"b?": 0.1})
|
{"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],
|
x = pd.DataFrame([[1,2], [1,4], [4,2]], index=[0,0.1,0.2],
|
||||||
columns=["A", "B"])
|
columns=["A", "B"])
|
||||||
|
|
||||||
|
|
||||||
class TestSTLRobustness(unittest.TestCase):
|
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):
|
def test_lex_synth(self, phi_str, order, ranges, polarity, val):
|
||||||
phi = stl.parse(phi_str)
|
phi = stl.parse(phi_str)
|
||||||
val2 = stl.synth.lex_param_project(
|
val2 = stl.synth.lex_param_project(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue