find_communities 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4baabfdcee6316ce51e6f68b4535e15ce0ecba2
4
- data.tar.gz: 160f7bbd40b8bbde535ff26d11df977cf5c34f55
3
+ metadata.gz: 26db4fdbab99e3162dcf8b14bb14030c9229686a
4
+ data.tar.gz: 7e2a64dbe57d6c6e5c07cd20e95597f331e2c8af
5
5
  SHA512:
6
- metadata.gz: bd8a31638591661e62877c976c3c4be5835efa0781582897c7df3352f91e33c48c936e7b2fd0357a9d6d09cf5a1a35e41be9169d2eb93a978d1ed8c437317683
7
- data.tar.gz: 507a858459bc54620e901390dd892069ea838f81159f073483565af48f2824b36244c8b27fda1adaa8985f3bfa31d8ba8782a0ff33997f00ef4dd46630690212
6
+ metadata.gz: 94b8c318dbd8db9cbb6bb73c7b096871f2f589ee2342be9bff3765aee25fa6dadeb0abe18653ecfae774bcb233366168dac2d2027217a8cda794ef8fd0bde091
7
+ data.tar.gz: 78fcf5ed0acbbf38f748212089fb6208e1019cdb9b42ddd61686baddc0e2f7664d3220ee516f87628a36868a7d8d5fb80d56b5e883bc913fb4b35dd066c96bd6
data/bin/community CHANGED
@@ -3,13 +3,14 @@
3
3
  require 'thor'
4
4
  require File.dirname(__FILE__)+"/../lib/find_communities"
5
5
 
6
- class CommunityMain < Thor
7
- method_option :level, :aliases => "-l", :desc => "displays the graph of level k rather than the hierachical structure. if k=-1 then displays the hierarchical structure rather than the graph at a given level"
8
- method_option :verbose, :aliases => "-v", :desc => "verbose mode: gives computation time, information about the hierarchy and modularity."
6
+ class CommunityMain < Thor::Group
9
7
 
10
- desc "community", "Decompose graph into communities"
8
+ class_option :level, :default => -1, :aliases => "-l", :desc => "displays the graph of level k rather than the hierachical structure. if k=-1 then displays the hierarchical structure rather than the graph at a given level"
9
+ class_option :verbose, :type => :boolean, :aliases => "-v", :desc => "verbose mode: gives computation time, information about the hierarchy and modularity."
10
+
11
+ desc "Decompose graph into communities"
11
12
  argument :filename
12
- def community
13
+ def act
13
14
  t0 = Time.now
14
15
  verbose = options[:verbose]
15
16
  puts "Begin: #{t0}" if verbose
@@ -25,12 +26,12 @@ class CommunityMain < Thor
25
26
  if verbose
26
27
  puts "level #{level}:"
27
28
  puts " start computation #{Time.now}"
28
- puts " network size: #{c.g.nb_nodes} nodes, #{c.g.nb_links} links, #{c.g.total_weight} weight."
29
+ puts " network size: #{c.g.nb_nodes} nodes, #{c.g.nb_links} links, #{c.g.total_weight.to_i} weight."
29
30
  end
30
31
  improvement = c.one_level
31
32
  new_mod = c.modularity
32
33
  level += 1
33
- g.display if level == display_level && g
34
+ g.display_graph if level == display_level && g
34
35
  c.display_partition if display_level == -1
35
36
  g = c.partition2graph_binary
36
37
  c = FindCommunities::Community.new(g, -1, precision)
@@ -50,7 +51,10 @@ class CommunityMain < Thor
50
51
  puts "%.6f" % new_mod
51
52
  end
52
53
 
53
- default_task :community
54
+ private
55
+ def self.banner
56
+ "community FILENAME"
57
+ end
54
58
  end
55
59
 
56
60
  CommunityMain.start
@@ -21,6 +21,21 @@ module FindCommunities
21
21
  }
22
22
  end
23
23
 
24
+ def display_graph
25
+ nb_nodes.times do |node|
26
+ p = neighbors(node)
27
+ print "#{node}:"
28
+ nb_neighbors(node).times do |i|
29
+ if weights.any?
30
+ print " (#{p.first[i]} #{p.last[i].to_i})"
31
+ else
32
+ print " #{p.first[i]}"
33
+ end
34
+ end
35
+ print "\n"
36
+ end
37
+ end
38
+
24
39
  def nb_neighbors(node)
25
40
  check_node(node)
26
41
  node == 0 ? degrees[0] : degrees[node] - degrees[node-1]
@@ -1,3 +1,3 @@
1
1
  module FindCommunities
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,13 +1,58 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "community (executable)" do
4
- it "outputs a hierarchy", :retry => 3 do
5
- filename = File.dirname(__FILE__) + "/../data/karate.bin"
6
- run "community -l -1 #{filename}"
7
- relevant_lines = out.split("\n").last(4)
8
- relevant_lines[0].should == "1 1"
9
- relevant_lines[1].should == "2 2"
10
- relevant_lines[2].should == "3 3"
11
- relevant_lines[3].to_f.round(1).should == 0.4
4
+ let(:filename) { File.dirname(__FILE__) + "/../data/karate.bin" }
5
+
6
+ context "outputs a hierarchy", :retry => 2 do
7
+ it "works when no level given" do
8
+ run "community #{filename}"
9
+ relevant_lines = out.split("\n").last(4)
10
+ 3.times do |i|
11
+ relevant_lines[i].should == "#{i+1} #{i+1}"
12
+ end
13
+ relevant_lines[3].to_f.round(2).should == 0.43
14
+ end
15
+
16
+ it "works when level given is -1" do
17
+ run "community -l -1 #{filename}"
18
+ relevant_lines = out.split("\n").last(4)
19
+ 3.times do |i|
20
+ relevant_lines[i].should == "#{i+1} #{i+1}"
21
+ end
22
+ relevant_lines[3].to_f.round(2).should == 0.43
23
+ end
24
+
25
+ it "can provide verbose output", :retry => 2 do
26
+ run "community #{filename} -v"
27
+ output = out
28
+ 3.times do |i|
29
+ output.should match /^level #{i}:\n start computation [0-9\-: ]+\n network size: \d+ nodes, \d+ links, \d+ weight.$(\n\d+ \d+){4,}\n modularity increased from (-)?\d+\.\d+ to \d+\.\d+\n end computation [0-9\-: ]+$/
30
+ end
31
+ lines = output.split("\n")
32
+ lines.first.should match /^Begin: [0-9\-: ]+$/
33
+ lines[lines.length-3].should match /^End: [0-9\-: ]+$/
34
+ lines[lines.length-2].should match /^Total duration: \d+\.\d+ sec\.$/
35
+ lines.last.to_f.round(2).should == 0.43
36
+ end
37
+ end
38
+
39
+ it "outputs level 2 in the hierchy", :retry => 2 do
40
+ run "community -l 2 #{filename}"
41
+ lines = out.split("\n")
42
+ lines.length.should > 5
43
+ lines[0..lines.length-2].each_with_index do |l, i|
44
+ l.should match /\A#{i}:( \(\d+ \d+\)){3,}\z/
45
+ end
46
+ lines.last.to_f.round(2).should == 0.43
47
+ end
48
+
49
+ it "outputs level 3 in the hierchy", :retry => 2 do
50
+ run "community #{filename} -l 3"
51
+ lines = out.split("\n")
52
+ lines.length.should == 5
53
+ lines[0..lines.length-2].each_with_index do |l, i|
54
+ l.should match /\A#{i}:( \(\d+ \d+\)){2,}\z/
55
+ end
56
+ lines.last.to_f.round(2).should == 0.43
12
57
  end
13
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: find_communities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Kopley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-11 00:00:00.000000000 Z
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata