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
44914951
Commit
44914951
authored
3 years ago
by
chsieh16
Browse files
Options
Downloads
Patches
Plain Diff
Add functions to convert samples to feature vectors
parent
372ccd1f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dtree_learner.py
+39
-0
39 additions, 0 deletions
dtree_learner.py
with
39 additions
and
0 deletions
dtree_learner.py
0 → 100644
+
39
−
0
View file @
44914951
from
typing
import
Tuple
import
numpy
as
np
STATE_DIM
=
3
PERC_DIM
=
2
def
construct_sample_to_feature_func
(
lin_trans
):
a_mat
,
b_vec
=
lin_trans
def
sample_to_feature_vec
(
sample
):
assert
len
(
sample
)
==
STATE_DIM
+
PERC_DIM
state
=
sample
[
0
:
STATE_DIM
]
perc
=
sample
[
STATE_DIM
:
STATE_DIM
+
PERC_DIM
]
perc_bar
=
perc
-
np
.
dot
(
state
,
a_mat
.
T
)
+
b_vec
return
perc_bar
return
sample_to_feature_vec
def
test_sample_to_feature
():
lin_trans
=
(
np
.
array
([[
0.
,
-
1.
,
0.
],
# a_mat
[
0.
,
0.
,
-
1
]]),
np
.
zeros
(
2
)
# b_vec
)
sample_to_feature_func
=
construct_sample_to_feature_func
(
lin_trans
)
sample
=
np
.
array
([
1.
,
2.
,
3.
,
-
2.
,
-
3.
])
feature_vec
=
sample_to_feature_func
(
sample
)
assert
np
.
array_equal
(
feature_vec
,
np
.
array
([
0.
,
0.
]))
sample
=
np
.
array
([
1.
,
2.
,
3.
,
-
1.
,
-
2.
])
feature_vec
=
sample_to_feature_func
(
sample
)
assert
np
.
array_equal
(
feature_vec
,
np
.
array
([
1.
,
1.
]))
if
__name__
==
"
__main__
"
:
test_sample_to_feature
()
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