Skip to content
Snippets Groups Projects
Commit 4bf0656f authored by chsieh16's avatar chsieh16
Browse files

Move spurious check to TeacherBase

parent b7293ccb
No related branches found
No related tags found
No related merge requests found
...@@ -31,12 +31,6 @@ NEW_ATAN_K_CTE_V_LIM = np.arctan(NEW_K_CTE_V_LIM) ...@@ -31,12 +31,6 @@ NEW_ATAN_K_CTE_V_LIM = np.arctan(NEW_K_CTE_V_LIM)
NEW_RAW_ANG_ERR_LIM = ANG_LIM + FORWARD_VEL * CYCLE_TIME NEW_RAW_ANG_ERR_LIM = ANG_LIM + FORWARD_VEL * CYCLE_TIME
def z3_float64_const_to_real(v: float) -> z3.RatNumRef:
return z3.simplify(
z3.fpToReal(z3.FPVal(v, z3.Float64()))
)
class GEMStanleyDRealTeacher(DRealTeacherBase): class GEMStanleyDRealTeacher(DRealTeacherBase):
def __init__(self, name="gem_stanley", norm_ord=2, delta=0.001) -> None: def __init__(self, name="gem_stanley", norm_ord=2, delta=0.001) -> None:
...@@ -90,20 +84,6 @@ class GEMStanleyGurobiTeacher(GurobiTeacherBase): ...@@ -90,20 +84,6 @@ class GEMStanleyGurobiTeacher(GurobiTeacherBase):
PERC_GT = np.array([[0., -1., 0.], PERC_GT = np.array([[0., -1., 0.],
[0., 0., -1.]], float) [0., 0., -1.]], float)
@staticmethod
def is_spurious_example(state_dim: int, perc_dim: int, candidate: z3.BoolRef, cex: Tuple[float, ...]) -> bool:
state_subs_map = [(z3.Real(f"x_{i}"), z3_float64_const_to_real(cex[i])) for i in range(state_dim)]
perc_subs_map = [(z3.Real(f"z_{i}"), z3_float64_const_to_real(cex[i+state_dim])) for i in range(perc_dim)]
sub_map = state_subs_map + perc_subs_map
val = z3.simplify(z3.substitute(candidate, *sub_map))
assert z3.is_bool(val)
if z3.is_false(val):
return True
elif z3.is_true(val):
return False
else:
raise RuntimeError(f"Cannot validate negative example {cex} by substitution")
def __init__(self, name="gem_stanley", norm_ord=2, ultimate_bound: float=0.0) -> None: def __init__(self, name="gem_stanley", norm_ord=2, ultimate_bound: float=0.0) -> None:
assert ultimate_bound >= 0.0 assert ultimate_bound >= 0.0
self._ultimate_bound = ultimate_bound self._ultimate_bound = ultimate_bound
......
...@@ -10,7 +10,28 @@ import z3 ...@@ -10,7 +10,28 @@ import z3
import dreal import dreal
def z3_float64_const_to_real(v: float) -> z3.RatNumRef:
return z3.simplify(
z3.fpToReal(z3.FPVal(v, z3.Float64()))
)
class TeacherBase(abc.ABC): class TeacherBase(abc.ABC):
@staticmethod
def is_spurious_example(state_dim: int, perc_dim: int, candidate: z3.BoolRef, cex: Tuple[float, ...]) -> bool:
state_subs_map = [(z3.Real(f"x_{i}"), z3_float64_const_to_real(cex[i])) for i in range(state_dim)]
perc_subs_map = [(z3.Real(f"z_{i}"), z3_float64_const_to_real(cex[i+state_dim])) for i in range(perc_dim)]
sub_map = state_subs_map + perc_subs_map
val = z3.simplify(z3.substitute(candidate, *sub_map))
assert z3.is_bool(val)
if z3.is_false(val):
return True
elif z3.is_true(val):
return False
else:
raise RuntimeError(f"Cannot validate negative example {cex} by substitution")
def __init__(self) -> None: def __init__(self) -> None:
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment