networkx 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/README.md +20 -22
- data/lib/networkx/link_analysis/pagerank.rb +3 -47
- data/lib/networkx/version.rb +1 -1
- data/networkx.gemspec +5 -1
- metadata +6 -6
- data/.github/workflows/gem-push.yml +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39e75c0ad21604275a008c53a29f282d681f3c50cb7648470cc6e4e2cffa5071
|
4
|
+
data.tar.gz: 93e93f5a2603beb715b38856518ed47e698c0978c5ff02a737a7baff68357e8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ce185b8e9246db7b791d4d1800b39d1ad9a5f1036c99899842554c31e2400469d775acd382c2dfc27275857db58e66228062502bffefb16ddca4c3a63b346fe
|
7
|
+
data.tar.gz: 9b615db49ec2ba5e06bbfecf1710849d079661b301a85493740434eae464bfd74c250c38c31ed2cc5dfb93983cb2c7315fe27452c2f6a243051ac1f80512816b
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
# NetworkX.rb
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/networkx.svg)](https://badge.fury.io/rb/networkx)
|
4
|
+
|
3
5
|
[NetworkX](https://networkx.github.io/) is a very popular Python library, that handles various use-cases of the Graph Data Structure.
|
4
6
|
This project intends to provide a working alternative to the Ruby community, by closely mimicing as many features as possible.
|
5
7
|
|
6
8
|
## List of contents
|
7
9
|
|
8
10
|
- [Installing](#installing)
|
11
|
+
- [Usage](#Usage)
|
9
12
|
- [Document](#document)
|
10
|
-
- [Roadmap](#roadmap)
|
11
13
|
- [Contributing](#contributing)
|
12
14
|
- [License](#license)
|
13
15
|
|
14
16
|
## Installing
|
15
17
|
|
16
|
-
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
- install it yourself as:
|
19
|
+
```console
|
20
|
+
$ gem install networkx
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
- Or use Bundler & Gemfile
|
25
|
+
1. add this line to your application's Gemfile:
|
26
|
+
```ruby
|
27
|
+
gem 'networkx'
|
28
|
+
```
|
29
|
+
2. And then execute:
|
30
|
+
```console
|
31
|
+
$ bundle install
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
21
35
|
|
22
36
|
```ruby
|
23
37
|
require 'networkx'
|
@@ -30,22 +44,6 @@ g.add_edge('start', 'stop')
|
|
30
44
|
|
31
45
|
You can read [Document](https://SciRuby.github.io/networkx.rb/) for this library.
|
32
46
|
|
33
|
-
## Roadmap
|
34
|
-
|
35
|
-
Quite easily, any networkx user would be able to understand the number of details that have been implemented in the Python library. As a humble start towards the release of v0.1.0, the following could be the goals to achieve :
|
36
|
-
|
37
|
-
- `Node` : This class should be capable of handling different types of nodes (not just `String` / `Integer`).
|
38
|
-
A possible complex use-case could be XML nodes.
|
39
|
-
|
40
|
-
- `Edge` : This class should be capable of handling different types of edges.
|
41
|
-
Though a basic undirected Graph doesn't store any metadata in the edges, weighted edges and parametric edges are something that need to be handled.
|
42
|
-
|
43
|
-
- `Graph` : The simplest of graphs.
|
44
|
-
This class handles just connections between different `Node`s via `Edge`s.
|
45
|
-
|
46
|
-
- `DirectedGraph` : Inherits from `Graph` class.
|
47
|
-
Uses directions between `Edge`s.
|
48
|
-
|
49
47
|
## Contributing
|
50
48
|
|
51
49
|
Your contributions are always welcome!
|
@@ -2,61 +2,16 @@ module NetworkX
|
|
2
2
|
# Computes pagerank values for the graph
|
3
3
|
#
|
4
4
|
# @param graph [Graph] a graph
|
5
|
-
# @param init [Array<Numeric>] initial pagerank values for the nodes
|
6
5
|
# @param alpha [Numeric] the alpha value to compute the pagerank
|
7
6
|
# @param eps [Numeric] tolerence to check for convergence
|
8
7
|
# @param max_iter [Integer] max iterations for the pagerank algorithm to run
|
9
8
|
#
|
10
|
-
# @return [
|
11
|
-
def self.pagerank(graph,
|
12
|
-
dim = graph.nodes.length
|
13
|
-
if init.nil?
|
14
|
-
init = graph.nodes(data: false).to_h{ |i| [i, 1.0 / dim] }
|
15
|
-
else
|
16
|
-
s = init.values.sum.to_f
|
17
|
-
init = init.transform_values { |v| v / s }
|
18
|
-
end
|
19
|
-
raise ArgumentError, 'Init array needs to have same length as number of graph nodes!' \
|
20
|
-
unless dim == init.length
|
21
|
-
|
22
|
-
matrix = []
|
23
|
-
elem_ind = {}
|
24
|
-
p = []
|
25
|
-
curr = init.values
|
26
|
-
init.keys.each_with_index { |n, i| elem_ind[n] = i }
|
27
|
-
graph.adj.each do |_u, u_edges|
|
28
|
-
adj_arr = Array.new(dim, 0)
|
29
|
-
u_edges.each do |v, _|
|
30
|
-
adj_arr[elem_ind[v]] = 1
|
31
|
-
end
|
32
|
-
matrix << adj_arr
|
33
|
-
end
|
34
|
-
(0..(dim - 1)).each do |i|
|
35
|
-
p[i] = []
|
36
|
-
(0..(dim - 1)).each { |j| p[i][j] = matrix[i][j] / (matrix[i].sum * 1.0) }
|
37
|
-
end
|
38
|
-
|
39
|
-
max_iter.times do |_|
|
40
|
-
prev = curr.clone
|
41
|
-
dim.times do |i|
|
42
|
-
ip = 0
|
43
|
-
dim.times { |j| ip += p.transpose[i][j] * prev[j] }
|
44
|
-
curr[i] = (alpha * ip) + ((1 - alpha) / (dim * 1.0))
|
45
|
-
end
|
46
|
-
err = 0
|
47
|
-
dim.times { |i| err += (prev[i] - curr[i]).abs }
|
48
|
-
return curr if err < eps
|
49
|
-
end
|
50
|
-
raise ArgumentError, 'PageRank failed to converge!'
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.pagerank2(graph, alpha: 0.85, personalization: nil, eps: 1e-6, max_iter: 100)
|
9
|
+
# @return [Hash of Object => Float] pagerank values of the graph
|
10
|
+
def self.pagerank(graph, alpha: 0.85, personalization: nil, eps: 1e-6, max_iter: 100)
|
54
11
|
n = graph.number_of_nodes
|
55
12
|
|
56
13
|
matrix, index_to_node = NetworkX.to_matrix(graph, 0)
|
57
14
|
|
58
|
-
# index_to_node = {0=>0, 1=>1, 2=>2, 3=>3}
|
59
|
-
|
60
15
|
index_from_node = index_to_node.invert
|
61
16
|
|
62
17
|
probabilities = Array.new(n) do |i|
|
@@ -84,6 +39,7 @@ module NetworkX
|
|
84
39
|
err = (0...n).map{|i| (prev[i] - curr[i]).abs }.sum
|
85
40
|
return (0...n).map{|i| [index_to_node[i], curr[i]] }.sort.to_h if err < eps
|
86
41
|
end
|
42
|
+
warn "pagerank() failed within #{max_iter} iterations. Please inclease max_iter: or loosen eps:"
|
87
43
|
(0...n).map{|i| [index_to_node[i], curr[i]] }.sort.to_h
|
88
44
|
end
|
89
45
|
end
|
data/lib/networkx/version.rb
CHANGED
data/networkx.gemspec
CHANGED
@@ -13,13 +13,15 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.email = ['athityakumar@gmail.com']
|
14
14
|
spec.summary = 'A Ruby implemenation of the well-known graph library called networkx.'
|
15
15
|
spec.description = NetworkX::DESCRIPTION
|
16
|
-
spec.homepage = 'https://github.com/
|
16
|
+
spec.homepage = 'https://github.com/SciRuby/networkx.rb'
|
17
17
|
spec.license = 'MIT'
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
19
|
spec.bindir = 'bin'
|
20
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
+
spec.required_ruby_version = '>= 2.7'
|
24
|
+
|
23
25
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
24
26
|
spec.add_development_dependency 'rake', '~> 13.0'
|
25
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
@@ -34,4 +36,6 @@ Gem::Specification.new do |spec|
|
|
34
36
|
|
35
37
|
spec.add_runtime_dependency 'matrix', '~> 0.4'
|
36
38
|
spec.add_runtime_dependency 'rb_heap', '~> 1.0'
|
39
|
+
|
40
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
37
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: networkx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Athitya Kumar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -207,7 +207,6 @@ files:
|
|
207
207
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
208
208
|
- ".github/workflows/ci.yml"
|
209
209
|
- ".github/workflows/doc.yml"
|
210
|
-
- ".github/workflows/gem-push.yml"
|
211
210
|
- ".gitignore"
|
212
211
|
- ".rspec"
|
213
212
|
- ".rubocop.yml"
|
@@ -259,10 +258,11 @@ files:
|
|
259
258
|
- lib/networkx/traversals/edge_dfs.rb
|
260
259
|
- lib/networkx/version.rb
|
261
260
|
- networkx.gemspec
|
262
|
-
homepage: https://github.com/
|
261
|
+
homepage: https://github.com/SciRuby/networkx.rb
|
263
262
|
licenses:
|
264
263
|
- MIT
|
265
|
-
metadata:
|
264
|
+
metadata:
|
265
|
+
rubygems_mfa_required: 'true'
|
266
266
|
post_install_message:
|
267
267
|
rdoc_options: []
|
268
268
|
require_paths:
|
@@ -271,7 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
271
271
|
requirements:
|
272
272
|
- - ">="
|
273
273
|
- !ruby/object:Gem::Version
|
274
|
-
version: '
|
274
|
+
version: '2.7'
|
275
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
276
276
|
requirements:
|
277
277
|
- - ">="
|
@@ -1,45 +0,0 @@
|
|
1
|
-
name: Ruby Gem
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ main ]
|
6
|
-
pull_request:
|
7
|
-
branches: [ main ]
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
build:
|
11
|
-
name: Build + Publish
|
12
|
-
runs-on: ubuntu-latest
|
13
|
-
permissions:
|
14
|
-
contents: read
|
15
|
-
packages: write
|
16
|
-
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v2
|
19
|
-
- name: Set up Ruby 2.6
|
20
|
-
uses: actions/setup-ruby@v1
|
21
|
-
with:
|
22
|
-
ruby-version: 2.6.x
|
23
|
-
|
24
|
-
- name: Publish to GPR
|
25
|
-
run: |
|
26
|
-
mkdir -p $HOME/.gem
|
27
|
-
touch $HOME/.gem/credentials
|
28
|
-
chmod 0600 $HOME/.gem/credentials
|
29
|
-
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
30
|
-
gem build *.gemspec
|
31
|
-
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
32
|
-
env:
|
33
|
-
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
34
|
-
OWNER: ${{ github.repository_owner }}
|
35
|
-
|
36
|
-
- name: Publish to RubyGems
|
37
|
-
run: |
|
38
|
-
mkdir -p $HOME/.gem
|
39
|
-
touch $HOME/.gem/credentials
|
40
|
-
chmod 0600 $HOME/.gem/credentials
|
41
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
42
|
-
gem build *.gemspec
|
43
|
-
gem push *.gem
|
44
|
-
env:
|
45
|
-
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|