SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
Graph Libraries
Overview on Networkx, SNAP
SNAP
http://snap.stanford.edu
Stanford Large Network Dataset Collection
http://snap.stanford.edu/data/index.html
Name Type Nodes Edges Description
ego-Facebook Undirected 4,039 88,234 Social circles from Facebook (anonymized)
ego-Gplus Directed 107,614 13,673,453 Social circles from Google+
ego-Twitter Directed 81,306 1,768,149 Social circles from Twitter
soc-Epinions1 Directed 75,879 508,837 Who-trusts-whom network of Epinions.com
soc-LiveJournal1 Directed 4,847,571 68,993,773 LiveJournal online social network
soc-Pokec Directed 1,632,803 30,622,564 Pokec online social network
soc-Slashdot0811 Directed 77,360 905,468 Slashdot social network from November 2008
soc-Slashdot0922 Directed 82,168 948,464 Slashdot social network from February 2009
wiki-Vote Directed 7,115 103,689 Wikipedia who-votes-on-whom network
wiki-RfA Directed, Signed 10,835 159,388 Wikipedia Requests for Adminship (with text)
Social networks
Visualizating by web
Manipulation
Reading file
Write out JSON
HTML CSS
Creating a graph
from networkx import *
G = Graph()
G.add_edges_from([(1, 2), (1, 5), (2, 3), (2, 5), (3, 4), (4, 5), (4, 6)])
Graph generators
https://networkx.github.io/documentation/latest/
reference/generators.html
Example of generators
Parameters: r : int
Branching factor of the tree
h : int
Height of the tree
create_using : NetworkX graph type, optional
Use specified type to construct graph (default = networkx.Graph)
Returns: G : networkx Graph
A tree with n nodes
balanced_tree
balanced_tree(r, h, create_using=None) [source]

