implemented f,neg,or canonical form and fixed bug in Or rule
This commit is contained in:
parent
8587d830ad
commit
a331d90b44
2 changed files with 27 additions and 8 deletions
|
|
@ -10,7 +10,7 @@ from lenses import lens
|
||||||
|
|
||||||
import stl.ast
|
import stl.ast
|
||||||
from stl.ast import t_sym
|
from stl.ast import t_sym
|
||||||
from stl.utils import walk
|
from stl.utils import walk, f_neg_or_canonical_form
|
||||||
from stl.robustness import op_lookup
|
from stl.robustness import op_lookup
|
||||||
|
|
||||||
Param = namedtuple("Param", ["L", "h", "B", "eps"])
|
Param = namedtuple("Param", ["L", "h", "B", "eps"])
|
||||||
|
|
@ -40,10 +40,6 @@ def admissible_params(phi, eps, L):
|
||||||
B = max(node_base(n, eps, L) for n in walk(phi))
|
B = max(node_base(n, eps, L) for n in walk(phi))
|
||||||
return B, h
|
return B, h
|
||||||
|
|
||||||
def new_symbol_set(ss):
|
|
||||||
indices = set(ss[id_map].keys())
|
|
||||||
non_indicies = set(v.name for k, v in ss.items() if v != "id_map")
|
|
||||||
return indices | non_indicies
|
|
||||||
|
|
||||||
def symbolic_params(phi, eps, L):
|
def symbolic_params(phi, eps, L):
|
||||||
return Param(
|
return Param(
|
||||||
|
|
@ -53,8 +49,8 @@ def symbolic_params(phi, eps, L):
|
||||||
eps=sym.Dummy("eps"),
|
eps=sym.Dummy("eps"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def smooth_robustness(phi, *, L=None, eps=None):
|
def smooth_robustness(phi, *, L=None, eps=None):
|
||||||
|
phi = f_neg_or_canonical_form(phi)
|
||||||
p = symbolic_params(phi, eps, L)
|
p = symbolic_params(phi, eps, L)
|
||||||
lo, hi = beta(phi, p), alpha(phi, p)
|
lo, hi = beta(phi, p), alpha(phi, p)
|
||||||
subs = {}
|
subs = {}
|
||||||
|
|
@ -96,7 +92,7 @@ def _(phi, p):
|
||||||
|
|
||||||
@alpha.register(stl.Neg)
|
@alpha.register(stl.Neg)
|
||||||
def _(phi, p):
|
def _(phi, p):
|
||||||
return 1/beta(phi, p)
|
return 1/beta(phi.arg, p)
|
||||||
|
|
||||||
|
|
||||||
@alpha.register(stl.Or)
|
@alpha.register(stl.Or)
|
||||||
|
|
@ -128,7 +124,7 @@ beta.register(stl.LinEq)(alpha)
|
||||||
|
|
||||||
@beta.register(stl.Neg)
|
@beta.register(stl.Neg)
|
||||||
def _(phi, p):
|
def _(phi, p):
|
||||||
return 1/alpha(phi, p)
|
return 1/alpha(phi.arg, p)
|
||||||
|
|
||||||
|
|
||||||
@beta.register(stl.Or)
|
@beta.register(stl.Or)
|
||||||
|
|
|
||||||
23
stl/utils.py
23
stl/utils.py
|
|
@ -85,3 +85,26 @@ def symbol_lens(phi):
|
||||||
def set_params(stl_or_lens, val):
|
def set_params(stl_or_lens, val):
|
||||||
l = stl_or_lens if isinstance(stl_or_lens, Lens) else param_lens(stl_or_lens)
|
l = stl_or_lens if isinstance(stl_or_lens, Lens) else param_lens(stl_or_lens)
|
||||||
return l.modify(lambda x: val[str(x)] if str(x) in val else x)
|
return l.modify(lambda x: val[str(x)] if str(x) in val else x)
|
||||||
|
|
||||||
|
|
||||||
|
def f_neg_or_canonical_form(phi):
|
||||||
|
if isinstance(phi, stl.LinEq):
|
||||||
|
return phi
|
||||||
|
|
||||||
|
children = [f_neg_or_canonical_form(s) for s in phi.children()]
|
||||||
|
if isinstance(phi, (stl.And, stl.G)):
|
||||||
|
children = [stl.ast.Neg(s) for s in children]
|
||||||
|
children = tuple(children)
|
||||||
|
|
||||||
|
if isinstance(phi, stl.Or):
|
||||||
|
return stl.Or(children)
|
||||||
|
elif isinstance(phi, stl.And):
|
||||||
|
return stl.Neg(stl.Or(children))
|
||||||
|
elif isinstance(phi, stl.Neg):
|
||||||
|
return stl.Neg(children[0])
|
||||||
|
elif isinstance(phi, stl.F):
|
||||||
|
return stl.F(phi.interval, children[0])
|
||||||
|
elif isinstance(phi, stl.G):
|
||||||
|
return stl.Neg(stl.F(phi.interval, children[0]))
|
||||||
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue