From e83cec371a406ff48903a1fa07f4ba8cbac5f309 Mon Sep 17 00:00:00 2001 From: Michele Date: Fri, 8 Jan 2016 15:33:34 +0100 Subject: [PATCH] added figure 2.5 from thesis --- CHANGELOG.md | 1 + README.md | 2 +- examples/figure2-5_thesis.py | 103 +++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 examples/figure2-5_thesis.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 85f15b7..629a0d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed - License +- Name: new name is Alnos ## [v0.2.0] - 2015-10-27 ### Added diff --git a/README.md b/README.md index 0e4a73c..b63cd3c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Synopsis -The active-learning-nondeterministic-systems is an implementation of an +**Alnos** is an implementation of an adaptation of [L*](http://www.cs.berkeley.edu/~dawnsong/teaching/s10/papers/angluin87.pdf) to nondeterministic systems. The code is based on these scientific papers: diff --git a/examples/figure2-5_thesis.py b/examples/figure2-5_thesis.py new file mode 100644 index 0000000..91e853d --- /dev/null +++ b/examples/figure2-5_thesis.py @@ -0,0 +1,103 @@ +# Copyright (c) 2015 Michele Volpato +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# This file is used to learn the IOTS depicted in Figure 2.5 of my PhD thesis. + +import random + +seed = output = random.sample(range(99999999), 1)[0] +print(seed) +random.seed(81077353) # 81077353 + +import os, inspect, sys +# Include project dir in path +currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +parentdir = os.path.dirname(currentdir) +sys.path.append(parentdir) +from learning.learning import LearningAlgorithm +from teachers.ltsteachers import InputOutputTeacher +from systems.implementations import InputOutputLTS +from teachers.ltsoracles import InputOutputPowerOracle +import logging +import helpers.bisimulation as bi +from testing.randomtesting import RandomTester +from systems.iopurpose import InputPurpose, OutputPurpose +import helpers.graphhelper as gh + + +logging.basicConfig(level=logging.DEBUG) +logger = logging.getLogger(__name__) + +inputs = set(['b']) +outputs = set(['t','c']) +quiescence = 'd' + +I1=InputOutputLTS(8, inputs, outputs, quiescence) +I1.addTransition(0,'b',1) +I1.addTransition(0,'b',2) +I1.addTransition(1,'t',3) +I1.addTransition(1,'c',3) +I1.addTransition(1,'b',6) +I1.addTransition(2,'b',4) +I1.addTransition(3,'t',0) +I1.addTransition(3,'c',0) +I1.addTransition(3,'b',6) +I1.addTransition(4,'c',5) +I1.addTransition(4,'b',6) +I1.addTransition(5,'b',6) +I1.addTransition(5,'t',0) +I1.addTransition(5,'c',0) + +# Chaos +I1.addTransition(6,'b',6) +I1.addTransition(6,'t',6) +I1.addTransition(6,'c',6) +I1.addTransition(6,'d',7) +I1.addTransition(7,'b',6) + + +I1.makeInputEnabled() + +T1 = InputOutputTeacher(I1) +O1 = InputOutputPowerOracle(I1) + +outputExpert = OutputPurpose(set(['t','c', quiescence])) +inputExpert = InputPurpose(set(['b'])) + +tester = RandomTester(T1, 10000, 50) + +currentdir = os.path.dirname(os.path.abspath( + inspect.getfile(inspect.currentframe()))) + +path = os.path.join(currentdir, "dotFiles") +gh.createDOTFile(I1, path + "figure2-5", "pdf") + +print("Starting learning...") + +# change printPath=None to printPath=path for dot files +L2 = LearningAlgorithm(T1, O1, printPath=path, maxLoops=4, + tablePreciseness=10000, logger=logger, tester=tester, outputPurpose=outputExpert, + inputPurpose=inputExpert) +minus, plus = L2.run() + +print("Models learned. Check language equivalence...") + +print("hMinus bisimilar to target: " + str(bi.bisimilar(I1,minus))) +print("hPlus bisimilar to target: " + str(bi.bisimilar(I1,plus))) -- GitLab