From 1b76707a792f12f109ecfbd13a93b22bb9007d5f Mon Sep 17 00:00:00 2001 From: Michele Volpato Date: Mon, 18 Sep 2017 17:15:42 +0200 Subject: [PATCH] working on old example for deterministic tictactoe, problem with placeholder and output generation --- examples/tictactoe/completetesting.py | 3 ++- examples/tictactoe/learn.py | 2 +- examples/tictactoe/tictacoracle.py | 2 +- examples/tictactoe/tictacpurpose.py | 14 +++++++------- examples/tictactoe/tictacteacher.py | 2 +- learning/learning.py | 10 +++++++--- learning/observationtable.py | 2 +- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/tictactoe/completetesting.py b/examples/tictactoe/completetesting.py index cb3bbdf..90d08fb 100644 --- a/examples/tictactoe/completetesting.py +++ b/examples/tictactoe/completetesting.py @@ -52,7 +52,8 @@ class CompleteTicTacToeTester(AbstractTester): model.move(action) if output not in model.outputs(): self._logger.info("Found a counterexample: " - + str(ce) + " output: "+str(output)) + + str(ce) + " output: "+str(output)+ + " not in " + str(model.outputs())) self._teacher.reset() model.reset() diff --git a/examples/tictactoe/learn.py b/examples/tictactoe/learn.py index 75e26ee..a8ff4a3 100644 --- a/examples/tictactoe/learn.py +++ b/examples/tictactoe/learn.py @@ -45,7 +45,7 @@ import helpers.bisimulation as bi import csv -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) HOST = 'localhost' diff --git a/examples/tictactoe/tictacoracle.py b/examples/tictactoe/tictacoracle.py index 34ae34f..22ad2d2 100644 --- a/examples/tictactoe/tictacoracle.py +++ b/examples/tictactoe/tictacoracle.py @@ -43,7 +43,7 @@ class TicTacToeOracle(AbstractOracle): if len(outputs) > 0: return True else: - # Check trace, if it has more outputs or more imputs in a row, + # Check trace, if it has more outputs or more inputs in a row, # then return True if trace == (): return False diff --git a/examples/tictactoe/tictacpurpose.py b/examples/tictactoe/tictacpurpose.py index a651b07..60dd651 100644 --- a/examples/tictactoe/tictacpurpose.py +++ b/examples/tictactoe/tictacpurpose.py @@ -58,23 +58,23 @@ class TicTacToeOutputPurpose(Purpose): if (trace != None and len(trace) > 0 and trace[-1] not in inputs): return set(['delta']) else: - if (outputs != None and len(outputs) > 0): - return outputs - else: + #if (outputs != None and len(outputs) > 0): + # return outputs + #else: # In this SUL we have many outputs (>4000) # for this reason we use a placeholder # We also need a way to compare a set of outputs with the # placeholder - return 'PLACEHOLDER' + return set(['PLACEHOLDER']) def isIncluded(self, set1, set2): - if set2 == 'PLACEHOLDER': + if 'PLACEHOLDER' in set2: return True else: - if set1 == 'PLACEHOLDER': + if 'PLACEHOLDER' in set1: return False else: return set1.issubset(set2) def allOutputs(self): - return set(itertools.product('XO_', repeat=9)) + return set(map(''.join, itertools.product('XO_', repeat=9))) diff --git a/examples/tictactoe/tictacteacher.py b/examples/tictactoe/tictacteacher.py index 84ccbbb..dcd70b5 100644 --- a/examples/tictactoe/tictacteacher.py +++ b/examples/tictactoe/tictacteacher.py @@ -42,7 +42,7 @@ class TicTacToeTeacher(AbstractTeacher): self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.connect((host, port)) - self._outputs = set(itertools.product('XO_', repeat=9)) + self._outputs = set(map(''.join, itertools.product('XO_', repeat=9))) # counter for inputs: self._count = 0 diff --git a/learning/learning.py b/learning/learning.py index b8b9011..c68bd34 100644 --- a/learning/learning.py +++ b/learning/learning.py @@ -318,7 +318,7 @@ class LearningAlgorithm: def getHypothesis(self, chaos=False): # If table is not closed, ERROR if self._table.isNotGloballyClosed(): - self._logger.error("Tried to get hypotheses with table not closed") + self._logger.warning("Trying to create a model from a not closed table") return None, None # Get equivalence classes rows = self._table.getEquivalenceClasses(chaos) @@ -330,7 +330,7 @@ class LearningAlgorithm: # assign to each equivalence class a state number # start with equivalence class of empty trace to 0 # TODO: is () always the representative of an equivalence class? - # NO + # NO, we might have more than one row representing (). TODO: FIX rowForEmpty = () # search for the representative for () for row in rows: @@ -338,6 +338,8 @@ class LearningAlgorithm: # private. Change to public, or add a public version if self._table._moreSpecificRow(row, rowForEmpty, chaos): rowForEmpty = row + self._logger.debug("Creating " + ("HPlus" if chaos else "HMinus") + + ": Row representing (): " + str(row)) break assignments = {rowForEmpty:0} @@ -351,7 +353,7 @@ class LearningAlgorithm: for row in rows: enabledOuptuts = self._table.getOutputs(row) allLabels = self._getAllLabels(row, enabledOuptuts) - + self._logger.debug("All labels: "+ str(allLabels)) for label in allLabels: # create row and search it in the table extension = row + (label,) @@ -408,6 +410,8 @@ class LearningAlgorithm: if self._outputPurpose != None: enabledOutputs = self._outputPurpose.getEnabled(row) allLabels = enabledInputs.union(enabledOutputs) + self._logger.debug("enabledInputs: "+ str(enabledInputs)) + self._logger.debug("enabledOutputs: "+ str(enabledOutputs)) return allLabels # Generate DOT files for hypotheses. hyp = hMinus|hPlus|both diff --git a/learning/observationtable.py b/learning/observationtable.py index e3c5411..ec93670 100644 --- a/learning/observationtable.py +++ b/learning/observationtable.py @@ -753,7 +753,7 @@ class Table: outputs1 = self._entries[th.flatten(row1,self._quiescence)][0] outputs2 = self._entries[th.flatten(row2,self._quiescence)][0] - # If they enable the same inputs, check each entry. + # Check each entry. for column in self._columns: entry1 = th.flatten(row1 + column, self._quiescence) entry2 = th.flatten(row2 + column, self._quiescence) -- GitLab