Commit c56b0130 authored by Michele's avatar Michele

added read_table, started fixing an error in consistency check

parent 2f1c022e
......@@ -71,7 +71,7 @@ class LearningAlgorithm:
trie = th.make_trie(oTraces)
# Until we tried K times with no results
K = len(oTraces) #* 5 # TODO: should not be hardcoded
K = len(oTraces) * 2 # TODO: should not be hardcoded, maybe the number of output is a good indication for this?
found = 0
tries = 0
while tries < K:
......
......@@ -403,7 +403,7 @@ class Table:
return newSuffixes.union(hPlusSuffixes)
def _isNotConsistent(self, chaos=False):
# TODO refactor entire method?
# get all combinations of rows in S, with repetitions
combi = permutations(self._rowsInS, 2)
newColumns = set()
......@@ -423,10 +423,30 @@ class Table:
# rowExt1 must be in Rows, because label is either an
# enabled input after row, or an observed output.
if rowExt1 not in self._rows:
self._logger.error("Error while checking consistency: the prefix "+str(rowExt1)+" should be a row, but it is not.")
self.printTable(prefix="_error")
self._logger.error("Table printed in ./tables/_error_table.csv")
raise
# It might be that rowExt1 is not in rows because it ends
# with an output that row1 did not enabled yet.
# This is possible only if chaos == True, and only because
# of _moreSpecificRow()
if chaos == False:
# if we are checking Hminus, then there is an error
self._logger.error("Error while checking consistency for Hminus: the prefix "+str(rowExt1)+" should be a row, but it is not.")
self.printTable(prefix="_error")
self._logger.error("Table printed in ./tables/_error_table.csv")
raise
else:
# if we are checking Hplus (and label is an output)
# then there is a transition to a chaotic state
if label in self._possibleOutputs(row1):
if label == self._quiescence:
# rowExt1 is chaos_quiescence
rowExt1 = "chaos_quiescence"
else:
# rowExt1 is chaos
rowExt1 = "chaos"
else:
self._logger.error("Error while checking consistency for Hplus: the prefix "+str(rowExt1)+" should be a row, but it is not.")
self.printTable(prefix="_error")
self._logger.error("Table printed in ./tables/_error_table.csv")
if not rowExt2 in self._rows:
# rowExt2 is not in rows. If label is an input then
# row2 does not enable it: row1 should not be more
......@@ -448,8 +468,14 @@ class Table:
# It is better to do it directly.
for column in self._columns:
entry1 = th.flatten(rowExt1 + column, self._quiescence)
entry2 = th.flatten(rowExt2 + column, self._quiescence)
if (rowExt1 == "chaos_quiescence" or rowExt1 == "chaos"):
#TODO: check if entry2+column has chaotic behaviour
print(erfefr)
continue
entry1 = th.flatten(rowExt1 + column, self._quiescence)
if (entry1 not in self._entries and
entry2 not in self._entries):
# for some reason both entry do not exist.
......
from nose.tools import *
from learning.learning import Table
import os, inspect, sys
from teachers.ltsteachers import InputOutputTeacher
from systems.implementations import InputOutputLTS
from teachers.ltsoracles import InputOutputPowerOracle
from systems.iopurpose import InputPurpose, OutputPurpose
class TestTableReader:
def setUp(self):
pass
def read_test(self):
inputs = set(['a','b', 'c', 'd'])
outputs = set(['x','y','z', 'k'])
quiescence = 'delta'
I1=InputOutputLTS(5, inputs, outputs, quiescence)
I1.addTransition(0,'a',1)
I1.addTransition(0,'a',2)
I1.addTransition(0,'b',0)
I1.addTransition(1,'a',0)
I1.addTransition(1,'b',3)
I1.addTransition(2,'a',0)
I1.addTransition(2,'b',3)
I1.addTransition(2,'x',4)
I1.addTransition(3,'a',0)
I1.addTransition(3,'x',4)
I1.addTransition(3,'b',3)
I1.addTransition(4,'y',2)
I1.addTransition(4,'b',4)
I1.addTransition(4,'a',0)
I1.addTransition(4,'x',0)
I1.addTransition(1,'a',0)
I1.addTransition(3,'b',1)
I1.addTransition(3,'a',0)
I1.addTransition(4,'b',2)
I1.addTransition(2,'a',3)
I1.addTransition(4,'y',0)
T1 = InputOutputTeacher(I1)
O1 = InputOutputPowerOracle(I1)
outputExpert = OutputPurpose(set(['x','y', quiescence]))
inputExpert = InputPurpose(set(['a','b']))
currentdir = os.path.dirname(os.path.abspath(
inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
path = os.path.join(parentdir, "learning", "tables", "_error_table.csv")
table = Table(T1.getInputAlphabet().copy(),
T1.getOutputAlphabet().copy(),
T1.getQuiescence(),
closeStrategy=None,
outputPurpose=outputExpert,
inputPurpose=inputExpert)
table._loadTable(path)
path = os.path.join(parentdir, "learning")
table.printTable(path=path, prefix='TEST')
moreSpecific = lambda x: lambda y: table._moreSpecificRow(y, x, False)
listOfRows = list(filter(moreSpecific(('a', 'x', 'y', 'a', 'delta') + ('a',)), table._rowsInS))
print(listOfRows)
print(table.isNotGloballyClosed())
assert_equal(listOfRows == [], False)
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