Slide 1 of 9
Wolfram Technologies: Graph Theory and Social Networks
Martin Hadley
Wolfram
martinh@wolfram.com
- |
Wolfram Technologies: Graph Theory and Social Networks Martin - - PDF document
Slide 1 of 9 Wolfram Technologies: Graph Theory and Social Networks Martin Hadley Wolfram martinh@wolfram.com | 2 Wolfram-Technologies_Graph-Theory-Social-Networks.nb Slide 2 of 9 Wolfram Technologies Twenty-Four Years of
Slide 1 of 9
martinh@wolfram.com
Slide 2 of 9
Twenty-Four Years of Scientific and Technological Innovation
Founded by Stephen Wolfram in 1987, British scientist, creator of Mathematica and Wolfram|Alpha and the author of A New Kind of Science Based in Illinois, USA with EMEA offices near Oxford, UK and Asia offices in Tokyo, Japan Employs 600 staff worldwide Wolfram Technology users number in the millions - used in most of the Euro Stoxx 50 companies, several major government departments across the E.U. and all of the world's top 200 universities.
The Core of Wolfram Technologies is Mathematica
2 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
Computability drives us forward
We have developed a free to use Computable Knowledge Engine with an ever growing array of computational algorithms and curated data. We’ve recently launched Wolfram SystemModeler, a multidomain modelling and simulation environment with tight Mathematica integration.
Slide 3 of 9
Building a Graph in Mathematica
Directed and Undirected Graph Interacting with Graph Importing/Exporting Graph
Graph Theory Analytical Methods
Graph Isomorphs, Complement, Difference and GraphDistributions Cliques, Centralities, and Communities Tours and Paths
Graph Theory in Financial Engineering: Risk-Diverse Investment Portfolios Analysing Social Networks with Wolfram Technologies
Wolfram|Alpha Personal Analytics for Facebook Social Network APIs in Mathematica
Slide 4 of 9
The Graph Function
In Mathematica a Graph is built by providing a list of edges to the Graph function
Provide a list of undirected edges, myUnDirectedGraphGraph13,21,34,1
Undirected Graph Directed Graph Building a graph is a non-destructive process, we can easily extract both edges and vertices
We apply the EdgeList function to a graph EdgeListmyUndirectedGraph
1 3, 2 1, 3 4, 1 4 Extracting Edges Extracting Vertices From this list of rules we can reconstruct the original graph, GraphEdgeRulesmyDirectedGraph
Symbolic Input
We can easily insert symbolic objects into our graph,
6 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
symbolic1 Graph
VertexLabels "Name", VertexSize Tiny, ImagePadding 50 symbolic2 Graph 2 3 4 1 0 8 5 7 , 9 0 1 1 2 3 4 1 , 0 8 5 7 9 8 7 5 , 2 3 4 1 9 8 7 5 , VertexLabels "Name", VertexSize Small, ImagePadding 30
2 3 4 1 8 5 7 9 1 1 9 8 7 5
The content remains undestroyed by the Graph function. EdgeRulessymbolic1
2 3 4 1 0 8 5 7 , 9 0 1 1 2 3 4 1 , 0 8 5 7 9 8 7 5 , 2 3 4 1 9 8 7 5 We can extend this functionality to build more complicated visualisations
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 7
web "Aphid" "Ladybug", "Beetle" "Mouse", "Caterpillar" "Beetle", "Caterpillar" "Mouse", "Caterpillar" "Towhee", "Grasshopper" "Mouse", "Grasshopper" "Towhee", "Ladybug" "Towhee", "Louse" "Mouse", "Mosquito" "Dragonfly", "Mosquito" "Towhee", "Mouse" "Owl", "Sunflower" "Aphid", "Sunflower" "Caterpillar", "Sunflower" "Grasshopper", "Sunflower" "Louse", "Towhee" "Owl"; shapes "Sunflower" , "Aphid" , "Ladybug" , "Towhee" , "Owl" , "Grasshopper" , "Louse" , "Caterpillar" , "Beetle" , "Mosquito" , "Dragonfly" , "Mouse" ;
Styling a Graph Highlighting Graph Features
Individual elements of a graph (vertices and edges) can be highlighted specifically HighlightGraphCompleteGraph5, 1, 2, 3 HighlightGraphCompleteGraph5, 1 2, Style3 4, Green
8 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
Import/Export Formats
We support import/export of the most widely used file formats, including; GraphML, GXL, Graphlet, Pajek, TGF, DOT, DIMACS, Graph6, Sparse6, and LEDA. Import"ExampleDataattributes.graphml", "Graph", VertexLabels "Name", ImagePadding 10
n0 n1 n2 n3 n4 n5
Theoretical Graphs
A wide variety of theoretical graphs, and their properties are available via the GraphData function
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 9
GraphData"PappusGraph" GraphData"HeawoodGraph", "Properties" Short Acyclic, AdjacencyMatrix, AllImages, 353, ZeroTwo, ZIndex We can also make queries, like whether a graph belongs to a Class GraphData"CubicalGraph", "Cage" False
Empirical Graphs
ExampleData provides a wide catalogue of empirical graph data, including NetworkGraphs ExampleData"NetworkGraph" Short, 4 & NetworkGraph, AmericanCollegeFootball, NetworkGraph, AskOpinionRecall, NetworkGraph, AskOpinionRecognition, 161, NetworkGraph, WorldCup1988, NetworkGraph, WorldWideWeb, NetworkGraph, ZacharyKarateClub ExampleData"NetworkGraph", "ZacharysKarateClub"
Applying Graph Theory to Example Data
Mathematica provides a wide range of curated data that are usefully visualised with Graph Theory,
10 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
AstronomicalData ElementData GraphData PolyhedronData ChemicalData FinancialData IsotopeData ProteinData CityData GenomeData KnotData WeatherData CountryData GeodesyData ParticleData WordData GraphFlattenThread CountryData, "BorderingCountries" & CountryData"SouthAmerica", VertexShapeFunction "Name"
Argentina Bolivia Brazil Chile Paraguay Uruguay Peru Colombia FrenchGuiana Guyana Suriname Venezuela Ecuador Panama
Slide 5 of 9
Graph Isomorphs, Complement, Difference and GraphDistributions
Isomorphs
Here we compute the isomorph that would convert a PetersenGraph, g PetersenGraph4, 1, VertexLabels "Name", ImagePadding 10
1 2 3 4 5 6 7 8
into an equivalent CompleteGraph. v1 "a", "b", "c", "d"; v2 "e", "f", "g", "h"; edge Tablev1i & Deletev2, 5 i, i, 4 Flatten;
12 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
h GraphJoinv1, v2, edge, VertexLabels "Name", ImagePadding 10, VertexSize Large, AbsoluteOptionsCompleteGraph4, 4, VertexCoordinates
a b c d e f g h
map FindGraphIsomorphismg, h 1 a, 2 e, 3 b, 4 f, 5 g, 6 c, 7 h, 8 d a First map; b Last map; highlightGraphg_, v_ : HighlightGraphg, TableStyleLabeledvi, vi, ColorData"TemperatureMap"i VertexCountg, i, VertexCountg; highlightGraphg, a, highlightGraphh, b
2 3 4 5 6 7 8
,
a b c d e f g h
We can compute GraphComplements through the GraphComplement function. complementList Table CycleGraphn, DirectedEdges True, EdgeStyle Arrowheads0.1, n, 4, 6
,
,
Graph differences may be computed easily through the GraphDifference function.
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 13
randGraph1 RandomGraph13, 14, VertexLabels "Name", ImagePadding 10
1 2 3 4 5 6 7 8 9 10 11 12 13
randGraph2 RandomGraph9, 10, VertexLabels "Name", ImagePadding 10
1 2 3 4 5 6 7 8 9
GraphDifferencerandGraph1, randGraph2, VertexLabels "Name", ImagePadding 10
2 3 4 5 6 7 9 10 11 12 13
14 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
GraphDistributions
Mathematica allows you to request a wide-range of parametric graphs.
1 2 3 4 5
CompleteGraph
1 2 3 4 5 6 7 8 9 10 11 12
ButterflyGraph
1 2 3 4 5 6 7 8 9 10
CirculantGraph
1 2 3 4 5
CycleGraph
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
HypercubeGraph
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
KnightTourGraph
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
PathGraph
1 2 3 4 5 6 7 8 9 10
PetersenGraph
You can request a RandomGraph with n vertices and m edges, RandomGraph6, 7, 3
,
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 15
BarabasiAlbertGraphDistribution graph with n vertices where each
BarabasiAlbertGraphDistribution BernoulliGraphDistribution DegreeGraphDistribution PriceGraphDistribution UniformGraphDistribution WattsStrogatzGraphDistribution
Cliques, Centralities and Communities
Cliques
We can use the FindClique function to find a clique, but in Version 9 we will provide the ability to find n cliques containing k vertices. Here’s an example analysing a standard empirical graph, “DolphinSocialNetwork”. g ExampleData"NetworkGraph", "DolphinSocialNetwork"; FindCliqueg 7, 10, 14, 18, 58
16 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
HighlightGraphg, FindCliqueg
Centralities
Mathematica includes a number of centrality measures, as with all functions these are fully documented at http://www.reference.wolfram.com ? *Centrality
System`
BetweennessCentrality DegreeCentrality HITSCentrality PageRankCentrality ClosenessCentrality EigenvectorCentrality KatzCentrality
Communities
Mathematica 9 will introduce a number of functions for finding communities and clans in graph.
Tours and Paths
Mathematica 9 will introduced FindHamiltonianCycle, FindMaximumFlow and FindPostmanTour in addition to other tour/path functions.
General Properties
We have a number of built-in functions for computing generic graph properties, including: GraphAssortative GraphDistanceMatrix GraphLinkEfficiency GraphDensity GraphDistance GraphPeriphery GraphDiameter GraphHub GraphReciprocity For example, we can compute a Histogram of the GraphReciprocity of 100 RandomGraph.
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 17
HistogramGraphReciprocity RandomGraph10, 20, 100, DirectedEdges True
0.1 0.2 0.3 0.4 0.5 0.6 5 10 15 20 25 30 35
In Mathematica 9 graph information is easily accessible from an in-built palette. RandomGraph20, 21
Slide 6 of 9
Samual Chen wrote us a blog post recently on using Graph Theory to help build a Risk Diverse Invest- ment Portfolio. These portfolios are constructed in such a way that the underlying financial instruments have uncorre- lated returns, suggesting that either the instruments are entirely unrelated or move in opposite directions.
Traditional Approach
Traditionally a portfolio manager would generate a correlation matrix and generate a heat map, but these are difficult to interrogate.
The Mathematica Approach
The Investment Portfolio
In Mathematica, we would first build a portfolio,
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 19
commodities "GLD", "SLV", "CAFE", "UNG", "USO", "DBA"; bonds "TUZ", "FIVZ", "TENZ", "ZROZ", "TRSY", "STPZ", "TIPZ", "CORP", "HYS", "AUD", "CAD", "BUND"; Then we can use Mathematica’s in-built access to curated FinancialData to find the returns of each instrument in a given time period. bigport Joincommodities, bonds; portRet FinancialData, "Return", 2012, 1, 1, 2012, 1, 10, "Value" & bigport;
The Correlation Matrix
Mathematica has a wide range of statistical functions built right in, but we just need a correlation matrix. portcor CorrelationTransposeportRet; TableFormportcor, TableHeadings bigport, bigport GLD SLV CAFE UNG USO DBA GLD 1. 0.634889 0.33332 0.443286 0.15746 0.0815666 SLV 0.634889 1. 0.346153 0.80205 0.117413 0.463332 CAFE 0.33332 0.346153 1. 0.0155808 0.660596 0.408883 UNG 0.443286 0.80205 0.0155808 1. 0.4888 0.0241931 USO 0.15746 0.117413 0.660596 0.4888 1. 0.71324 DBA 0.0815666 0.463332 0.408883 0.0241931 0.71324 1. TUZ 0.820138 0.230868 0.485541 0.138007 0.546777 0.00950066 FIVZ 0.549785 0.345095 0.832193 0.202497 0.880094 0.491304 TENZ 0.590204 0.348091 0.264696 0.062688 0.245704 0.178264 ZROZ 0.474319 0.197856 0.654274 0.287453 0.35119 0.304815 TRSY 0.252542 0.227312 0.483952 0.396105 0.167837 0.111934 STPZ 0.122471 0.739592 0.652738 0.458889 0.395456 0.761189 TIPZ 0.619214 0.922686 0.612142 0.527811 0.482329 0.661586 CORP 0.420205 0.418745 0.89102 0.134684 0.895057 0.646981 HYS 0.61749 0.706698 0.789741 0.574632 0.183865 0.161655 AUD 0.352033 0.508619 0.259998 0.0554305 0.753487 0.807583 CAD 0.690335 0.915651 0.668296 0.553421 0.444178 0.557434 BUND 0.353519 0.49391 0.546124 0.437549 0.167376 0.180343
The Application
Graph Theory
We then build a function that defines a correlation cut off for our portfolio, portfolioMatrixΘ_ : ReplacePartportcor, i_, i_ 0 . x_ ; x Θ 1, x_ ; x Θ 0 Finally, we can ask for a graph of our portfolio to make sense of it, specifying the correlation cut-off at 0.58.
20 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
GLD SLV CAFE UNG USO DBA TUZ FIVZ TENZ ZROZ TRSY STPZ TIPZ CORP HYS AUD CAD BUND
Stocks Commodities Bonds
The Application
Interactivity
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 21
Slide 7 of 9
Wolfram|Alpha Personal Analytics for Facebook
Live Example
Calling Social Network APIs in Mathematica
In Mathematica 9 we are introducing a new function for importing Social Networking data into a notebook. At launch we will support data importation from the following networks, Facebook GooglePlus LinkedIn Twitter
22 Wolfram-Technologies_Graph-Theory-Social-Networks.nb
Slide 8 of 9
Innovative Automation
Graph are provided automated visualisation options, but are very easily customised RandomGraph9, 10
Multi-Paradigm Language
The ability to choose your programming style, in conjunction with an in-depth Documentation Centre, reduces your learning curve. Well defined Mathematica function definitions provide easy to use functionality.
Hybrid Numeric-Symbolic Methodology
Graph will accept any symbolic data and exist as computable symbolic objects.
Integrated All-In-One Platform with Built-In Knowledge
In addition to a wide variety of curated data, we support an array of import/export formats. Mathematica 9 brings the ability to directly query Social Networks in a notebook.
Document Centric Workflow
Computation is useless without the ability to communicate results Mathematica can be used as a “computational typesetting environment”
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 23
Integrate 1 1 x7 , x
7 Sin Π 14 Logx2 2 x Sin Π 14 1
7 Sin 3 Π 14 Logx2 2 x Sin 3 Π 14 1 1 7 Cos Π 7 Logx2 2 x Cos Π 7 1 1 7 Logx 1 2 7 Sin Π 7 ArcTanCsc Π 7
Π 7 2 7 Cos Π 14 ArcTanSec Π 14
Π 14 2 7 Cos 3 Π 14 ArcTanSec 3 Π 14
3 Π 14 Mathematica notebooks may be saved as .cdf files and distributed to anyone via the Free CDF Player* For examples of what the .cdf document standard allows, see the Demonstrations Project
Slide 9 of 9
graphsty SequenceVertexLabels MapThreadRule, RangeLengthbigport, Style, 7, GrayLevel.3, FontFamily "Verdana" & bigport, VertexSize Large, GraphLayout "PackingLayout" "ClosestPacking", ImagePadding 20;
MapThread::mptd : Object bigport at position 2, 2 in MapThreadRule, , bigport has only 0 of required 1 dimensions.
blueo_ : RGBColor.15, .4, .6, o;
Wolfram-Technologies_Graph-Theory-Social-Networks.nb 25