Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs598mp-fall2021-proj
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
chsieh16
cs598mp-fall2021-proj
Commits
8b74f63d
Commit
8b74f63d
authored
2 years ago
by
chsieh16
Browse files
Options
Downloads
Patches
Plain Diff
Reorder inheritance
parent
4bf0656f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dtree_synth.py
+3
-3
3 additions, 3 deletions
dtree_synth.py
dtree_teacher_base.py
+2
-17
2 additions, 17 deletions
dtree_teacher_base.py
gem_stanley_teacher.py
+16
-3
16 additions, 3 deletions
gem_stanley_teacher.py
with
21 additions
and
23 deletions
dtree_synth.py
+
3
−
3
View file @
8b74f63d
...
@@ -11,7 +11,7 @@ from typing import Dict, Hashable, List, Tuple
...
@@ -11,7 +11,7 @@ from typing import Dict, Hashable, List, Tuple
import
numpy
as
np
import
numpy
as
np
import
z3
import
z3
from
dtree_learner
import
DTreeLearner
as
Learner
from
dtree_learner
import
DTreeLearner
as
Learner
from
dtree_teacher_
gem_stanley
import
DTreeGEMStanleyGurobiTeacher
as
Teacher
from
gem_stanley
_teacher
import
DTreeGEMStanleyGurobiTeacher
as
Teacher
def
load_examples
(
file_name
:
str
,
spec
)
->
Tuple
[
List
[
Tuple
[
float
,
...]],
List
[
Tuple
[
float
,
...]]]:
def
load_examples
(
file_name
:
str
,
spec
)
->
Tuple
[
List
[
Tuple
[
float
,
...]],
List
[
Tuple
[
float
,
...]]]:
...
@@ -164,8 +164,8 @@ def main(dim:str, bnd_relax:float ):
...
@@ -164,8 +164,8 @@ def main(dim:str, bnd_relax:float ):
result
=
[]
result
=
[]
for
i
,
(
part
,
(
safe_dps
,
unsafe_dps
,
num_nan
))
in
enumerate
(
part_to_examples
.
items
()):
for
i
,
(
part
,
(
safe_dps
,
unsafe_dps
,
num_nan
))
in
enumerate
(
part_to_examples
.
items
()):
#
if not i == 1
4
:
if
not
i
==
1
:
#
continue
continue
print
(
"
#
"
*
80
)
print
(
"
#
"
*
80
)
print
(
f
"
# safe:
{
len
(
safe_dps
)
}
;
"
print
(
f
"
# safe:
{
len
(
safe_dps
)
}
;
"
...
...
This diff is collapsed.
Click to expand it.
dtree_teacher_
gem_stanley
.py
→
dtree_teacher_
base
.py
+
2
−
17
View file @
8b74f63d
...
@@ -3,10 +3,10 @@ import re
...
@@ -3,10 +3,10 @@ import re
import
gurobipy
as
gp
import
gurobipy
as
gp
import
z3
import
z3
from
gem_stanley_
teacher
import
GEMStanley
GurobiTeacher
from
teacher
_base
import
GurobiTeacher
Base
class
DTreeG
EMStanleyG
urobiTeacher
(
GEMStanley
GurobiTeacher
):
class
DTreeGurobiTeacher
Base
(
GurobiTeacher
Base
):
PRECISION
=
10
**-
3
PRECISION
=
10
**-
3
Z3_VAR_RE
=
re
.
compile
(
r
"
(?P<var>\w+)_(?P<idx>\d+)
"
)
Z3_VAR_RE
=
re
.
compile
(
r
"
(?P<var>\w+)_(?P<idx>\d+)
"
)
...
@@ -153,18 +153,3 @@ class DTreeGEMStanleyGurobiTeacher(GEMStanleyGurobiTeacher):
...
@@ -153,18 +153,3 @@ class DTreeGEMStanleyGurobiTeacher(GEMStanleyGurobiTeacher):
return
z3
.
sat
return
z3
.
sat
else
:
else
:
return
z3
.
unsat
return
z3
.
unsat
def
test_dtree_gem_stanley_gurobi_teacher
():
x_0
,
x_1
=
z3
.
Reals
(
"
x_0 x_1
"
)
candidate
=
z3
.
If
(
x_0
>=
0.2
,
z3
.
If
(
x_1
<=
1
,
z3
.
BoolVal
(
True
),
0.5
*
x_0
+
x_1
<=
3
),
0.5
*
x_0
+
x_1
>
3
)
teacher
=
DTreeGEMStanleyGurobiTeacher
(
norm_ord
=
2
)
print
(
teacher
.
check
(
candidate
))
print
(
teacher
.
model
())
if
__name__
==
"
__main__
"
:
test_dtree_gem_stanley_gurobi_teacher
()
This diff is collapsed.
Click to expand it.
gem_stanley_teacher.py
+
16
−
3
View file @
8b74f63d
...
@@ -6,7 +6,8 @@ import numpy as np
...
@@ -6,7 +6,8 @@ import numpy as np
import
sympy
import
sympy
import
z3
import
z3
from
teacher_base
import
GurobiTeacherBase
,
DRealTeacherBase
,
SymPyTeacherBase
from
teacher_base
import
DRealTeacherBase
,
SymPyTeacherBase
from
dtree_teacher_base
import
DTreeGurobiTeacherBase
WHEEL_BASE
=
1.75
# m
WHEEL_BASE
=
1.75
# m
...
@@ -79,7 +80,7 @@ class GEMStanleyDRealTeacher(DRealTeacherBase):
...
@@ -79,7 +80,7 @@ class GEMStanleyDRealTeacher(DRealTeacherBase):
])
])
class
GEMStanleyGurobiTeacher
(
GurobiTeacherBase
):
class
DTree
GEMStanleyGurobiTeacher
(
DTree
GurobiTeacherBase
):
# Ideal perception as a linear transform from state to ground truth percept
# Ideal perception as a linear transform from state to ground truth percept
PERC_GT
=
np
.
array
([[
0.
,
-
1.
,
0.
],
PERC_GT
=
np
.
array
([[
0.
,
-
1.
,
0.
],
[
0.
,
0.
,
-
1.
]],
float
)
[
0.
,
0.
,
-
1.
]],
float
)
...
@@ -309,7 +310,7 @@ def test_gem_stanley_sympy_teacher():
...
@@ -309,7 +310,7 @@ def test_gem_stanley_sympy_teacher():
def
test_gem_stanley_gurobi_teacher
():
def
test_gem_stanley_gurobi_teacher
():
teacher
=
GEMStanleyGurobiTeacher
(
ultimate_bound
=
.
4
)
teacher
=
DTree
GEMStanleyGurobiTeacher
(
ultimate_bound
=
.
4
)
teacher
.
set_old_state_bound
(
teacher
.
set_old_state_bound
(
lb
=
(
-
np
.
inf
,
0.5
,
0.0625
),
lb
=
(
-
np
.
inf
,
0.5
,
0.0625
),
ub
=
(
np
.
inf
,
1.0
,
0.25
)
ub
=
(
np
.
inf
,
1.0
,
0.25
)
...
@@ -317,6 +318,18 @@ def test_gem_stanley_gurobi_teacher():
...
@@ -317,6 +318,18 @@ def test_gem_stanley_gurobi_teacher():
teacher
.
dump_system_encoding
()
teacher
.
dump_system_encoding
()
def
test_dtree_gem_stanley_gurobi_teacher
():
x_0
,
x_1
=
z3
.
Reals
(
"
x_0 x_1
"
)
candidate
=
z3
.
If
(
x_0
>=
0.2
,
z3
.
If
(
x_1
<=
1
,
z3
.
BoolVal
(
True
),
0.5
*
x_0
+
x_1
<=
3
),
0.5
*
x_0
+
x_1
>
3
)
teacher
=
DTreeGEMStanleyGurobiTeacher
(
norm_ord
=
2
)
print
(
teacher
.
check
(
candidate
))
print
(
teacher
.
model
())
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
test_gem_stanley_gurobi_teacher
()
test_gem_stanley_gurobi_teacher
()
# test_gem_stanley_sympy_teacher()
# test_gem_stanley_sympy_teacher()
test_dtree_gem_stanley_gurobi_teacher
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment