Revision 4ceb9f92

View differences:

fiddle/simulation_analysis/plot.sh
1
INPUTDIR=output
2

  
3
for file in `ls output | grep plotdata`;
4
do
5
    echo $file;
6
    ./plot_experiment_result.py -i $INPUTDIR/$file;
7
done
fiddle/simulation_analysis/plot_experiment_result.py
1
#!/usr/bin/env python
2

  
3
"""
4
Input: *.plotdata
5
Output: a graph showing the average of BC and HBC
6
"""
7
import argparse
8
import os
9
import numpy as np
10
import matplotlib.pyplot as plt
11

  
12
class ExperimentVisualizer():
13
    graph_descriptions = {
14
        "CN": "Community Network",
15
        "ER": "Erdos",
16
        "PL": "Power Lab",
17
    }
18

  
19
    def __init__(self):
20
        self.args = None
21
        self.graph_type = None
22

  
23
    def parse_args(self):
24
        parser = argparse.ArgumentParser(description="Plotting the comparison  \
25
                                         between Brandes Betweenness Centrality \
26
                                         (BC) and Heuristic BC (HBC)")
27
        parser.add_argument("-i", dest="input")
28
        parser.add_argument("-o", dest="output", required=False,
29
                            default="")
30

  
31
        self.args = parser.parse_args()
32

  
33
    def plot(self):
34
        input_dir = os.path.dirname(self.args.input)
35
        filename = os.path.splitext(os.path.basename(self.args.input))[0]
36

  
37
        self.graph_type = self.graph_descriptions.get(filename, "")
38

  
39
        if self.args.output == "":
40
            self.args.output = '%s/%s_BC_HBC.png' % (input_dir, filename)
41

  
42
        plot_data = self.read_plot_data()
43

  
44
        # Plot
45
        self.plot_line_graph(plot_data)
46

  
47
    def read_plot_data(self):
48
        plot_data = np.loadtxt(self.args.input,
49
            dtype= {
50
                'names': ('typotype', 'graphtype', 'numofnodes', 'avg_bc', 'avg_hbc',
51
                          'std_bc', 'std_hbc'),
52
                'formats': ('a6', 'a2', 'i4', 'f8', 'f8', 'f8', 'f8')
53
            },
54
            delimiter=','
55
        )
56
        plot_data = plot_data[plot_data['numofnodes'].argsort()]
57
        return plot_data
58

  
59

  
60
    def plot_line_graph(self, plot_data):
61
        x = plot_data['numofnodes']
62
        y1 = plot_data['avg_bc']
63
        y2 = plot_data['avg_hbc']
64

  
65
        plt.plot(x, y1, marker='s', linestyle='-', color='b', label='BC')
66
        plt.plot(x, y2, marker='o', linestyle='--', color='r', label='HBC')
67
        plt.xlabel("Number of nodes")
68
        plt.ylabel("Running time (seconds)")
69
        plt.title("Running time for BC and HBC with %s graphs" % self.graph_type)
70
        plt.legend()
71
        plt.savefig(self.args.output)
72
        plt.close()
73

  
74

  
75
if __name__ == '__main__':
76
    vis = ExperimentVisualizer()
77
    vis.parse_args()
78
    vis.plot()
fiddle/simulation_analysis/script.sh
1 1
./analyzer.py -t 1 -i input/simresult.out1 -p output/
2 2
./analyzer.py -t 2 -i output/simresult.out2 -p output/
3

  
fiddle/simulation_analysis/split_out3.sh
1
OUTFILE=output/simresult.out3
2

  
3
rm -f output/*.plotdata
4

  
5
for x in $(<$OUTFILE);
6
do
7
    echo $x | awk -F"," '{
8
        outfile = "output/" r$2 ".plotdata";
9
        print $x >> outfile;
10
    }'
11
done

Also available in: Unified diff