Commit a9423172 authored by Michele's avatar Michele
Browse files

added experts handling

parent 12d69d20
......@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](
- Validity of suspension automata.
- Testing algorithms
- Counterexample handling
- Algorithms for double sets in the table
## [v0.1.0] - 2015-09-29
### Added
......@@ -542,7 +542,8 @@ class LearningAlgorithm2Sets(LearningAlgorithm):
def __init__(self, teacher, oracle, tester, tablePreciseness = 1000,
modelPreciseness = 0.1, closeStrategy = None,
printPath = None, maxLoops=10, logger=None):
printPath = None, maxLoops=10, logger=None, outputPurpose=None,
LearningAlgorithm.__init__(self, teacher, oracle, tester,
modelPreciseness, closeStrategy,
......@@ -598,15 +598,38 @@ class Table:
class DoubleSetTable(Table):
def __init__(self, inputs, outputs, quiescence,
closeStrategy = None, logger=None):
closeStrategy = None, logger=None, outputPurpose=None,
Table.__init__(self, inputs, outputs, quiescence,
closeStrategy, logger)
# allows underspecification in inputs and outputs
self._outputPurpose = outputPurpose
self._inputPurpose = inputPurpose
# _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(),outputs.union(set((quiescence,))))}
self._entries = {():(set(),self._possibleOutputs(()))}
for label in self._inputs:
self._entries[tuple(label)] = (set(),outputs.union(set((quiescence,))))
self._entries[tuple(label)] = (set(),self._possibleOutputs(tuple(label)))
# given a trace, query outputPurpose for the outputs that are possibly
# enabled after it
def _possibleOutputs(self, trace):
if self._outputPurpose == None:
return self._outputs.union(set((self._quiescence,)))
return self._outputs.union(set((self._quiescence,)))
# given a trace, query inputPurpose for the inputs that are
# enabled after it
def _possibleInputs(self, trace):
if self._inputPurpose == None:
return self._inputs
return self._inputs
# get an empty nonfinal entry
def _emptyEntry(self):
# Abstract class for experts
from abc import ABCMeta, abstractmethod
class Purpose(metaclass=ABCMeta):
# Given a trace, return the set of enabled actions after that trace
def getEnabled(self, trace):
# Classes representing experts for input and output labels
from .basepurpose import Purpose
class InputPurpose(Purpose):
def __init__(self, inputs):
self._inputs = inputs.copy()
# Given a trace returns the set of inputs enabled after it.
def getEnabled(self, trace):
return self._inputs
class OutputPurpose(Purpose):
def __init__(self, outputs):
self._outputs = outputs.copy()
# Given a trace returns the set of outputs enabled after it.
def getEnabled(self, trace):
return self._outputs
......@@ -4,6 +4,7 @@ from import *
from learning.learning import LearningAlgorithm, LearningAlgorithm2Sets
from teachers.ltsteachers import InputOutputTeacher
from systems.implementations import InputOutputLTS
from systems.iopurpose import InputPurpose, OutputPurpose
from teachers.ltsoracles import InputOutputPowerOracle
import helpers.graphhelper as gh
import helpers.bisimulation as bi
......@@ -50,9 +51,15 @@ class TestLearningAlgorithm2:
self.T1 = InputOutputTeacher(self.I1)
self.O1 = InputOutputPowerOracle(self.I1)
self.tester = RandomTester(self.T1, 1000, 20)
self.tester = RandomTester(self.T1, 10000, 20)
self.L1 = LearningAlgorithm2Sets(self.T1, self.O1, self.tester, logger=logger)
outputExpert = OutputPurpose(outputs)
inputExpert = InputPurpose(inputs)
self.L1 = LearningAlgorithm2Sets(self.T1, self.O1, self.tester,
logger=logger, tablePreciseness = 10000, outputPurpose=outputExpert,
def creation_test(self):
Supports Markdown
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