Saturday, September 10, 2011

Useful Jython scripts for GUESS, The Graph Exploration System

Often the data that we import in GUESS is in such a form that to look at every node and edge distinctly we need to do lot of repositioning and have to set many features so that the graph look elegant in terms of its visualization.

Here is a quick fix to this problem. In the following script i am going to set the node color, edge color, size of nodes,label visibility, label color,  the layout of the graph, and most importantly if you are working with the weighted graph, i am going to make the width of the edges of the graph proportional to their corresponding weight. Also in case of signed graph the color of the positive edges and the negative edges will be distinct which will make it easy for you to recognize them at once.



def modify_graph():
    edgeset=g.getEdges()
    if edgeset.size()>0:
        edgeset1=g.getEdges()
        maxweight=-1000
        minweight=1000
        i=0
        rescaleLayout(1280,800)
        for i in edgeset:
            i.labelvisible=false
            i.labelcolor=black
            if i.weight>0:
                i.color=limegreen
            else:
                i.color=red
                edgeset1.remove(i)
        for i in range (edgeset1.size()):
            if edgeset1[i].weight<minweight:
                minweight=edgeset1[i].weight
            if edgeset1[i].weight>maxweight:
                maxweight=edgeset1[i].weight
        diff=maxweight-minweight
        x=1.0
        max=0
        x=.01
        while max<=10:
            max=maxweight*x
            x=x+.01
        i=0
        for i in range (edgeset1.size()):
            edgeset1[i].width=(edgeset1[i].weight*x)
    nodeset=g.getNodes()
    for n in nodeset:
        n.width = 20
        n.height = 20
        n.labelvisible=true
        n.labelcolor=black
        n.color=black
        n.style = 2
    g.kkLayout()
modify_graph()   

useful script for GUESS, The Graph Exploration System

1) animhighlight.py
This script responds to your mouse positioning over a particular node. After running the script, as soon as you will take the mouse cursor to the node it will highlight the node and its corresponding neighbors with yellow color. Also the edges between the node and its neighbor will be highlighted in red. The nodes and edges will retain their previous color when you will leave that node. The Jython script for the same is as below

import java

class animhighlight(java.lang.Object):

    # so we can "unhighlight" nodes
    _toFix = {}
   
    def __init__(self):
        # add the listeners
        graphevents.mouseEnterNode = self.mouseEnter
        graphevents.mouseLeaveNode = self.mouseLeave
        graphevents.clickNode = self.mouseClick
       
        # remove default behaviors
        vf.defaultNodeHighlights(false)
        vf.defaultNodeZooming(false)

    def mouseEnter(self,_node):
        self._toFix[_node] = _node.color
        StatusBar.setStatus(str(_node))
        _node.color = yellow

        for _e in _node.getOutEdges():
            if not (_e in self._toFix.keys()):
                self._toFix[_e] = _e.color
                _e.color = orange
                _e.animate("arrows")

        for _e in _node.getInEdges():
            if not (_e in self._toFix.keys()):
                self._toFix[_e] = _e.color
                _e.color = green
                _e.animate("arrows")

        for _n in _node.getPredecessors():
            if (_n != _node):
                self._toFix[_n] = _n.color
                _n.color = green
                _n.animate("pulse")

        for _n in _node.getSuccessors():
            if (_n != _node):
                self._toFix[_n] = _n.color
                _n.color = red
                _n.animate("pulse")



    def mouseLeave(self,_node):
        # put back all the original colors
        # and stop animations
        for _elem in self._toFix.keys():
            _elem.color = self._toFix[_elem]
            _elem.animationStopAll()
        self._toFix.clear();

    def mouseClick(self,_node):
        # zoom to the node AND its neighbors
        _toCenter = [_node]
        _toCenter += _node.getNeighbors()
        center(_toCenter)

animhighlight()

Friday, September 9, 2011

How to run a Jython script automatically when the GUESS starts?

If you have installed guess on your windows machine then generally the path of installation is
c:\program files\GUESS\
If you want to run a scripts as soon as you start the guess from the guess.bat file present in the above mentioned folder then here is the step by step process to do the following.
step1) place your script xyz.py in the parent folder of GUESS
step 2) Make a net .bat file naming newguess.bat in the above parent folder
step3) In the file write "start guess.bat null xyz.py"
step4) give the administrative privilege to the newguess.bat file

now it should run same as expected.





The data network graph in .gdf format

During the course of my studies i have created and compiled many graph networks from many formats to .gdf format. ".gdf" is the graph definition format which is the standard format of data for graph exploration system GUESS. There is no such repository for .gdf graph and the research scholars have to face many problems while compiling their data into the proper format with elegant positioning of the nodes.

I have good amount of data for both the signed and the unsigned networks. The list of the well known literature data i have in .gdf format is as below.

1)  9/11 terrorist attack data .gdf format. Originally compiled by Valdis Kerbs
2) 9/11 Terrorist attack data in weighted form
3) Social Network of Bottlenose Dolphin, weighed form
4) Gahuku-Gama subtribes network, signed form .gdf format
5) Jemaah Islamiah (JI) bali bombing terrorist network .gdf format
6) lesmis.gdf , the weighted network of characters from WILLIAM SHAKESPEAR's novel Les-Misreables 
7)Karate club network
8) communication network within a small enterprise: a sawmill.gdf
9)Networks who were analyzed by other researchers in the field of social Network analysis and terrorist network analysis are also available.
10) Few randomly generated network graphs.

Guess version 1.04 Beta



GUESS version 1.04 Beta was released on 24/08/2009. The latest version of guess that is available on the internet in the form of executable files is 1.03 Beta, but Eytan has also released the guess 1.04 Beta version which is really hard to find over the internet and it is really too very hard to compile it and make executable files out of it. If you need version 1.04 Beta which because of lots of change itself should have been something like Guess version 2.0, you can send me a mail at tushar.sharma.9@gmail.com. I am attaching few snapshots of Guess 1.04 Beta for you to figure it out at yourself how many changes it has gone through.