Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Mapper Class #52

Closed
bazali opened this issue Nov 24, 2017 · 15 comments
Closed

Use of Mapper Class #52

bazali opened this issue Nov 24, 2017 · 15 comments
Labels

Comments

@bazali
Copy link

bazali commented Nov 24, 2017

Hello!
I have read a document on Active Automata Learning from the following link:
https://www.kma.informatik.tu-darmstadt.de/fileadmin/user_upload/Group_KMA/ESF-WS/bernhard.pdf

Now,
I want to write the code for Mapper Module to learn the behavior of a stack with following code:

public static class StackDemoUsingArray{
    public static final int maxSize=3;
	   private Object[] stackArray=new Object[maxSize];
	   public int size=0;  	   
	   
	   //pushing operation
	   public Boolean push(Object j) {
		   if(size<maxSize) {		   
			   stackArray[size] = j;
			   size++;
			   return true;
		   }
		   else
			   return false;
	   }    	   
	   //pop operation
	   public Object pop() {
		   if(size==0)
			   return null;
			   //return "baz";
		   else
			   size--;
			   return stackArray[size];    		   		
	   }    	   
}

And the final Learned Model/targeted model should somewhat as (screen shots taken from the above link):
mod

I have modify the code of Example2 in the de.leranlib.examples.exmaple2. The modified code is as:

  1. first of all i replace the code of stack already given in example2 with name i.e., public static class BoundedStringQueue with the above one

  2. and modified code of Mapper as:
    // instantiate test driver
    SimplePOJOTestDriver driver = new SimplePOJOTestDriver(
    StackDemoUsingArray.class); //Working Fine .... OK

     // create learning alphabet
     Method mPush = StackDemoUsingArray.class.getMethod(
             "push", new Class<?>[]{Object.class});
     Method mPop = StackDemoUsingArray.class.getMethod(
             "pop", new Class<?>[]{});
             
     // offer
    AbstractMethodInput push1 = driver.addInput("push1", mPush, "1");
    AbstractMethodInput push2 = driver.addInput("push2", mPush, "2");        
     // poll
     AbstractMethodInput pop = driver.addInput("pop", mPop);
    

And
// create initial set of suffixes
List<Word> suffixes = new ArrayList<>();
suffixes.add(Word.fromSymbols(push1));
suffixes.add(Word.fromSymbols(push2));
suffixes.add(Word.fromSymbols(pop));

And rest of code is same as in de.leranlib.examples.exmaple2. I obtained the following learned model(its not the complete model but a short part of big one....bcoz i was unable to upload here):

learned modell

My questions are:

  1. In my learned model there should be transition labels like push1/ok and push2/ok instead of push1[]/true and push2[]/true And at the final states (end states) it should be like push1/nok and push2/nok instead of push1[]/false and push2[]/false. It looks that Mapper is working only in forward direction (mapping abstract to concrete) but not in backward direction. Besides, the symbol [] with push and pop should not be appeared. How/Where should I modify in code of Mapper so that i will be able to learn the exact model.

  2. After that i will infer the following model:
    mod-k stack

Please, guide me how to write/modify the code of Mapper so that it can transform the symbols form Abstract to Concrete and then back from Concrete to Abstract. e.g true to OK , false to NOK, upon receiving 51from SUL to odd and 2012 to even etc...

thanks...

Ali

@bazali bazali closed this as completed Nov 24, 2017
@bazali bazali reopened this Nov 24, 2017
@bazali bazali closed this as completed Nov 24, 2017
@bazali bazali reopened this Nov 25, 2017
@mtf90
Copy link
Member

mtf90 commented Nov 28, 2017

If you look at the SimplePOJOTestDriver, you can see that it is basically a mapper, that maps Java reflection invocations to an intermediate abstraction layer (MethodInput and AbstractMethodOutput). While these allow for a little bit more convenient handling of the SUL (e.g. exceptions are not actually thrown but mapped to an Error output, etc.) they are still rather generic. If you look at their respective toString methods, you can see that they print the actual method name and their parameters (hence the []) or just the return value, which is why your hypothesis still looks rather low-level.

I see to possibilities changing this:

  • Rather than using these generic MethodInputs, you could define your own MethodInputs, e.g. Push1Input that renders as a simple "push" symbol and pushes the number 1 on the stack. You would probably have to write your own version of a SimplePOJOTestDriver that does not use the generic MethodInput class.
  • Use another mapper that even further abstracts from the MethodInputs and chain these two mappers.

For the second approach I have coded a little example that should yield the hypothesis you're interested in. While this may look easier at first, using this chained mapper approach also has drawbacks. For example, if you start to push boolean values on the stack, you cannot decide whether e.g. true is the result of the pop or push method solely by looking at the result. You would have to introduce some kind of state in the mapper (e.g. remember the name of the previous method you invoked, etc.)

I hope this example answers your question. (It's not the complete answer to your second question, but I think leaving some room for experimentation for yourself hopefully helps you to understand it even better)

@mtf90
Copy link
Member

mtf90 commented Nov 28, 2017

Also make sure to checkout / use our Q&A mailing list for future questions, so we can use the issue tracker for actual issues.

@mtf90 mtf90 added the question label Nov 28, 2017
@bazali
Copy link
Author

bazali commented Nov 29, 2017

Thank you so much. Now, I will be able to solve the issues with my code......

@bazali bazali closed this as completed Nov 29, 2017
@bazali
Copy link
Author

bazali commented Nov 29, 2017

Hello Sir!
I am facing the same issue ( issue #44 (Error while importing package)) in order to run the modified example sent by you. Previously it was solved by the help of #32 (Compile in Eclipse) and since then all the examples/projects are being compiled and executed perfectly. I am using Eclipse IDE with Maven enable feature.
For example, below is the screen shot of example/code that was bundled with LearnLib package i.e., de.learnlib.examples.example2;
1

But, when i added/loaded the example (you posted) it gave errors like:
2

Please note here that I am using Learnlib version (learnlib-learnlib-0.12.0). I have also tired to modify the build-path but not successful. Again set the settings according to issue #32 but could not succeed to compile it.

Besides,
There are different ways/links to download Learnlib e.g

1- https://github.com/LearnLib/learnlib/tree/learnlib-0.12.0
( Malte Isberner [maven-release-plugin] prepare release learnlib-0.12.0)
or
2- https://github.com/LearnLib/learnlib/tree/master
or
3- https://github.com/LearnLib/learnlib (with option clone and download)

To me, I think third link is regularly updated. Should i used this version? Needed you help in this regard please.

regards
ali

@bazali bazali reopened this Nov 29, 2017
@mtf90
Copy link
Member

mtf90 commented Nov 29, 2017

Sorry, my bad. Yes, I wrote the example against the latest development version. Your first link points to the git tag of the latest release (version 0.12) which is basically the latest commit on the master branch (your second link).

Your third link, points to the most recent development branch of the repository. I suggest you clone the repository using git. This way you only have to run git pull to receive get the latest updates and don't have to download the complete repository over and over.

The latest official releases are rather old (Malte left our chair about 2 years ago and I only picked up the maintainment a couple of months ago). I recently got the deployment rights for the sonatype repositories and I'm planing to release a new version early next year, so you don't have to rely on development versions anymore.

@bazali
Copy link
Author

bazali commented Nov 30, 2017

Thanks you for your quick reply.......

1 similar comment
@bazali
Copy link
Author

bazali commented Dec 4, 2017

Thanks you for your quick reply.......

@bazali
Copy link
Author

bazali commented Dec 4, 2017

Hello sir!

I obtained learnlib and automatalib by cloning, as given below:
$ git clone https://github.com/Learnlib/learnlib.git
$ git clone https://github.com/Learnlib/automatalib.git
Then i imported the two folders in maven enabled Eclipse as:
File --->import----->Existing Maven Projects and then select first learnlib folder and after repeating the same steps i imported automatalib. All things going fine. Examples shiped with libraries .i.e., Example1, Example2, and Example3 are working fine. But, there is also an error in project learnlib-Equivalence-Oracles, as shown below:
1

And,
2
Due to this i am unable to execute the code example sent by you also.

regards
Ali

@mtf90
Copy link
Member

mtf90 commented Dec 4, 2017

The issue with the missing SLF4J implementation should be fixed with 40fa12f.

For the other issue ("The interface XXX cannot be implemented ..."), I currently have no solution at hand. I got the same error, when I imported the project into Eclipse, so it's not an error on your side. I suspect the issue to be related to Eclipse, since both the continuous integration server and IntelliJ don't report such errors. However, even in Eclipse I was able to run the example I send to you, if I just clicked "Proceed Anyway" on the dialog box (the EQ oracle test is not mandatory for the example to work).

I'll try to look into it, once I have some time to spare. If you cannot get the code to run at all, maybe you could try using IntelliJ instead?

@bazali
Copy link
Author

bazali commented Dec 5, 2017

Thank you so much for your cooperation. I really appreciate you and your team's dedicated efforts towards the development of LearnLib library. Now, I am successful to execute the example sent by you.

Secondly, We are mostly used to Eclipse and configured it for learnlib (maven plugin, graphviz settings, use of issue#32 etc) And dont want the reconfiguration of IntelliJ). We shall be grateful to you if you solve the issue of i.e., learnlib-equivalence-oracles ("The interface XXX cannot be implemented ...").

As far as my query is concern, it is solved. You may close this issue and open a new one regarding the solution of learnlib-equivalence-oracles ("The interface XXX cannot be implemented ...") or keep it alive.

Once again thank you very much.

regards

@mtf90
Copy link
Member

mtf90 commented Dec 5, 2017

I will close this issue for now, since the original question is answered.

For the Eclipse error, I will have to look. Even the error message seems wrong. Apparently there should be two different type arguments, but in both cases it even says DeterministicAutomaton<?, I, ?>. I'm kind of hesitant to programm around deficits of the Eclipse compiler, but maybe this will be fixed in one of the next versions of Eclipse.

Overall, thanks for the input. By providing these examples for you, I could actually see some shortcomings of the current API. With adc2d1a I added/refactored some of the existing Mapper code (don't worry, your code should still work fine. In the worst case, you should only have to implement a difference interface). But overall, these changes should allow you to write less boilerplate code on your own and use the classes shipped with LearnLib. I have updated my first example MapperExample.java to reflect these changes (the custom implementation of ResettingMappedOracle can now be completely replaced by the generic MappedOracle).

@mtf90 mtf90 closed this as completed Dec 5, 2017
@bazali
Copy link
Author

bazali commented Dec 7, 2017 via email

@mtf90
Copy link
Member

mtf90 commented Dec 8, 2017

Dear @bazali, I think github swallowed you're attachment, since you directly answered to the notification (and hence your mail is picked up as a comment to this issue).

I think, it would be best to send me an e-mail directly. This way, I would also get your correct e-mail address, so that I know whom to answer (normally github shadows the sender to "bazali" <notifications@github.com>

@bazali
Copy link
Author

bazali commented Dec 9, 2017 via email

@mtf90
Copy link
Member

mtf90 commented Dec 11, 2017

you can use the same address, that I use for my git comits: markus.frohme at udo.edu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants