Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Michele Volpato
Alnos
Commits
79ec49b9
Commit
79ec49b9
authored
Nov 04, 2015
by
Michele
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed error in get equivalence classes
parent
9cd3ac7c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
7 deletions
+19
-7
learning/learning.py
learning/learning.py
+1
-1
learning/observationtable.py
learning/observationtable.py
+14
-2
tests/learning_algorithm_test.py
tests/learning_algorithm_test.py
+4
-4
No files found.
learning/learning.py
View file @
79ec49b9
...
...
@@ -313,7 +313,7 @@ class LearningAlgorithm:
def
getHypothesis
(
self
,
chaos
=
False
):
# If table is not closed, ERROR
if
self
.
_table
.
isNotGloballyClosed
():
self
.
_logger
.
error
(
"Tried to get h
i
potheses with table not
\
self
.
_logger
.
error
(
"Tried to get h
y
potheses with table not
\
closed or not consistent"
)
return
None
,
None
# Get equivalence classes
...
...
learning/observationtable.py
View file @
79ec49b9
...
...
@@ -93,13 +93,23 @@ class Table:
# () is always in the equivalence classes
rows
=
set
()
rows
.
add
(())
# for each row in S, check if there is a singleRow in equivalence classes that is
# more specific, if not, add row to equivalence classes.
#
# for each singleRow in equivalence classes check if row is more specific than singleRow
# if so, remove singleRow and add row.
for
row
in
self
.
_rowsInS
-
set
(()):
found
=
False
for
singleRow
in
rows
:
if
self
.
_moreSpecificRow
(
row
,
singleRow
,
plus
):
if
self
.
_moreSpecificRow
(
singleRow
,
row
,
plus
):
found
=
True
break
if
not
found
:
toBeRemoved
=
set
()
for
singleRow
in
rows
:
if
self
.
_moreSpecificRow
(
row
,
singleRow
,
plus
):
toBeRemoved
.
add
(
singleRow
)
rows
=
rows
-
toBeRemoved
rows
.
add
(
row
)
return
rows
...
...
@@ -623,6 +633,7 @@ class Table:
return
self
.
_inputPurpose
.
getEnabled
(
trace
)
# Given two entries, check if the former is more specific than the latter
# entry1 ⊑ entry2 => entry2.first is subset of entry1.first and entry1.second is subset of entry2.second
def
_moreSpecificEntry
(
self
,
entry1
,
entry2
,
plus
):
if
not
plus
:
return
entry1
[
0
]
==
entry2
[
0
]
...
...
@@ -632,6 +643,7 @@ class Table:
return
(
entry2
[
0
].
issubset
(
entry1
[
0
])
and
entry1
[
1
].
issubset
(
entry2
[
1
]))
# Given two rows, check if the former is more specific than the latter
# row1 ⊑ row2 => for each column, row1[column] ⊑ row2[column]
def
_moreSpecificRow
(
self
,
row1
,
row2
,
plus
=
False
):
# First: if they do not enable the same inputs, they are not in such
# a relation
...
...
@@ -645,7 +657,7 @@ class Table:
entry1
=
th
.
flatten
(
row1
+
column
,
self
.
_quiescence
)
entry2
=
th
.
flatten
(
row2
+
column
,
self
.
_quiescence
)
if
entry1
not
in
self
.
_entries
and
entry2
not
in
self
.
_entries
:
# for some reason both entr
y
do not exist.
# for some reason both entr
ies
do not exist.
self
.
_logger
.
warning
(
"Checking relation between rows: both entries are not defined."
)
continue
elif
entry1
not
in
self
.
_entries
or
entry2
not
in
self
.
_entries
:
...
...
tests/learning_algorithm_test.py
View file @
79ec49b9
...
...
@@ -79,16 +79,16 @@ class TestLearningAlgorithm2:
def
table_row_equality_test
(
self
):
self
.
_Hminus
,
self
.
_Hplus
=
self
.
L1
.
run
()
equal
=
self
.
L1
.
_table
.
_
rowEquality
((
'delta'
,),
(
'b'
,),
True
)
equal
=
self
.
L1
.
_table
.
_
moreSpecificRow
((
'delta'
,),
(
'b'
,),
True
)
assert_equal
(
equal
,
True
)
# Actually, next test might fail if _noEffectLimit in learning.py is small
equal
=
self
.
L1
.
_table
.
_
rowEquality
((
'a'
,),
(
'b'
,),
True
)
equal
=
self
.
L1
.
_table
.
_
moreSpecificRow
((
'a'
,),
(
'b'
,),
True
)
assert_equal
(
equal
,
False
)
# Test also other equality check
equal
=
self
.
L1
.
_table
.
_
rowEquality
((
'delta'
,),
(
'b'
,))
equal
=
self
.
L1
.
_table
.
_
moreSpecificRow
((
'delta'
,),
(
'b'
,))
assert_equal
(
equal
,
True
)
# Actually, next test might fail if _noEffectLimit in learning.py is small
equal
=
self
.
L1
.
_table
.
_
rowEquality
((
'a'
,),
(
'b'
,))
equal
=
self
.
L1
.
_table
.
_
moreSpecificRow
((
'a'
,),
(
'b'
,))
assert_equal
(
equal
,
False
)
assert_not_in
((
'b'
,),
self
.
L1
.
_table
.
_rowsInS
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment