lib/rgraph/graph.rb in rgraph-0.0.5 vs lib/rgraph/graph.rb in rgraph-0.0.6
- old
+ new
@@ -43,9 +43,19 @@
def average_degree
degrees.inject(:+) / @nodes.size.to_f
end
+ def cumulative_degree
+ cached_degrees = degrees
+ cum = []
+
+ 0.upto(degrees.max - 1) do |i|
+ cum[i] = cached_degrees.select{|degree| degree > i}.count
+ end
+ cum.map{|a| a / cum.max.to_f}
+ end
+
private
def get_node_by_id(node_id)
@nodes.select{|n| n.id == node_id}.first
end