Commit ac77db53 authored by Michele's avatar Michele

added placeholder for ALL OUTPUTS in table

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