Commit ac77db53 authored by Michele's avatar Michele

added placeholder for ALL OUTPUTS in table

parent c30fa82c
...@@ -34,10 +34,11 @@ import itertools ...@@ -34,10 +34,11 @@ import itertools
from tictacteacher import TicTacToeTeacher from tictacteacher import TicTacToeTeacher
from tictacoracle import TicTacToeOracle from tictacoracle import TicTacToeOracle
from tictacpurpose import InputPurpose, OutputPurpose from tictacpurpose import TicTacToeInputPurpose, TicTacToeOutputPurpose
from learning.learning import LearningAlgorithm from learning.learning import LearningAlgorithm
from testing.randomtesting import RandomTester from testing.randomtesting import RandomTester
from completetesting import CompleteTicTacToeTester
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -45,17 +46,21 @@ logger = logging.getLogger(__name__) ...@@ -45,17 +46,21 @@ logger = logging.getLogger(__name__)
HOST = 'localhost' HOST = 'localhost'
PORT = 29000 # Arbitrary non-privileged port PORT = 29000 # Arbitrary non-privileged port
outputExpert = TicTacToeOutputPurpose()
inputExpert = TicTacToeInputPurpose()
inputs = set(['0','1','2','3','4','5','6','7','8']) inputs = set(['0','1','2','3','4','5','6','7','8'])
outputs = set(itertools.product('XO_', repeat=9)) # Use a placeholder for outputs
quiescence = 'delta' outputs = outputExpert.allOutputs()
#outputs = set(itertools.product('XO_', repeat=9))
outputExpert = OutputPurpose() quiescence = 'delta'
inputExpert = InputPurpose()
T1 = TicTacToeTeacher(HOST, PORT) T1 = TicTacToeTeacher(HOST, PORT)
O1 = TicTacToeOracle() O1 = TicTacToeOracle(inputs, quiescence)
tester = RandomTester(T1, 100, 10) #tester = RandomTester(T1, 50000, 100)
tester = CompleteTicTacToeTester(T1)
currentdir = os.path.dirname(os.path.abspath( currentdir = os.path.dirname(os.path.abspath(
inspect.getfile(inspect.currentframe()))) inspect.getfile(inspect.currentframe())))
...@@ -67,7 +72,7 @@ print("Starting learning...") ...@@ -67,7 +72,7 @@ print("Starting learning...")
#print(T1.oneOutput(('1'))) #print(T1.oneOutput(('1')))
L = LearningAlgorithm(T1, O1, printPath=path, maxLoops=4, L = LearningAlgorithm(T1, O1, printPath=path, maxLoops=4,
tablePreciseness=10000, logger=logger, tester=tester, outputPurpose=outputExpert, tablePreciseness=100000, logger=logger, tester=tester, outputPurpose=outputExpert,
inputPurpose=inputExpert) inputPurpose=inputExpert)
minus, plus = L.run() minus, plus = L.run()
......
...@@ -31,13 +31,38 @@ import random ...@@ -31,13 +31,38 @@ import random
# TODO for the moment we keep SUL deterministic, simple oracle. # TODO for the moment we keep SUL deterministic, simple oracle.
class TicTacToeOracle(AbstractOracle): class TicTacToeOracle(AbstractOracle):
def __init__(self): def __init__(self, inputs, quiescence):
pass self._inputs = inputs.copy()
self._quiescence = quiescence
# Reply to an observation query # Reply to an observation query
# trace is a list of inputs and or outputs # trace is a list of inputs and or outputs
# outputs is the set of outputs observed so far (after trace) # outputs is the set of outputs observed so far (after trace)
def observation(self, trace, outputs): def observation(self, trace, outputs):
# If we already observed some outputs, then return True (determinism)
if len(outputs) > 0: if len(outputs) > 0:
return True return True
else:
# Check trace, if it has more outputs or more imputs in a row,
# then return True
if trace == ():
return False
# 0 = input, 1 = output
latest = 1
if trace[0] in self._inputs:
latest = 0
for i in range(1,len(trace)):
if trace[i] == self._quiescence:
continue
if trace[i] in self._inputs:
if latest == 0:
return True
else:
latest = 0
else:
if latest == 1:
return True
else:
latest = 1
return False return False
...@@ -28,7 +28,7 @@ sys.path.append(currentdir) ...@@ -28,7 +28,7 @@ sys.path.append(currentdir)
from systems.basepurpose import Purpose from systems.basepurpose import Purpose
import itertools import itertools
class InputPurpose(Purpose): class TicTacToeInputPurpose(Purpose):
def __init__(self): def __init__(self):
pass pass
...@@ -45,7 +45,7 @@ class InputPurpose(Purpose): ...@@ -45,7 +45,7 @@ class InputPurpose(Purpose):
else: else:
return inputs return inputs
class OutputPurpose(Purpose): class TicTacToeOutputPurpose(Purpose):
def __init__(self): def __init__(self):
pass pass
...@@ -61,4 +61,9 @@ class OutputPurpose(Purpose): ...@@ -61,4 +61,9 @@ class OutputPurpose(Purpose):
if (outputs != None and len(outputs) > 0): if (outputs != None and len(outputs) > 0):
return outputs return outputs
else: else:
# In this SUL we have many outputs (>4000)
# for this reason we use a placeholder
return 1
def allOutputs(self):
return set(itertools.product('XO_', repeat=9)) return set(itertools.product('XO_', repeat=9))
...@@ -422,7 +422,7 @@ if __name__ == "__main__": ...@@ -422,7 +422,7 @@ if __name__ == "__main__":
board = in_line_board() board = in_line_board()
if winner != 0: if winner != 0:
logger.debug("Sending: END ") logger.debug("We have a winner!")
board = board + " END" board = board + " END"
conn.sendall(bytes(board, 'UTF-8')) conn.sendall(bytes(board, 'UTF-8'))
newGame() newGame()
......
...@@ -39,6 +39,8 @@ class LearningAlgorithm: ...@@ -39,6 +39,8 @@ class LearningAlgorithm:
self._inputPurpose = inputPurpose self._inputPurpose = inputPurpose
self._outputPurpose = outputPurpose self._outputPurpose = outputPurpose
# If input (output) purpose is not defined, then add one that
# returns always all inputs (outputs)
if self._inputPurpose == None: if self._inputPurpose == None:
self._inputPurpose = InputPurpose(teacher.getInputAlphabet().copy()) self._inputPurpose = InputPurpose(teacher.getInputAlphabet().copy())
if self._outputPurpose == None: if self._outputPurpose == None:
......
...@@ -95,6 +95,8 @@ class RandomTester(AbstractTester): ...@@ -95,6 +95,8 @@ class RandomTester(AbstractTester):
model.reset() model.reset()
# return counterexample trace and output obtained by # return counterexample trace and output obtained by
# testing # testing
self._logger.info(ce)
self._logger.info(output)
return ce, output return ce, output
# reset # reset
self._teacher.reset() self._teacher.reset()
......
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