Return the perfectly balanced r-tree of height h.
G = balanced_tree(2, 2)
Generating JSON data
https://networkx.github.io/documentation/latest/
reference/readwrite.json_graph.html
Generating JSON
JSON
Generate and parse JSON serializable data for NetworkX graphs.
These formats are suitable for use with the d3.js examples http://d3js.org/
import json
from networkx import *
from networkx.readwrite import json_graph
G = balanced_tree(2, 2)
# Return data in node-link format that is suitable for JSON serialization.
JsonG = json_graph.node_link_data(G)
# Writing JsonG to output.json by python's native json encoder.
json.dump(JsonG, open('output.json', 'w'))
Rendering HTML
index.html
<head>
<title>Force-Directed Layout</title>
<script src=“//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js”></script>
<link type="text/css" rel="stylesheet" href="force.css"/>
</head>
<body>
<div id="chart"></div>
<script src="force.js"></script>
</body>
var vis = d3.select("#chart")
.append("svg:svg")
.attr("width", w).attr("height", h);
d3.json("output.json", function(json) {
var force = d3.layout.force()
.charge(-120)
.linkDistance(30)
.nodes(json.nodes)
.links(json.links)
.size([w, h])
.start();
force.js
Github example
D3.js force-directed layout
Reading a graph
https://networkx.github.io/documentation/latest/
reference/readwrite.html
Reading a graph
import json
from networkx import *
from networkx.readwrite import json_graph
# return [‘881 858’, ‘828 697’, ‘884 864’, …]
Edges = open(‘net.edges’).read().splitlines()
# Parse lines of an edge list representation of a graph.
G = parse_edgelist(Edges, delimiter = ' ')
881 858
828 697
884 864
856 869
889 856
872 873
719 713
861 863
840 803
864 856
719 840
745 805
865 857
874 873
708 823
872 885
870 871
888 889
825 889
869 774
729 888
769 869
823 840
861 729
774 769
805 800
713 819
774 856
885 859
729 876
net.edges
Implementing Constellation
import json
from networkx import *
from networkx.readwrite import json_graph
# gnp_random_graph(Nodes, Probability for edge creation)
G = gnp_random_graph(10, 0.4)
Degrees = G.degree()
MaxDeg = max(Degrees, key=Degrees.get)
Neighbors = G.neighbors(MaxDeg)
JsonG = json_graph.node_link_data(G)
# Coloring max deg and it's neighbors
JsonG['nodes'][MaxDeg]['group'] = 1
for node in Neighbors:
JsonG['nodes'][node]['group'] = 1
json.dump(JsonG, open('output.json', 'w'))
Q&A

Más contenido relacionado

La actualidad más candente

R statistics with mongo db
R statistics with mongo dbR statistics with mongo db
R statistics with mongo db
MongoDB
 

La actualidad más candente (19)

Exploring Titan and Spark GraphX for Analyzing Time-Varying Electrical Networks
Exploring Titan and Spark GraphX for Analyzing Time-Varying Electrical Networks Exploring Titan and Spark GraphX for Analyzing Time-Varying Electrical Networks
Exploring Titan and Spark GraphX for Analyzing Time-Varying Electrical Networks
 
R statistics with mongo db
R statistics with mongo dbR statistics with mongo db
R statistics with mongo db
 
Data Wrangling and Visualization Using Python
Data Wrangling and Visualization Using PythonData Wrangling and Visualization Using Python
Data Wrangling and Visualization Using Python
 
Incremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher QueriesIncremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher Queries
 
Sea Amsterdam 2014 November 19
Sea Amsterdam 2014 November 19Sea Amsterdam 2014 November 19
Sea Amsterdam 2014 November 19
 
Ling liu part 01:big graph processing
Ling liu part 01:big graph processingLing liu part 01:big graph processing
Ling liu part 01:big graph processing
 
High Performance Python - Marc Garcia
High Performance Python - Marc GarciaHigh Performance Python - Marc Garcia
High Performance Python - Marc Garcia
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Data Science Keys to Open Up OpenNASA Datasets - PyData New York 2017
Data Science Keys to Open Up OpenNASA Datasets - PyData New York 2017Data Science Keys to Open Up OpenNASA Datasets - PyData New York 2017
Data Science Keys to Open Up OpenNASA Datasets - PyData New York 2017
 
Chengqi zhang graph processing and mining in the era of big data
Chengqi zhang graph processing and mining in the era of big dataChengqi zhang graph processing and mining in the era of big data
Chengqi zhang graph processing and mining in the era of big data
 
Distance oracle - Truy vấn nhanh khoảng cách giữa hai điểm bất kỳ trên đồ thị
Distance oracle - Truy vấn nhanh khoảng cách giữa hai điểm bất kỳ trên đồ thịDistance oracle - Truy vấn nhanh khoảng cách giữa hai điểm bất kỳ trên đồ thị
Distance oracle - Truy vấn nhanh khoảng cách giữa hai điểm bất kỳ trên đồ thị
 
R-programming-training-in-mumbai
R-programming-training-in-mumbaiR-programming-training-in-mumbai
R-programming-training-in-mumbai
 
R language
R languageR language
R language
 
Text classification in scikit-learn
Text classification in scikit-learnText classification in scikit-learn
Text classification in scikit-learn
 
Making Machine Learning Scale: Single Machine and Distributed
Making Machine Learning Scale: Single Machine and DistributedMaking Machine Learning Scale: Single Machine and Distributed
Making Machine Learning Scale: Single Machine and Distributed
 
Indexing Complex PostgreSQL Data Types
Indexing Complex PostgreSQL Data TypesIndexing Complex PostgreSQL Data Types
Indexing Complex PostgreSQL Data Types
 
Mining Big Data in Real Time
Mining Big Data in Real TimeMining Big Data in Real Time
Mining Big Data in Real Time
 
Relaxing global-as-view in mediated data integration from linked data
Relaxing global-as-view in mediated data integration from linked dataRelaxing global-as-view in mediated data integration from linked data
Relaxing global-as-view in mediated data integration from linked data
 
A Scalable Hierarchical Clustering Algorithm Using Spark: Spark Summit East t...
A Scalable Hierarchical Clustering Algorithm Using Spark: Spark Summit East t...A Scalable Hierarchical Clustering Algorithm Using Spark: Spark Summit East t...
A Scalable Hierarchical Clustering Algorithm Using Spark: Spark Summit East t...
 

Similar a Graph Libraries - Overview on Networkx

Playing with d3.js
Playing with d3.jsPlaying with d3.js
Playing with d3.js
mangoice
 
Create Graph and Grid Using D3 Library
Create Graph and Grid Using D3 LibraryCreate Graph and Grid Using D3 Library
Create Graph and Grid Using D3 Library
Yanliang Bao (Beryl)
 

Similar a Graph Libraries - Overview on Networkx (20)

Ingesting streaming data into Graph Database
Ingesting streaming data into Graph DatabaseIngesting streaming data into Graph Database
Ingesting streaming data into Graph Database
 
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
"Визуализация данных с помощью d3.js", Михаил Дунаев, MoscowJS 19
 
Data visualization in python/Django
Data visualization in python/DjangoData visualization in python/Django
Data visualization in python/Django
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
tutorial2-notes2
tutorial2-notes2tutorial2-notes2
tutorial2-notes2
 
tutorial2-notes2
tutorial2-notes2tutorial2-notes2
tutorial2-notes2
 
YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기
 
GitConnect
GitConnectGitConnect
GitConnect
 
D3: Easy and flexible data visualisation using web standards
D3: Easy and flexible data visualisation using web standardsD3: Easy and flexible data visualisation using web standards
D3: Easy and flexible data visualisation using web standards
 
Playing with d3.js
Playing with d3.jsPlaying with d3.js
Playing with d3.js
 
2017 05-26 NodeXL Twitter search #shakeupshow
2017 05-26 NodeXL Twitter search #shakeupshow2017 05-26 NodeXL Twitter search #shakeupshow
2017 05-26 NodeXL Twitter search #shakeupshow
 
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
 
Introduction to D3.js
Introduction to D3.jsIntroduction to D3.js
Introduction to D3.js
 
Create Graph and Grid Using D3 Library
Create Graph and Grid Using D3 LibraryCreate Graph and Grid Using D3 Library
Create Graph and Grid Using D3 Library
 
Extensible RESTful Applications with Apache TinkerPop
Extensible RESTful Applications with Apache TinkerPopExtensible RESTful Applications with Apache TinkerPop
Extensible RESTful Applications with Apache TinkerPop
 
How to Extend Axure's Animation Capability
How to Extend Axure's Animation CapabilityHow to Extend Axure's Animation Capability
How to Extend Axure's Animation Capability
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
 
Yql hacku iitd_2012
Yql hacku iitd_2012Yql hacku iitd_2012
Yql hacku iitd_2012
 
Visualising data: Seeing is Believing - CS Forum 2012
Visualising data: Seeing is Believing - CS Forum 2012Visualising data: Seeing is Believing - CS Forum 2012
Visualising data: Seeing is Believing - CS Forum 2012
 

Último

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 

Graph Libraries - Overview on Networkx

  • 3. Stanford Large Network Dataset Collection http://snap.stanford.edu/data/index.html Name Type Nodes Edges Description ego-Facebook Undirected 4,039 88,234 Social circles from Facebook (anonymized) ego-Gplus Directed 107,614 13,673,453 Social circles from Google+ ego-Twitter Directed 81,306 1,768,149 Social circles from Twitter soc-Epinions1 Directed 75,879 508,837 Who-trusts-whom network of Epinions.com soc-LiveJournal1 Directed 4,847,571 68,993,773 LiveJournal online social network soc-Pokec Directed 1,632,803 30,622,564 Pokec online social network soc-Slashdot0811 Directed 77,360 905,468 Slashdot social network from November 2008 soc-Slashdot0922 Directed 82,168 948,464 Slashdot social network from February 2009 wiki-Vote Directed 7,115 103,689 Wikipedia who-votes-on-whom network wiki-RfA Directed, Signed 10,835 159,388 Wikipedia Requests for Adminship (with text) Social networks
  • 4.
  • 5. Visualizating by web Manipulation Reading file Write out JSON HTML CSS
  • 6. Creating a graph from networkx import * G = Graph() G.add_edges_from([(1, 2), (1, 5), (2, 3), (2, 5), (3, 4), (4, 5), (4, 6)])
  • 8. Example of generators Parameters: r : int Branching factor of the tree h : int Height of the tree create_using : NetworkX graph type, optional Use specified type to construct graph (default = networkx.Graph) Returns: G : networkx Graph A tree with n nodes balanced_tree balanced_tree(r, h, create_using=None) [source]
 Return the perfectly balanced r-tree of height h. G = balanced_tree(2, 2)
  • 9.
  • 11. Generating JSON JSON Generate and parse JSON serializable data for NetworkX graphs. These formats are suitable for use with the d3.js examples http://d3js.org/ import json from networkx import * from networkx.readwrite import json_graph G = balanced_tree(2, 2) # Return data in node-link format that is suitable for JSON serialization. JsonG = json_graph.node_link_data(G) # Writing JsonG to output.json by python's native json encoder. json.dump(JsonG, open('output.json', 'w'))
  • 12. Rendering HTML index.html <head> <title>Force-Directed Layout</title> <script src=“//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js”></script> <link type="text/css" rel="stylesheet" href="force.css"/> </head> <body> <div id="chart"></div> <script src="force.js"></script> </body> var vis = d3.select("#chart") .append("svg:svg") .attr("width", w).attr("height", h); d3.json("output.json", function(json) { var force = d3.layout.force() .charge(-120) .linkDistance(30) .nodes(json.nodes) .links(json.links) .size([w, h]) .start(); force.js Github example D3.js force-directed layout
  • 14. Reading a graph import json from networkx import * from networkx.readwrite import json_graph # return [‘881 858’, ‘828 697’, ‘884 864’, …] Edges = open(‘net.edges’).read().splitlines() # Parse lines of an edge list representation of a graph. G = parse_edgelist(Edges, delimiter = ' ') 881 858 828 697 884 864 856 869 889 856 872 873 719 713 861 863 840 803 864 856 719 840 745 805 865 857 874 873 708 823 872 885 870 871 888 889 825 889 869 774 729 888 769 869 823 840 861 729 774 769 805 800 713 819 774 856 885 859 729 876 net.edges
  • 15. Implementing Constellation import json from networkx import * from networkx.readwrite import json_graph # gnp_random_graph(Nodes, Probability for edge creation) G = gnp_random_graph(10, 0.4) Degrees = G.degree() MaxDeg = max(Degrees, key=Degrees.get) Neighbors = G.neighbors(MaxDeg) JsonG = json_graph.node_link_data(G) # Coloring max deg and it's neighbors JsonG['nodes'][MaxDeg]['group'] = 1 for node in Neighbors: JsonG['nodes'][node]['group'] = 1 json.dump(JsonG, open('output.json', 'w'))
  • 16. Q&A