Commit 5823f7c1 authored by Michele's avatar Michele

added statistics to learning tic tac toe

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