How to print the intermediate observation table (especially when the create the hypothesis) #117
Replies: 3 comments 4 replies
-
In this case you need to implement the lstar.startLearning();
DFA<?, Character> hyp = lstar.getHypothesisModel();
DefaultQuery<Character, Boolean> ce;
while ((ce = eqo.findCounterExample(hyp, alphabet)) != null) {
while (lstar.refineHypothesis(ce)) {}
hyp = lstar.getHypothesisModel();
} Here, you can insert any code you want between the individual steps (e.g., the logging of intermediate observation tables). |
Beta Was this translation helpful? Give feedback.
-
Please provide that when we run the algorithm
we can measure the entire time, but I want to compute the time in that number of equivalence queries and membership queies separately. |
Beta Was this translation helpful? Give feedback.
-
actually I ddin't know much about the implementation from the library. Please can we provide the little bit of idea or sample code so I can do it by myself package com.experiment;
import com.experiment.dfa.DFAOperation;
import com.google.common.collect.Lists;
import de.learnlib.algorithms.lstar.closing.ClosingStrategies;
import de.learnlib.algorithms.lstar.dfa.ClassicLStarDFA;
import de.learnlib.algorithms.lstar.dfa.ClassicLStarDFABuilder;
import de.learnlib.algorithms.malerpnueli.MalerPnueliDFA;
import de.learnlib.algorithms.rivestschapire.RivestSchapireDFA;
import de.learnlib.algorithms.rivestschapire.RivestSchapireDFABuilder;
import de.learnlib.api.oracle.MembershipOracle;
import de.learnlib.api.query.DefaultQuery;
import de.learnlib.datastructure.observationtable.ObservationTable;
import de.learnlib.datastructure.observationtable.writer.ObservationTableASCIIWriter;
import de.learnlib.filter.statistic.oracle.DFACounterOracle;
import de.learnlib.oracle.equivalence.DFAWMethodEQOracle;
import de.learnlib.oracle.equivalence.SampleSetEQOracle;
import de.learnlib.oracle.membership.SimulatorOracle;
import de.learnlib.util.Experiment;
import dk.brics.automaton.Automaton;
import dk.brics.automaton.RegExp;
import net.automatalib.automata.fsa.DFA;
import net.automatalib.brics.BricsDFA;
import net.automatalib.util.automata.conformance.WMethodTestsIterator;
import net.automatalib.visualization.Visualization;
import net.automatalib.words.Alphabet;
import net.automatalib.words.impl.Alphabets;
public class Driver {
private static final DFAOperation dfaOperation = new DFAOperation();
private static final int EXPLORATION_DEPTH = 5;
public static void main(String[] args) {
String regex = "a|b|.{3,}";
final Automaton automaton = new RegExp(regex).toAutomaton();
final Alphabet<Character> alphabet = Alphabets.characters('a', 'b');
final BricsDFA dfa = new BricsDFA(automaton, true);
MembershipOracle.DFAMembershipOracle<Character> sul = new SimulatorOracle.DFASimulatorOracle<>(dfa);
rsAlgorithm(dfa, alphabet, sul);
System.out.println("-------------------------------------------------------");
}
private static void rsAlgorithm(BricsDFA dfa, Alphabet<Character> alphabet, MembershipOracle.DFAMembershipOracle<Character> sul) {
DFACounterOracle<Character> rsCounter = new DFACounterOracle<>(sul, "Membership Queries");
RivestSchapireDFA<Character> rs = new RivestSchapireDFABuilder<Character>()
.withAlphabet(alphabet)
.withOracle(rsCounter)
.withClosingStrategy(ClosingStrategies.CLOSE_FIRST)
.create();
final SampleSetEQOracle<Character, Boolean> eqo = new SampleSetEQOracle<>(false);
eqo.addAll(sul, Lists.newArrayList(new WMethodTestsIterator<>(dfa, alphabet, EXPLORATION_DEPTH)));
Experiment.DFAExperiment<Character> rsExperiment = new Experiment.DFAExperiment<>(rs, eqo, alphabet);
rs.startLearning();
DFA<?, Character> hyp = rs.getHypothesisModel();
DefaultQuery<Character, Boolean> ce;
int count = 1;
while ((ce = eqo.findCounterExample(hyp, alphabet)) != null) {
while (rs.refineHypothesis(ce)) {
System.out.println(ce.toStringWithAnswer(true));
hyp = rs.getHypothesisModel();
// Visualization.visualize(hyp, alphabet);
new ObservationTableASCIIWriter<>().write(rs.getObservationTable(), System.out);
++count;
}
}
long startTime = System.currentTimeMillis();
// rsExperiment.run();
long endTime = System.currentTimeMillis();
printResults("L_RS", rsExperiment, rsCounter, endTime - startTime);
System.out.println("Final observation table of L_RS:");
new ObservationTableASCIIWriter<>().write(rs.getObservationTable(), System.out);
}
private static void printResults(String algorithmName, Experiment.DFAExperiment<Character> experiment,
DFACounterOracle<Character> counterOracle, long timeTaken) {
System.out.println("----------------" + algorithmName + "-------------");
System.out.println("EQ: " + experiment.getRounds().getCount());
System.out.println("MQ: " + counterOracle.getCount());
System.out.println("Time: " + timeTaken);
}
} |
Beta Was this translation helpful? Give feedback.
-
"I provide the code, I want to print the intermediate observation table when hypothesis created or when the each membership queries ask to the teacher (SUL)"
Beta Was this translation helpful? Give feedback.
All reactions