rgraph 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
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)
@@ -1,3 +1,3 @@
1
1
  module Rgraph
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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 "returns degree of all nodes as an array" do
46
+ it "all nodes degree" do
47
47
  expect(subject.degrees).to eq([2,2,2])
48
48
  end
49
- it "calculates de average degree" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: