adding tests for lexicographic parameteric synth
This commit is contained in:
parent
673ede60e3
commit
28f755edc5
2 changed files with 30 additions and 3 deletions
|
|
@ -79,7 +79,6 @@ def binsearch(stleval, *, tol=1e-3, lo, hi, polarity):
|
|||
while abs(r) > tol and hi - lo > tol:
|
||||
mid = lo + (hi - lo) / 2
|
||||
r = stleval(mid)
|
||||
print(lo, mid, hi, r)
|
||||
if polarity: # swap direction
|
||||
r *= -1
|
||||
if r < 0:
|
||||
|
|
@ -98,9 +97,7 @@ def lex_param_project(stl, x, *, order, polarity, ranges, tol=1e-3):
|
|||
l = lens(val)[var]
|
||||
return lambda p: pointwise_robustness(set_params(stl, l.set(p)))(x, 0)
|
||||
|
||||
|
||||
for var in order:
|
||||
print(val)
|
||||
stleval = stleval_fact(var, val)
|
||||
lo, hi = ranges[var]
|
||||
_, param = binsearch(stleval, lo=lo, hi=hi, tol=tol, polarity=polarity[var])
|
||||
|
|
|
|||
30
test_synth.py
Normal file
30
test_synth.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import stl
|
||||
import stl.robustness
|
||||
import pandas as pd
|
||||
from nose2.tools import params
|
||||
import unittest
|
||||
from sympy import Symbol
|
||||
|
||||
oo = float('inf')
|
||||
|
||||
ex1 = ("A > a?", ("a?",), {"a?": (0, 10)}, {"a?": True}, {"a?": 1})
|
||||
ex1 = ("F[0, b?](A > a?)", ("a?", "b?"), {"a?": (0, 10), "b?": (0, 10)},
|
||||
{"a?": True, "b?": False}, {"a?": 4, "b?": 0.2})
|
||||
x = pd.DataFrame([[1,2], [1,4], [4,2]], index=[0,0.1,0.2],
|
||||
columns=["A", "B"])
|
||||
|
||||
|
||||
class TestSTLRobustness(unittest.TestCase):
|
||||
@params(ex1)
|
||||
def test_lex_synth(self, phi_str, order, ranges, polarity, val):
|
||||
phi = stl.parse(phi_str)
|
||||
val2 = stl.robustness.lex_param_project(
|
||||
phi, x, order=order, ranges=ranges, polarity=polarity)
|
||||
|
||||
phi = stl.robustness.set_params(phi, val)
|
||||
stl_eval = stl.robustness.pointwise_robustness(phi)
|
||||
self.assertAlmostEqual(stl_eval(x, 0), 0)
|
||||
|
||||
for var in order:
|
||||
self.assertAlmostEqual(val2[var], val[var], delta=0.01)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue