Saturday, October 24, 2009

My research methodology, formalized :)

Ok, here's the scenario. You are in a conference hall lecturing some of the brilliant minds about your research, people are taking your notes!!! (aha), asking you fancy questions and you just bowl them over with your elegant answers (double aha). The conference is a great success, your teachers are impressed by you; who knows, your name just might appear in the news paper (now you can hear violins playing in the background). Suddenly you hear your mom shouting, struggling to wake you up from your slumber...grrr (Sad reality of life, good moments don't last long). Anyways, this dream has motivated you to write your very own research paper except for one teeny little problem. You dunno how to start. Oh, i hear your nerdish blood throbbing, good good, you can read on...

Research is and always has been intuitive in nature. Most great things are just stumbled upon.., rarely do people plan and do something ingenious. If you are like me, then DO NOT rely on luck expecting a golden apple to fall right into your hands, work your way towards it. 99% of research is planned. Plan and work towards your goal, its that simple.

Research topic/problem selection


1) Select an interesting area of your choice. Its better if you have some former knowledge on it. I know big bang stuff sounds cool, but its way outta my league; so, select something that fits in your knowledge domain. Lets see, i am into software stuff...that should be a good place to start.

2) Narrow down your domain. Ask yourself, "what in software stuff"? Hmm, for me it would be business modeling and analysis, just follow your interests.

3) This is very important...what are my time constraints? How much research time (fool around time) can i afford? 1 month? 1 year?? Just keep an approx time frame in your mind before you proceed any further.

4) Research type falls under three major categories (lol, i just made that up)
  • Listing industrial/personal experience with something.
  • Survey of existing techniques/models/methods or whatever.
  • Augmenting/extending/improving existing stuff.
  • Coming up with something new in a particular area.
  • Coming up with something so dramatic, that it gives rise to a new field of study (like human computation or neotic sciences)
Did i say three categories? That's because you wouldn't be reading this post if you are researching 4th or 5th category. So for all purposes of the study (i know, it sounds L.A.M.E.), lets just focus on the first three categories. Also, the categories are arranged in the increasing order of difficulty (usually, not always the case).

5) Its now the time to narrow down your domain further. Business analysis and modeling is a very large area. It will certainly consist of many sub-parts, explore each one of those sub-parts.
  • If you are attempting a research paper of category 1, then all you have to do is formalize your experience on a paper. It might seem lame to you, but it will make sense to many others.
  • If you wanna survey, be sure to choose a sub topic that's very extensive, i.e., has too many models/techniques each with their own advantages and disadvantages.
  • For the third category, your immediate goal should be to determine possible research areas/problems.
Based on these factors, choose a suitable sub-part. If its not in compliance with your time frame, repeat step 5 or jump back to step 2. ( I know, i know, its like a bloody pseudo code)

6)For either of these categories, you gotta do some literature study. Try to get one of those survey papers that has a comprehensive analysis of all or most popularly available methods. You could google something like "sub-part survey ieee", "sub-part survey papers" or "sub-part research areas", "sub-part research problems". This should give you a head start. Also, do save the pdf copies as they will be used later on for references.

From this point on i am just gonna discuss about 3rd category of research. Maybe i'll write about the first two categories later on...Here goes, make a list of all the positive and negative counterparts of each method. All you have to do is come up with one, that has all the strength's and none of the weakness (easier said than done). Ok, if not none of the weaknesses part, try to get all the positive attributes together in your method/model.

By the end of these six steps, you should have come up with a problem worth investigating. Believe it or not, deciding upon a good problem is effectively 30% of the research (at least, according to me).

Now the next step is to find a solution to your problem and then write your paper. Both these tasks are very daunting and i am feeling very sleepy right now. I will write about these in my next post. Hope you find this article useful.


Monday, October 12, 2009

Can share algorithm

Show that there is an algorithm of complexity O(|V| + |E|) that tests the predicate can•share, where V is the set of vertices and E the set of edges, in G0. Prove this by showing one such algorithm.

This question is from the book: Computer Security: Art and Science by Matt Bishop. I Found this question quite interesting (especially the algorithm part), hence the post.



According to theorem 3-10, The predicate can•share(a, x, y, G0) is true if and only if there is an edge from x to y in G0 labeled a, or if the following hold simultaneously:

a. There is a vertex s in G0 with an s-to-y edge labeled a.
b. There exists a subject vertex x' such that x' = x or x' initially spans to x.
c. There exists a subject vertex s' such that s' = s or s' terminally spans to s
d. There exist islands I1, …, In such that x' belongs to I1, s' belongs to In, and there is a bridge from Ij to Ij+1


Algorithm:

(Abstraction level 1)

The idea for the algorithm is as follows:
  1. If node x or y does not exist, return false.
  2. If there is an edge ‘a’ from x to y, return true.
  3. Check conditions a, b, c, d of theorem 3-10, if they hold simultaneously, return true else return false.

(Abstraction level 2)

Step 3 from above can be elaborated as follows:
  1. Start from node x.
  2. Try to find x' satisfying condition B of theorem 3-10. If no, return false. If yes, for every such x', loop step 3.
  3. Try to find s' satisfying condition D of theorem 3-10. (We don’t return false here as there might be some other x' for which step 3 might be true, so we check exhaustively; i.e., since we are in a loop right now). If yes, for every such s', loop step 4.
  4. Try to find s satisfying condition C of theorem 3-10. If yes, for every such s, loop step 5.
  5. If there is an edge ‘a’ from s to y, return true. (Checking condition A of theorem 3-10)
  6. Return false (If it reached this step, it means that step 5 failed to return true)

The above sequence of actions can be represented as:
  1. Start from node x.
  2. Algorithm Step2(x)
  3. Algorithm Step3(x')
  4. Algorithm Step4(s')
  5. If there is an edge ‘a’ from s to y, return true. (Checking condition A of theorem 3-10)
  6. Return false (If it reached this step, it means that step 5 failed to return true)

(Abstraction level 3)

Algorithm Step2(X)

The graph data structure is such that every node has an associated data ‘visited’, which is Boolean in nature. This data is used so that the node is not re-analyzed again. We need to find all x', such that, x' is a subject and x' has a T*G path to x. Two intermediate algorithms used within this algorithm, they are:

Algo1(X) (Finds the neighborhood node of X such that it has a grant right over X)
  1. For each neighboring vertex V of X such that V->visited = false (for loop), execute steps 2, 3
  2. Make V->visited = true
  3. If( V -> X has a grant), call Algo2(V)

Algo2(V) (Recursively checks for T* paths and calls step3 whenever appropriate)
  1. For each neighboring vertex x' of V, if x' -> V has a Take right and x' -> visited = false. Execute steps 2, 3, 5
  2. x' -> visited = true
  3. If x' is a subject vertex, execute step 4
  4. Call algorithm Step3(x')
  5. Call algorithm Algo2(x') (This call gives us the desired effect to check T* paths)

The Step2(X) algorithm is defined as:
  1. Call algorithm Algo1(X)

Algorithm Step3(X')

//Check for paths satisfying T* ->, T* <-, T* -> G <- T* <-, T* -> G -> T* <- Algo3(X') (Checks for T* <- paths)
  1. For each neighboring vertex n of x', if n <- x' has a Take right and n -> visited = false. Execute steps 2, 3, 5
  2. n -> visited = true
  3. If n is a subject vertex, execute step 4
  4. Call algorithm Step4(n)
  5. Call algorithm Algo3(x') (This call gives us the desired effect to check T* paths)

Algo4(X') (Handles remaining cases)

For each neighboring vertex n of x', if n <- x' has a Take right and n -> visited = false. Execute steps 2, 3, 8
  1. n -> visited = true
  2. If n is a subject vertex, execute block 4, 5, 6, 7
  3. Call algorithm Step4(n)
  4. For each neighboring vertex n' of n, if n' -> n or n' <- n has a Grant right and n' -> visited = false. Execute step 6, 7
  5. n' -> visited = true
  6. Call Algo3(n') (Tries to terminate with subject vertex having T* ->)
  7. Call algorithm Algo4(x') (Handles recursive paths with similar signature)

The Step3(X') algorithm is defined as:
  1. Call algorithm Algo3(X')
  2. Call algorithm Algo4(X')

Algorithm Step4(S)

//Try to find s' such that s' -> s has T* path.
  1. Call algorithm Algo2(S) used in Step2, modify step 3 of Algo2 as ‘Call Step 5’



Complexity Analysis:

From abstraction level 1, we conclude that the running time of the algorithm is the running time of step 3 as steps 1, 2 take O(1) time (Since only a lookup operation needs to be performed in the adjacency matrix)

From abstraction level 2, we conclude that the complexity is determined by the sequence of actions in steps 2, 3, 4, 5.

By observing steps 2, 3, 4, 5; in the worst case, all the edges and the vertices of the graph will be explored. (This will happen when all nodes connected to node n initially spans to it, making step 2 call step 3. Similarly, step 3, 4, 5 may explore all nodes before step 6 is reached).

Therefore, worst case running time for the algorithm is O(|V| + |E|)
The best case running time is O(1) (If the algorithm concludes with step 1 or 2 in abstraction level 1)

Thursday, August 6, 2009

When headache truly becomes a headache...

I had one of the worst possible night's yesterday. I had a bad headache, was tired but couldn't sleep :(

After my excruciating experience i decided to blog on simple home therapies to relieve headaches. You can try one of the following:
  1. Tie a cloth around your head, switch off the damn fan or AC. Take a sharp object, like a pen and poke it slightly on your upper left thumb.
  2. Headache's can also occur because of high BP. It is typically characterized by neck pains, breathing spasms and heart throbbing sensations. Try garlic, watermelons or lemon + honey combo if that appears to be your case.
  3. Put a hot water dripped cloth around your neck.
  4. Avoid light and sound.
  5. Start imagining and try making up some scenarios in your head to keep you distracted.
In case you are suffering from migraines, i suggest you read this post. If none of the above works for you, go visit a doctor.

Sunday, June 28, 2009

Sunday, June 14, 2009

Saturday, June 13, 2009

LookupListener problem?

There are many unanswered threads to this question. The common issue is that the resultChanged(...) method is never triggered!! Here is a proper use-case scenario (note the comments, they provide tips to avoid common loopholes)
public SomeClass extends LookupListener
{
//It is important that you hold a reference to Lookup.Result
//so that it doesn't get garbage collected. This also applies to Lookup.Template
private Lookup.Result result = lookup.getDefault().lookupResult(MyInterface.class);

public SomeClass()
{
result.addLookupListener(this);

//It is important to call this method once...otherwise
//resultChanged(...) method is never triggered!!
resultchanged(new LookupEvent(result));
}

public void resultChanged(LookupEvent ev)
{
//do your stuff here...
}
}
If you still have problems, then check the META-INF/services folder of your implementation, there is probably a typo in the flat file. Its better to use @Service annotation to avoid such mistakes.

Plugin manager for standalone swing apps

Lookup API provides more features than the typical ServiceLoader mechanism introduced in JDK 6. It allows you to listen to changes using LookupListener. If your not aware of Lookup API, please read about it here before continuing any further. For a more comprehensive tutorial on the subject, check out this screencast

Lookup API provides amazing decoupling capabilities to your application, even in standalone and non visual applications. The problem comes when you have to install or remove modules from your applications (implementations of an interface). In Netbeans platform the plugin manager would automatically do this for you. To utilize the benefits of LookupListener, one has to add the module jar files to the classpath (at run time).

This however cannot be achieved directly, here's a reflection hack to get it done:
/**
* Rescans the given folder and adds all the Jar files (plugins)
* to class path...simply ignores if a jar file is already added...
*
* @param path The folder containing plugins...
* @throws java.io.IOException
*/
public void rescan(String path) throws IOException
{
File pluginFolder = new File(path);
File plugins[] = pluginFolder.listFiles(new FileFilter()
{
public boolean accept(File pathname)
{
if(pathname.getPath().endsWith(".jar"))
return true;
else
return false;
}
});

for(File f : plugins)
{
addPlugin(f.toURI().toURL());
}
}

/**
* The url (preferably jar) to be added to the classpath.
* This is like an install plugin thingy...
* Must be used in place of {@link #rescan(java.lang.String) rescan} method
* if a single new plugin is to be installed...gives good performance ups
*
* @param url The url to be added to classpath
*/
public void addPlugin(URL url) throws IOException
{
addURLToClassPath(url);
}

/**
* To avoid un-necessary object creation on method calls...
*/
private static final Class[] parameters = new Class[]{URL.class};
/**
* Adds a URL, preferably a JAR file to classpath. If URL already exists,
* then this method simply returns...
*
* @param u The URL t be added to classpath
* @throws java.io.IOException
*/
private void addURLToClassPath(URL u) throws IOException
{
URLClassLoader sysloader = URLClassLoader)ClassLoader.getSystemClassLoader();

boolean isAdded = false;
for(URL url : sysloader.getURLs())
{
if(url.equals(u))
isAdded = true;
}
if(isAdded)
return;

Class sysclass = URLClassLoader.class;
try
{
Method method = sysclass.getDeclaredMethod("addURL",parameters);
method.setAccessible(true);
method.invoke(sysloader, new Object[]{ u });
}
catch (Throwable t)
{
t.printStackTrace();
throw new IOException("Error, could not add URL to system classloader");
}
}
In the above code we are adding a URL (typically pointing to a jar file) to the system classloader by invoking its private method via reflection.

In your plugin manager...all you have to do is paste the jar file to a certain folder (say user.dir/plugins), then execute the following code to add jars to classpath:

/**
* Rescans the given folder and adds all the Jar files (plugins)
* to class path...simply ignores if a jar file is already added...
*
* @param path The folder containing plugins...
* @throws java.io.IOException
*/
public void rescan(String path) throws IOException
{
File pluginFolder = new File(path);
File plugins[] = pluginFolder.listFiles(new FileFilter()
{
public boolean accept(File pathname)
{
if(pathname.getPath().endsWith(".jar"))
return true;
else
return false;
}
});

for(File f : plugins)
{
addPlugin(f.toURI().toURL());
}
}

/**
* The url (preferably jar) to be added to the classpath.
* This is like an install plugin thingy...
* Must be used in place of {@link #rescan(java.lang.String) rescan} method
* if a single new plugin is to be installed...gives good performance ups
*
* @param url The url to be added to classpath
*/
public void addPlugin(URL url) throws IOException
{
addURLToClassPath(url);
}
That's it! the newly registered service providers can be caught in resultChanged(...) method of the LookupListener. Similarly you can remove items from the classpath to deactivate the plugins from your application, i'll leave that as your home work assignment :)

Wednesday, June 10, 2009

lookup third party service impl of an interface

If you have a jar file containing implementations of an interface that you want to be discovered by lookup...here's what you do:

1) Use library wrapper wizard in Netbeans to create a jar module wrapper.
2) Create a folder META-INF/services in the wrapper module.
3) Create a file in META-INF/services named after the fully qualified name of the interface containing the fully qualified names of the implementations (one per line)

That's it!
Third party service implementations to now be discovered by the global lookup on startup.

Saturday, June 6, 2009

Unnecessary object creation...

Most of you might already know about this. I just found this out while working on my open source project JNeuralNet.

I had this situation:


loop
{
Double d = someclass.compute();
}
When i ran the profiler. I noticed that the major portion of CPU was going into Double object creation. That's when i realized that its the classloader overload everytime the object is being created..so this is what i did:

//init variable...
Double d = 0.0;
loop
{
d = someclass.compute();
}
This simple optimization reduced a lot of CPU overload! Also if u have situations such as:

loop
{
Obj o = new Obj();
}
If feasible...try using:

Obj o = new Obj();
loop
{
//use o...
o.set(abc);
}
This approach is not always feasible...especially if you intend to use the reference of the object elsewhere, my point is, to reduce object creation wherever feasible.

Friday, June 5, 2009

My theory on time travel...

Already tortured people by giving this presentation back in my 8th semester...here goes:

I have two solid conclusions:
1) Its possible to view past.
2) Not possible to travel back in past or is a very bad idea!

1st assumption is an easy one to crack...you see this phenomenon every day (every night actually). Just look up at the sky...see the stars. What u actually see is the past. That star might have died by now...since it is 100's of light years away...what you're actually seeing is 100 light years backward.

As for the 2nd assumption...lets start with the hypothesis that it is possible to travel to past. Now imagine that you do something to trigger the death of your past self...It means that you never took the path that led you to travel back to the past, a direct contradiction.

so let us now suppose that its not possible to kill your past self. It might mean that your consciousness might merge with the past self and u forget everything about the future u came from...meaning that in future u again do the same time travel thingy., come back to past. Dude, you're now stuck in an indefinite loop.

Third option, according to string theory, every universe represents a possibility. suppose u travel in past and do something different it means that you have shifted the future timeline to a new parallel universe...meaning that u effectively destroyed the current universe and connected the future events to another one...destruction of a universe...certainly sounds like a bad idea!

Crazy comments are most welcome!!

My theory of good and bad

Pardon me for the language folks, but i think good and bad is BULL CRAP! Here's what i believe...

Some clever saint/person must have thought of this idea to keep things in control...so that the world doesn't go chaotic.

Just think of this for a moment...U say that a good thing is good because if gives u the internal satisfaction or whatever. You know what i think...i feel its because of the society/environment you're brought up in. Imagine a society where they'd preach that hurting some one is a good thing. In that case, hurting someone may give u that internal satisfaction...just like the way animals kill each other...no moral code whatsoever.

So in conclusion...there is no good and bad. Its human invented! Don't get the wrong idea, im not telling u to become bad or something. Its just my option...thought it was interesting and shared it!

Give...dont expect things back!

Expectation is your worst enemy. Always help...if possible go out of the way to help others. I believe in karma and have a belief that whatever u do comes back to you. Please don't expect things in return...I have seem many people getting hurt because of this. Just take the happiness as a return gift for the moment. In the worst of times, the favor will return by itself!

Afterall they're humans too!

Were there times when u get scared of your boss, faculty, giving presentations? Just remember this one thing, bottom line they're also humans...just like us. They have also made mistakes and must have been nervous at some point.

Just imagine yourself in their position. Would have just laughed it off wouldn't you? So just tell them whatever it is that you're so hesitant about. Want a pay raise...wouldn't agree with their ideas, SPEAK OUT! At the most what will happen? You may get fired or ridiculed at...but will always be happy that you did the RIGHT THING!...In the end its the satisfaction that matters.

Wednesday, May 27, 2009

My ideal desktop recipe

Don't know about others, but i sure am confused by the vast ocean of frameworks and libraries available out there to help aid in java desktop applications.

This blog is not about frameworks and libraries that offer the best functionality and power, but those that do with a faster learning curve.

Typically, these are the pain points you'll encounter (sooner or later) in a large desktop application.

  • Validation
  • Binding Pojo's with GUI
  • Database Management
  • Cool and sleek GUI
  • Code complexity
  • Packaging and deployment
  • Creating Trialware's

1) Validation

I never paid much attention initially, but validation is one aspect that tends to get laborious. There are popular validation frameworks out there to help you with it. But as a beginner you'll want to learn it quick and easy. I'd prefer the Simple Validation Api by Tim Boudreau. Powerful and simple at the same time. Hardly takes 10 minutes to learn.


2) Binding POJO's with GUI

In my opinion there is no good tool for data binding, its currently unstable and there's no out of the box support for it. Its usually more pain than gain. But if u insist i suggest that you use the Netbeans IDE, it features mattise GUI builder with binding support. It'd be nice if JComponent binds POJO via annotations. In either case be on a look out, some one is probably developing it right now.


3) Database Management

Wouldn't it be nice if you didnt have to write all the plumbing code required to execute a database transaction and just concentrate on the task itself? ORM's typically sheild you from all the database junk. Hibernate will probably be the first result if u ever tried to google. It however has a lot of XML mapping stuff to be done.

In my opinion, ActiveObjects orm by Daniel Spiewak is the easiest to use, i.e., in case u dont have distributed databases to deal with. It conpletely sheilds you from database complexity. The only disadvantage is that u need to create POJO interfaces first to generate the database schema . If you already have a database then you must create the interfaces yourself (no generator tool for now). A great feature worth noting is that it has Database Migrations (useful for maintenance).


4) Cool and sleek GUI

Get substance look and feel by Kirill Grouchnikov is an excellent option to spice up you UI. All you have to do is add one line of code. If you're on MAC OS consider Quaqua lnf. Also check out SwingX, Flamingo, L2fProd, JGoodies for cool swing components.

If you have time to spare and want some extreme GUI with cool animation effects consider using Animated Transitions Api and Timing Framework by Romain Guy and Chet Haase. I also suggest that you read Filthy Rich clients by the same authors.

For a quickie, with almost no learning curve u should use substance look and feel with SwingX components along with mattise in NetbeansIDE.


5) Code Complexity

Be it a small or a large project, a GUI application soon gets out of the hand or you'll find yourself handling messy code or writing lots of plumbing code instead of putting effort into the business logic of the application. There's no point in reinventing the wheel, its always better to reuse a well tested framework instead of making one on your own.

For a small scale application its better to use to use your own MVC pattern to separate model, view and control. Major concerns in such application would be to maintain configuration. You'll probably use bean property change listeners...in this case consider using AbstractSerializableBean from swingX project to reduce the amount of boilerplate code for firing property change. It your application still gets out of hand consider using JIDE Application framework...havent really tried it, but looks good and has a moderate learning curve (2-3 days)

For a large application it is best of you use Netbeans Platform, its pretty complex and has a high learning curve, i would'nt recommend it unless you want to reuse netbeans features such as pallete, property sheets and editors etc...but on the bottom line its got great support and excellent documentation. Since its developed by sun, you can expect great support. Moreover NetbeansIDE has lots of code completion features for leveraging a netbeans platform based application.

If you have at least made 5-6 desktop applications and have good knowledge of OOPS, especially the use of interfaces and abstract classes (read this post for information on abstract classes) then you must consider using the Netbeans platform. Start by viewing these excellent screencasts.


6) Packaging and deployment

