Commit 5823f7c1 authored by Michele's avatar Michele

added statistics to learning tic tac toe

parent 293473bd
...@@ -69,7 +69,7 @@ class CompleteTicTacToeTester(AbstractTester): ...@@ -69,7 +69,7 @@ class CompleteTicTacToeTester(AbstractTester):
def _processInputs(self, consecutiveInputs): def _processInputs(self, consecutiveInputs):
if consecutiveInputs != (): if consecutiveInputs != ():
output = self._teacher.oneOutput(consecutiveInputs) output = self._teacher.oneOutputForTesting(consecutiveInputs)
if output == None: if output == None:
return None return None
return output return output
......
...@@ -82,6 +82,7 @@ L = LearningAlgorithm(T1, O1, printPath=path, maxLoops=4, ...@@ -82,6 +82,7 @@ L = LearningAlgorithm(T1, O1, printPath=path, maxLoops=4,
minus, plus = L.run() minus, plus = L.run()
print("Models learned.") print("Models learned.")
print("Number of inputs sent to the SUL: " + str(T1.getInputCounter()))
T1.close() T1.close()
......
This diff is collapsed.
This diff is collapsed.
...@@ -44,10 +44,10 @@ import de.learnlib.eqtests.basic.CompleteExplorationEQOracle; ...@@ -44,10 +44,10 @@ import de.learnlib.eqtests.basic.CompleteExplorationEQOracle;
import de.learnlib.eqtests.basic.RandomWordsEQOracle; import de.learnlib.eqtests.basic.RandomWordsEQOracle;
import de.learnlib.eqtests.basic.WMethodEQOracle.MealyWMethodEQOracle; import de.learnlib.eqtests.basic.WMethodEQOracle.MealyWMethodEQOracle;
import de.learnlib.experiments.Experiment.MealyExperiment; import de.learnlib.experiments.Experiment.MealyExperiment;
import de.learnlib.oracles.ResetCounterSUL;
import de.learnlib.oracles.SULOracle; import de.learnlib.oracles.SULOracle;
import de.learnlib.statistics.SimpleProfiler; import de.learnlib.statistics.SimpleProfiler;
import de.learnlib.statistics.StatisticSUL; import de.learnlib.statistics.StatisticSUL;
import nl.ru.cs.mvolpato.tictaclearnlib.InputCounterSUL;
public class TicTacToeLearner { public class TicTacToeLearner {
...@@ -96,13 +96,18 @@ public class TicTacToeLearner { ...@@ -96,13 +96,18 @@ public class TicTacToeLearner {
SUL<String,String> sul = new SULAdapter(); SUL<String,String> sul = new SULAdapter();
// oracle for counting queries wraps sul // oracle for counting queries wraps sul
StatisticSUL<String, String> statisticSul = new ResetCounterSUL<>("membership queries", sul); StatisticSUL<String, String> statisticSul = new InputCounterSUL<>("inputs", sul);
SUL<String,String> effectiveSul = statisticSul; SUL<String,String> effectiveSul = statisticSul;
// use caching in order to avoid duplicate queries // use caching in order to avoid duplicate queries
effectiveSul = Caches.createSULCache(inputs, effectiveSul); effectiveSul = Caches.createSULCache(inputs, effectiveSul);
// Membership Oracle for learning
SULOracle<String, String> mqOracle = new SULOracle<>(effectiveSul); SULOracle<String, String> mqOracle = new SULOracle<>(effectiveSul);
// Different Membership Oracle for testing. Doing this because I want to count inputs for learning only
SULOracle<String, String> mqTestingOracle = new SULOracle<>(sul);
// create initial set of suffixes // create initial set of suffixes
List<Word<String>> suffixes = new ArrayList<>(); List<Word<String>> suffixes = new ArrayList<>();
...@@ -123,7 +128,7 @@ public class TicTacToeLearner { ...@@ -123,7 +128,7 @@ public class TicTacToeLearner {
// create random words equivalence test // create random words equivalence test
RandomWordsEQOracle<String, Word<String>, MealyMachine<?,String,?,String>> randomWords = RandomWordsEQOracle<String, Word<String>, MealyMachine<?,String,?,String>> randomWords =
new RandomWordsEQOracle<String, Word<String>, MealyMachine<?,String,?,String>>( new RandomWordsEQOracle<String, Word<String>, MealyMachine<?,String,?,String>>(
mqOracle, mqTestingOracle,
3, // int minLength 3, // int minLength
8, // int maxLength 8, // int maxLength
1000, // int maxTests 1000, // int maxTests
...@@ -133,16 +138,16 @@ public class TicTacToeLearner { ...@@ -133,16 +138,16 @@ public class TicTacToeLearner {
// create complete exploration equivalence test // create complete exploration equivalence test
CompleteExplorationEQOracle<String, Word<String>> completeOracle = CompleteExplorationEQOracle<String, Word<String>> completeOracle =
new CompleteExplorationEQOracle<>( new CompleteExplorationEQOracle<>(
mqOracle, // a membership oracle mqTestingOracle, // a membership oracle
3, // int minDepth 5, // int minDepth
6 // int maxDepth 5 // int maxDepth
); );
// create equivalence oracle based on the W method // create equivalence oracle based on the W method
MealyWMethodEQOracle<String, String> wOracle= MealyWMethodEQOracle<String, String> wOracle=
new MealyWMethodEQOracle<>( new MealyWMethodEQOracle<>(
5, //int maxDepth 5, //int maxDepth
mqOracle // a membership oracle mqTestingOracle // a membership oracle
); );
...@@ -177,7 +182,7 @@ public class TicTacToeLearner { ...@@ -177,7 +182,7 @@ public class TicTacToeLearner {
// learning statistics // learning statistics
System.out.println(experiment.getRounds().getSummary()); System.out.println(experiment.getRounds().getSummary());
System.out.println(statisticSul.getStatisticalData().getSummary()); System.out.println("Number of inputs sent to the SUL: " + statisticSul.getStatisticalData().getSummary());
// model statistics // model statistics
System.out.println("States: " + result.size()); System.out.println("States: " + result.size());
......
...@@ -44,6 +44,9 @@ class TicTacToeTeacher(AbstractTeacher): ...@@ -44,6 +44,9 @@ class TicTacToeTeacher(AbstractTeacher):
self._outputs = set(itertools.product('XO_', repeat=9)) self._outputs = set(itertools.product('XO_', repeat=9))
# counter for inputs:
self._count = 0
#Receiving confirmation from game #Receiving confirmation from game
data = self._socket.recv(1024) data = self._socket.recv(1024)
if data.decode("utf-8") != "CONNECTED\n": if data.decode("utf-8") != "CONNECTED\n":
...@@ -61,6 +64,16 @@ class TicTacToeTeacher(AbstractTeacher): ...@@ -61,6 +64,16 @@ class TicTacToeTeacher(AbstractTeacher):
# Tic Tac Toe is a mealy machine like game, there is alternation of input and # Tic Tac Toe is a mealy machine like game, there is alternation of input and
# output. This must be defined in inputExpert # output. This must be defined in inputExpert
def oneOutput(self, actions): def oneOutput(self, actions):
for i in range(len(actions)):
self._socket.sendall(bytes(str(actions[i]), 'UTF-8'))
self._count += 1
output = self.output()
return output
# Exactly the same function oneOutput, but without incrementing the inputs counter
# because we do not want to count inputs during testing
def oneOutputForTesting(self, actions):
for i in range(len(actions)): for i in range(len(actions)):
self._socket.sendall(bytes(str(actions[i]), 'UTF-8')) self._socket.sendall(bytes(str(actions[i]), 'UTF-8'))
...@@ -98,6 +111,10 @@ class TicTacToeTeacher(AbstractTeacher): ...@@ -98,6 +111,10 @@ class TicTacToeTeacher(AbstractTeacher):
def getQuiescence(self): def getQuiescence(self):
return 'delta' return 'delta'
# Get input counter
def getInputCounter(self):
return self._count
# Close connection # Close connection
def close(self): def close(self):
self._socket.sendall(bytes("EXIT\r\n", 'UTF-8')) self._socket.sendall(bytes("EXIT\r\n", 'UTF-8'))
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