Commit a84b8477 authored by Michele's avatar Michele

fixed: input labels were added to rows even if not enabled

parent 78a4eb51
......@@ -59,14 +59,14 @@ class LearningAlgorithm:
trie = th.make_trie(oTraces)
# Until we tried K times with no results
K = len(oTraces) * 100 # TODO: should not be hardcoded
K = len(oTraces) * 150 # TODO: should not be hardcoded
found = 0
tries = 0
while tries < K:
#print(tries + 1)
tries += 1
oTraces = self._table.getObservableTraces()
#prefixes = th.getPrefixes(oTraces)
trie = th.make_trie(oTraces)
subtrie = trie
......@@ -84,8 +84,6 @@ class LearningAlgorithm:
# 2 - there is no continuation of that trace in prefixes
# We stop when we observed at least an output for each observable
while len(oTraces) > len(observations.keys()): #and i < K:
#print("Missing traces: "+str(len(oTraces) - len(observations.keys())))
#print(trie)
i += 1
# check if trie contains no traces (but still has a child)
......@@ -126,7 +124,6 @@ class LearningAlgorithm:
# if that output is not a valid continuation
if output not in subtrie.keys():
#print("Cannot continue with that output, reset")
# reset the process
currentTrace = ()
subtrie = trie
......@@ -342,6 +339,7 @@ class LearningAlgorithm:
found = True
break
if not found:
self._logger.warning("Chaotic behaviour")
# Either the table is not closed, or
# First column of extension has an empty set.
# If label is an input, then send it to ChaosDelta
......@@ -351,7 +349,7 @@ class LearningAlgorithm:
if label in self._teacher.getInputAlphabet():
hyp.addTransition(assignments[row], label,
hyp.getChaosDelta())
else:
elif label in self._table.getPossibleOutputs(row):
hyp.addTransition(assignments[row], label,
hyp.getChaos())
elif (len(row) > 0 and
......@@ -361,7 +359,8 @@ class LearningAlgorithm:
# a sequence of quiescence
hyp.addTransition(assignments[row], label,
assignments[row])
elif (chaos and label in self._teacher.getOutputAlphabet()):
elif (chaos and label in self._table.getPossibleOutputs(row)):
self._logger.warning("Chaotic behaviour 2")
# Add transitions to chaotic state if necessary
if row in self._table.getObservableTraces():
if label != hyp.getQuiescence():
......
......@@ -22,7 +22,7 @@ class Table:
# actions
self._columns = set()
self._columns.add(())
# _rows also contains one letter extensions
# _rows also contains empty trace
self._rows = set()
self._rows.add(())
for label in self._inputs:
......@@ -526,6 +526,13 @@ class Table:
return outputs
# Return the set of outputs that can be observed after trace
def getPossibleOutputs(self, trace):
if trace in self._entries and self._entries[trace][1]:
return self._entries[trace][0]
else:
return self._outputs.union(set(self._quiescence))
# Update an entry in the table. If it does not exist, create it
def updateEntry(self, trace, output=None, observation=None):
trace = th.flatten(trace, self._quiescence)
......@@ -603,6 +610,11 @@ class DoubleSetTable(Table):
self._outputPurpose = outputPurpose
self._inputPurpose = inputPurpose
self._rows = set()
self._rows.add(())
for label in self._inputPurpose.getEnabled(()):
self._rows.add(tuple(label))
# _entries is a dictionary (tuple of actions) -> (set(outputs), set(outputs))
# start with the empty sequence of actions and one letter extensions
self._entries = {():(set(),self._possibleOutputs(()))}
......@@ -745,7 +757,7 @@ class DoubleSetTable(Table):
# the first entry is emptyEntry.
# In this case (it can only be an input) we
# send the input to chaotic_delta
if self._entries[current[0] + (label,)] == self._emptyEntry:
if self._entries[current[0] + (label,)] == self._emptyEntry(current[0] + (label,)):
newRow1 = "chaos_quiescence"
else:
self._logger.error("Quiescence reducibility check: cannot obtain new pair of states. Row1: "
......
......@@ -19,7 +19,7 @@ class TestLearningAlgorithm2:
logger = logging.getLogger(__name__)
inputs = set(['a','b', 'c', 'd'])
outputs = set(['x','y','z'])
outputs = set(['x','y','z', 'k'])
quiescence = 'delta'
self.I1=InputOutputLTS(5, inputs, outputs, quiescence)
......@@ -53,7 +53,7 @@ class TestLearningAlgorithm2:
self.tester = RandomTester(self.T1, 10000, 60)
outputExpert = OutputPurpose(set(['x','y']))
outputExpert = OutputPurpose(set(['x','y', 'k']))
inputExpert = InputPurpose(set(['a','b']))
currentdir = os.path.dirname(os.path.abspath(
......
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