Consider an application based on java comm api. In such an app, you cant ask your client to copy and paste dll's at different locations, this should instead be done automatically at the deployment time, typically by distributing a setup file. To encash the benefits of cross platform nature of your java code, you'll need to use a cross platform deployer. Again, there are many of them, the easiest one to use and learn is by using PackJacket, a GUI frontend to the IzPack project. It also lets you create runtime scripts to execute custom tasks. whats more, the project is open sourced and is free to use.


7) Creating Trialwares

Depending on your marketing strategy, you might want to create trialware applications that expire after a certain time period.I recommend using TrueLicense library. Will take 1 day to get a hang of it.


Hope the above collection of tools and libs help you be more productive... Please let me know if you find better and easier tools.

Monday, January 12, 2009

Tyranny of autorun.inf

Irritated with the darn viruses...?
A friend of mine came up with this cool idea.

As u all might already know. Most of the viruses create an autorun.inf file (hidden obviously) in the drive. On double clicking the drive, the script is , triggering the virus (Trojans).

Here's the big idea, create a autorun.inf file (blank one) with read only and hidden attributes set. Paste this file in all your drives...even your pen drives. That way, even if a virus is present, it wont be able to create its own autorun.inf, as one already exists, i.e., with the read only permission.

Viola, the virus is as good as useless as it wont be triggered. This applies to most of them but not all.

Friday, January 2, 2009

Cool web pages...

Designing cool looking web pages is not a rocket science. Awesome effects can be acheived without javascript, flash etc etc...

Dont let these things deter you, best example is my friend vivek...with just 2-3 days of work he managed to make a gr8 web page (just needed to learn CSS). Take a look at his page.

Also he showed me some of the coolest web pages ever...very simple in concept and could have been implemented by YOU.

Check out Tyler's web page, this page takes time to load...let it load completely before clicking on any thing. This page was made using the '#' element...pretty cool nah!

Also there is a site called CSS beauty, it has a listing of all the cool web pages...hope this gives you enough inspiration to work on that innovate page of urs :)

Pic of the year...hehe

My stupid cousin naveen never misses opportunities to take ediotic pics of mine...not just mine but of every one else. This one was particularly funny...Believe it or not, that damn brown dog is just 5 months old (super big lol). Its gonna be like 90 kgs, but i still beat it in terms of weight :)