Wednesday, March 29, 2023

Visualization of network structure on the peersim simulator

Guest Author: Nisarg Negi, M.S. Data Science, UB  

Peersim is an open-source simulator for large-scale peer-to-peer systems. It can be used to design and test large-scale machine-learning algorithms. One example is a large-scale, Support Vector Machine algorithm -- Gossip-bAseD sub-GradiEnT SVM (Source Code). The ready-to-use implementation of gossip-based protocols on the simulator is a powerful alternative to serverless Federated Learning environments. 

Visualizing the graph structure in Peersim is often a cumbersome task. The following description provides one example of how this can be accomplished. We assume that the graph will be generated using the wireKOut configuration:

network.size 5 network.node.size 5 network.node.dim 4932 network.node peersim.gossip.PegasosNode network.node.resourcepath data/sido network.node.lambda 0.0001 network.node.maxiter 1 network.node.examperiter 1 degree 2 protocol.0 peersim.core.IdleProtocol protocol.0.cache degree protocol.1 peersim.gossip.GadgetProtocol protocol.1.linkable 0 # learning rate and iter for GADGET, keep lambda smaller and iter larger protocol.1.lambda 0.0001 protocol.1.iter 1 protocol.1.prot pushsum1 protocol.1.prot pushSV protocol.1.method randomr protocol.1.param 1 init.0 peersim.dynamics.WireKOut init.0.protocol 0 init.0.k degree

For this, we had to modify some components of the peersim GraphFactory library. Since the code runs from the configuration file, more than simple editing of our code would be required.

We call GraphIO and create this graph, but we modified the library.
In the GraphFactory, after the graph is generated we call the GraphIO function and pass our randomly generated graph as a parameter. GraphIO returns the Graph saved in DOT format as below:

We saved the above configuration in a text file. On Unix systems, we can install graphviz:
sudo apt install graphviz
and utilize it to convert the text output graph to a better-visualized graph with the command:

dot -Tpng network_digraph_output.txt -o graph.png

The following code changes are required in the wireKOut function:

public static Graph wireKOut( Graph g, int k, Random r ) { final int n = g.size(); if( n < 2 ) return g; if( n <= k ) k=n-1; int[] nodes = new int[n]; for(int i=0; i<nodes.length; ++i) nodes[i]=i; for(int i=0; i<n; ++i) { int j=0; while(j<k) { int newedge = j+r.nextInt(n-j); int tmp = nodes[j]; nodes[j] = nodes[newedge]; nodes[newedge] = tmp; if( nodes[j] != i ) { g.setEdge(i,nodes[j]); j++; } } } ///Code to print the graph network try { System.out.print("\n GraphFactory:"+ g.toString()+ "\n"); peersim.graph.GraphIO.writeDOT( g,System.err); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try {//saving network digraph to file //Can use graphviz to print it, linux commands below: //sudo apt install graphviz //dot -Tpng network_digraph_output.txt -o graph.png FileOutputStream fos = new FileOutputStream("network_digraph_output.txt"); PrintStream ps = new PrintStream(fos); peersim.graph.GraphIO.writeDOT(g,ps); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return g; }



Monday, December 13, 2021

Bhavana Little Magazine, Vol 3.

 The third volume of our little magazine is available from:

https://drive.google.com/file/d/1gA8gIlj7700LUA1CGExF2i_5zMMUPKR9/view?usp=sharing

Among the interesting highlights are:

a. A personal narrative about Fall colors in Vermont written by my dad.  Not only is it an outstanding contribution, the perseverance involved in getting this done is inspiring. 

b. A book entitled "The Landfall", which has a very interesting plot and showcases life in Bengal intermingled by foreign influence, current political events, and the global pandemic. Please do request for a copy from the authors

c. A third grader, Advik who paints and draws like a pro! He is just amazing.

It would be wonderful to receive comments, thoughts and suggestions. Please provide your feedback using the form below. Alternatively, you can email The Editorial Team at bhavanamag@gmail.com

Bhavana Little Magazine, Vol 2

 The second volume of our little magazine is available from 

https://drive.google.com/file/d/1egs5th7wL2lRm3tqP8e4nfXKk_8IlprJ/view?usp=sharing

Tuesday, December 7, 2021

Homemade Almond and Cranberry Biscotti


 When the store stopped selling them, and you still crave for them, there remains no option but bake them! But did you know that biscotti literally means twice baked and it for this reason that they have the crunch and can survive longer than soft cookies? 'Tis the holiday season - enjoy a few with hot chocolate!

Sunday, November 7, 2021

Bird Conservation in Erie County, NY

 My son made a new bird feeder from recyclable materials and the sparrows and cardinals are now regular visitors. We don't know for how long though -- the ground is already frozen and the birds may have to fly South. 

Frozen Ground in early November

The new bird feeder

He also made an interesting poster advocating bird conservation in Erie County -- the drawings of birds are inspired by the work of naturalist Charlie Harper