rgraph 0.0.5 → 0.0.6
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.
- data/lib/rgraph/graph.rb +10 -0
- data/lib/rgraph/version.rb +1 -1
- data/spec/rgraph/graph_spec.rb +5 -2
- metadata +1 -1
data/lib/rgraph/graph.rb
CHANGED
@@ -45,6 +45,16 @@ class Graph
|
|
45
45
|
degrees.inject(:+) / @nodes.size.to_f
|
46
46
|
end
|
47
47
|
|
48
|
+
def cumulative_degree
|
49
|
+
cached_degrees = degrees
|
50
|
+
cum = []
|
51
|
+
|
52
|
+
0.upto(degrees.max - 1) do |i|
|
53
|
+
cum[i] = cached_degrees.select{|degree| degree > i}.count
|
54
|
+
end
|
55
|
+
cum.map{|a| a / cum.max.to_f}
|
56
|
+
end
|
57
|
+
|
48
58
|
private
|
49
59
|
|
50
60
|
def get_node_by_id(node_id)
|
data/lib/rgraph/version.rb
CHANGED
data/spec/rgraph/graph_spec.rb
CHANGED
@@ -43,11 +43,14 @@ describe Graph do
|
|
43
43
|
|
44
44
|
describe "Metrics" do
|
45
45
|
subject { Graph.new('spec/fixtures/three_links.csv') }
|
46
|
-
it "
|
46
|
+
it "all nodes degree" do
|
47
47
|
expect(subject.degrees).to eq([2,2,2])
|
48
48
|
end
|
49
|
-
it "
|
49
|
+
it "average degree" do
|
50
50
|
expect(subject.average_degree).to eq(2)
|
51
51
|
end
|
52
|
+
it "cumulative degree" do
|
53
|
+
expect(subject.cumulative_degree).to eq([1.0, 1.0])
|
54
|
+
end
|
52
55
|
end
|
53
56
|
end
|