Commit 79ec49b9 authored by Michele's avatar Michele

fixed error in get equivalence classes

parent 9cd3ac7c
......@@ -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 hipotheses with table not \
self._logger.error("Tried to get hypotheses with table not \
closed or not consistent")
return None, None
# Get equivalence classes
......
......@@ -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 entry do not exist.
# for some reason both entries 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:
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment