Trace loading from files?

40 views
Skip to first unread message

Georgios Giantamidis

unread,
May 25, 2019, 4:28:44 PM5/25/19
to LearnLib Q&A
Hi,

I'm interested in evaluating LearnLib's passive learning algorithm implementations and I was wondering if there is support for loading a training sample from a file in the format of e.g. past automata learning competitions like stamina ( http://stamina.chefbe.net/download ). A quick search in the repository didn't yield anything -- I'll keep looking, but if anyone knows the answer, please let me know.

Thanks,
George

Markus Frohme

unread,
May 25, 2019, 7:15:27 PM5/25/19
to Georgios Giantamidis, LearnLib Q&A
Dear George,


currently, there is no support for parsing passive training data in LearnLib. However, the file format is simple enough to write a small "parser" on the fly (see below). The resulting trainingSet can simply be passed to the passive learner's 'addSamples' method (cf. [0]).

Kind regards,
Markus


[0] - https://github.com/LearnLib/learnlib/blob/develop/examples/src/main/java/de/learnlib/examples/passive/Example1.java


```java
final List<DefaultQuery<Integer, Boolean>> trainingSet = new ArrayList<>();

try (BufferedReader r = Files.newBufferedReader(new File("/path/to/file.txt").toPath())) {
String line;
while ((line = r.readLine()) != null) {
final String[] tokens = line.split(" ");
final boolean positive;

switch (tokens[0]) {
case "+":
positive = true;
break;
case "-":
positive = false;
break;
default:
throw new IllegalArgumentException("Unknown label: " + tokens[0]);
}

final WordBuilder<Integer> builder = new WordBuilder<>(tokens.length - 1);

for (int i = 1; i < tokens.length; i++) {
builder.add(Integer.parseInt(tokens[i]));
}

trainingSet.add(new DefaultQuery<>(builder.toWord(), positive));
}
}
```
> --
> You received this message because you are subscribed to the Google Groups "LearnLib Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to learnlib-qa...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/learnlib-qa/795d6c30-4f08-4c9a-a991-5d056705dcb2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Georgios Giantamidis

unread,
May 25, 2019, 8:02:52 PM5/25/19
to LearnLib Q&A
> To unsubscribe from this group and stop receiving emails from it, send an email to learn...@googlegroups.com.

Hi Markus,

Many thanks for the quick reply and the code snippet!

I just have one more follow-up question -- I've been trying to convert the DFA passive learning example you linked to into a Mealy one:

package org.example.learnlib;

import java.util.Arrays;
import java.util.Collection;

import de.learnlib.algorithms.rpni.BlueFringeRPNIMealy;
import de.learnlib.api.algorithm.PassiveLearningAlgorithm.PassiveMealyLearner;
import de.learnlib.api.query.DefaultQuery;
import net.automatalib.automata.transducers.MealyMachine;
import net.automatalib.visualization.Visualization;
import net.automatalib.words.Alphabet;
import net.automatalib.words.Word;
import net.automatalib.words.impl.Alphabets;


public final class ExampleMealy {


   
public static void main(String[] args) {

       
final Alphabet<String> alphabet = Alphabets.fromList(Arrays.asList("alpha", "beta", "1", "2", "3", "4"));


       
final PassiveMealyLearner<String, String> learner = new BlueFringeRPNIMealy<>(alphabet);


        learner
.addSamples(getMealySample());


       
final MealyMachine<?, String, ?, String> model = learner.computeModel();


       
Visualization.visualize(model, alphabet);

   
}

   
private static Collection<DefaultQuery<String, Word<String>>> getMealySample() {
       
return Arrays.asList(
           
new DefaultQuery(Word.fromList(Arrays.asList("alpha", "beta")), Word.fromList(Arrays.asList("1", "2"))),
           
new DefaultQuery(Word.fromList(Arrays.asList("beta", "alpha")), Word.fromList(Arrays.asList("3", "4"))),
           
new DefaultQuery(Word.fromList(Arrays.asList("alpha", "alpha")), Word.fromList(Arrays.asList("1", "4"))),
           
new DefaultQuery(Word.fromList(Arrays.asList("beta", "beta")), Word.fromList(Arrays.asList("3", "2")))
       
);
   
}
}

It compiles, but I get an NPE when I run it...

Exception in thread "main" java.lang.NullPointerException
    at de.learnlib.algorithms.rpni.BlueFringeRPNIMealy.initializePTA(BlueFringeRPNIMealy.java:60)
    at de.learnlib.algorithms.rpni.AbstractBlueFringeRPNI.computeModel(AbstractBlueFringeRPNI.java:111)
    at org.example.learnlib.ExampleMealy.main(ExampleMealy.java:36)

Could you just take a very quick look at my code to make sure I'm not doing anything stupid?..

Many thanks again!

Cheers,
George

Markus Frohme

unread,
May 26, 2019, 4:49:41 PM5/26/19
to Georgios Giantamidis, LearnLib Q&A
Hi George,


this one is nasty ;). Since your output domain has the same type as your input traces (Word<String>), calling the constructor DefaultQuery(Word<String>, Word<String>) maps to the DefaultQuery(prefix, suffix) constructor, i.e. your query objects don't have an output value.

In order to use the second parameter as the output of the query, you would have to call the DefaultQuery(prefix, suffix, output) constructor, i.e.

```java
private static Collection<DefaultQuery<String, Word<String>>> getMealySample() {
return Arrays.asList(
new DefaultQuery<>(Word.epsilon(), Word.fromSymbols("alpha", "beta"), Word.fromSymbols("1", "2")),
new DefaultQuery<>(Word.epsilon(), Word.fromSymbols("beta", "alpha"), Word.fromSymbols("3", "4")),
new DefaultQuery<>(Word.epsilon(), Word.fromSymbols("alpha", "alpha"), Word.fromSymbols("1", "4")),
new DefaultQuery<>(Word.epsilon(), Word.fromSymbols("beta", "beta"), Word.fromSymbols("3", "2"))
);
}
```

Kind regards,
Markus
> --
> You received this message because you are subscribed to the Google Groups "LearnLib Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to learnlib-qa...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/learnlib-qa/095a2814-9c8f-4957-b111-7ee9baba05d9%40googlegroups.com.

Georgios Giantamidis

unread,
May 26, 2019, 5:56:51 PM5/26/19
to LearnLib Q&A
Awesome... Thanks a lot, Markus.

Makes perfect sense -- now I also realize why it complained when I didn't include the output symbols in the alphabet (it thought they were input symbols).

Thanks again!

Cheers,
George
> To unsubscribe from this group and stop receiving emails from it, send an email to learn...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages