SlideShare ist ein Scribd-Unternehmen logo
1 von 67
A Little Graph Theory for the
Busy Developer
Jim Webber
Chief Scientist, Neo Technology
@jimwebber
Roadmap
• Imprisoned data
• Graph models
• Graph theory
– Local properties, global behaviors
– Predictive techniques
• Graph matching
– Real-time analytics for fun and profit
• Fin
http://www.flickr.com/photos/crazyneighborlady/355232758/
http://gallery.nen.gov.uk/image82582-.html
Aggregate-Oriented Data
http://martinfowler.com/bliki/AggregateOrientedDatabase.html
“There is a significant downside - the whole approach works really well
when data access is aligned with the aggregates, but what if you want to
look at the data in a different way? Order entry naturally stores orders as
aggregates, but analyzing product sales cuts across the aggregate structure.
The advantage of not using an aggregate structure in the database is that it
allows you to slice and dice your data different ways for different
audiences.
This is why aggregate-oriented stores talk so much about map-reduce.”
complexity = f(size, connectedness, uniformity)
http://www.bbc.co.uk/london/travel/downloads/tube_map.html
Property graphs
• Property graph model:
– Nodes with properties
– Named, directed relationships with properties
– Relationships have exactly one start and end node
• Which may be the same node
stole
from
loves
loves
enemy
enemy
A Good Man
Goes to War
appeared
in
appeared
in
appeared
in
appeared
in
Victory of
the Daleks
appeared
in
appeared
in
companion
companion
enemy
Property graphs are very whiteboard-friendly
http://blogs.adobe.com/digitalmarketing/analytics/predictive-analytics/predictive-analytics-and-the-digital-marketer/
http://en.wikipedia.org/wiki/File:Leonhard_Euler_2.jpg
Meet Leonhard Euler
• Swiss mathematician
• Inventor of Graph
Theory (1736)
16
Königsberg (Prussia) - 1736
A
B
D
C
A
B
D
C
1
2
3
4
7
6
5
http://en.wikipedia.org/wiki/Seven_Bridges_of_Königsberg
20
Triadic Closure
name: Kyle
name: Stan name: Kenny
Triadic Closure
name: Kyle
name: Stan name: Kenny
name: Kyle
name: Stan name: Kenny
FRIEND
Structural Balance
name: Cartman
name: Craig name: Tweek
Structural Balance
name: Cartman
name: Craig name: Tweek
name: Cartman
name: Craig name: Tweek
FRIEND
Structural Balance
name: Cartman
name: Craig name: Tweek
name: Cartman
name: Craig name: Tweek
ENEMY
Structural Balance
name: Kyle
name: Stan name: Kenny
name: Kyle
name: Stan name: Kenny
FRIEND
Structural Balance is a key
predictive technique
And it’s domain-agnostic
Allies and Enemies
UK
GermanyFrance
Russia Italy
Austria
Allies and Enemies
UK
GermanyFrance
Russia Italy
Austria
Allies and Enemies
UK
GermanyFrance
Russia Italy
Austria
Allies and Enemies
UK
GermanyFrance
Russia Italy
Austria
Allies and Enemies
UK
GermanyFrance
Russia Italy
Austria
Allies and Enemies
UK
GermanyFrance
Russia Italy
Austria
Predicting WWI
[Easley and Kleinberg]
Strong Triadic Closure
It if a node has strong relationships to two
neighbours, then these neighbours must have at
least a weak relationship between them.
[Wikipedia]
Triadic Closure
(weak relationship)
name: Kenny
name: Stan name: Cartman
Triadic Closure
(weak relationship)
name: Kenny
name: Stan name: Cartman
name: Kenny
name: Stan name: Cartman
FRIEND 50%
Weak relationships
• Relationships can have “strength” as well as
intent
– Think: weighting on a relationship in a property
graph
• Weak links play another super-important
structural role in graph theory
– They bridge neighbourhoods
Local Bridges
FRIEND
name: Kenny
name: Stanname: Kyle
FRIEND
FRIEND
name: Sally
name: Bebename: Wendy
FRIEND
FRIEND 50%
name: Cartman
FRIEND
ENEMY
Local Bridge Property
“If a node A in a network satisfies the Strong
Triadic Closure Property and is involved in at
least two strong relationships, then any local
bridge it is involved in must be a weak
relationship.”
[Easley and Kleinberg]
University Karate Club
Graph Partitioning
• (NP) Hard problem
– Recursively remove the spanning links between
dense regions
– Or recursively merge nodes into ever larger
“subgraph” nodes
– Choose your algorithm carefully – some are better
than others for a given domain
• Can use to (almost exactly) predict the
break up of the karate club!
University Karate Clubs
(predicted by Graph Theory)
9
University Karate Clubs
(what actually happened!)
Cypher
• Declarative graph pattern matching language
– “SQL for graphs”
– Columnar results
• Supports graph matching commands and
queries
– Find me stuff like this…
– Aggregation, ordering and limit, etc.
Firstname:
Mickey
Surname: Smith
DoB: 19781006
SKU: 5e175641
Product:
Badgers
Nadgers Ale
SKU: 2555f258
Product:
Peewee Pilsner
Category: beer
SKU: 49d102bc
Product: Baby
Dry Nights
Category:
nappies
Category: baby Category:
alcoholic
drinks
SKU: 49d102bc
Product: XBox
360
Category:
consumer
electronics
Category:
console
BOUGHTBOUGHT
MEMBER_OF
MEMBER_OFMEMBER_OF
MEMBER_OFMEMBER_OF
Firstname: *
Surname: *
DoB: 1996 > x
> 1972
Category: beerCategory:
nappies
BOUGHTCategory: game
console
Firstname: *
Surname: *
DoB: 1996 > x
> 1972
Category: beerCategory:
nappies
!BOUGHTCategory: game
console
(beer)(nappies)
(console)
(daddy)
() ()
()
Flatten the graph
(daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies)
(daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer)
(daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console)
Wrap in a Cypher MATCH clause
MATCH (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies),
(daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer),
(daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console)
Cypher WHERE clause
MATCH (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies),
(daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer),
(daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console)
WHERE b is null
Full Cypher query
START beer=node:categories(category=‘beer’),
nappies=node:categories(category=‘nappies’),
xbox=node:products(product=‘xbox 360’)
MATCH (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer),
(daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies),
(daddy)-[b?:BOUGHT]->(xbox)
WHERE b is null
RETURN distinct daddy
Results
==> +---------------------------------------------+
==> | daddy |
==> +---------------------------------------------+
==> | Node[15]{name:"Rory Williams",dob:19880121} |
==> +---------------------------------------------+
==> 1 row
==> 0 ms
==>
neo4j-sh (0)$
Facebook Graph Search
Which sushi restaurants in
NYC do my friends like?
Graph Structure
Cypher query
START me=node:person(name = 'Jim'),
location=node:location(location='New York'),
cuisine=node:cuisine(cuisine='Sushi')
MATCH (me)-[:IS_FRIEND_OF]->(friend)-[:LIKES]->(restaurant)
-[:LOCATED_IN]->(location),(restaurant)-[:SERVES]->(cuisine)
RETURN restaurant
Search structure
What are graphs good for?
• Recommendations
• Pharmacology
• Business intelligence
• Social computing
• Geospatial
• MDM
• Data center management
• Web of things
• Genealogy
• Time series data
• Product catalogue
• Web analytics
• Scientific computing
• Indexing your slow RDBMS
• And much more!
Free O’Reilly book for
everyone!
http://graphdatabases.com
Thanks for listening
Neo4j: http://neo4j.org
Me: @jimwebber

Weitere ähnliche Inhalte

Ähnlich wie A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chicago 2013

Ähnlich wie A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chicago 2013 (20)

Graphs for Ai and ML
Graphs for Ai and MLGraphs for Ai and ML
Graphs for Ai and ML
 
GraphTour Boston - Graphs for AI and ML
GraphTour Boston - Graphs for AI and MLGraphTour Boston - Graphs for AI and ML
GraphTour Boston - Graphs for AI and ML
 
Graphs for AI – Guess the Future Given the Past
Graphs for AI – Guess the Future Given the PastGraphs for AI – Guess the Future Given the Past
Graphs for AI – Guess the Future Given the Past
 
Getting Started with Graph Databases
Getting Started with Graph DatabasesGetting Started with Graph Databases
Getting Started with Graph Databases
 
MongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationMongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combination
 
Application Development and Data Modeling on Amazon DynamoDB
Application Development and Data Modeling on Amazon DynamoDBApplication Development and Data Modeling on Amazon DynamoDB
Application Development and Data Modeling on Amazon DynamoDB
 
Graphs for AI & ML, Jim Webber, Neo4j
Graphs for AI & ML, Jim Webber, Neo4jGraphs for AI & ML, Jim Webber, Neo4j
Graphs for AI & ML, Jim Webber, Neo4j
 
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
 
Still using MySQL? Maybe you should reconsider.
Still using MySQL? Maybe you should reconsider.Still using MySQL? Maybe you should reconsider.
Still using MySQL? Maybe you should reconsider.
 
Intro to Neo4j 2.0
Intro to Neo4j 2.0Intro to Neo4j 2.0
Intro to Neo4j 2.0
 
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...
 
Working With Big Data - Nov 2016
Working With Big Data - Nov 2016Working With Big Data - Nov 2016
Working With Big Data - Nov 2016
 
GraphSummit Toronto: Keynote - Innovating with Graphs
GraphSummit Toronto: Keynote - Innovating with Graphs GraphSummit Toronto: Keynote - Innovating with Graphs
GraphSummit Toronto: Keynote - Innovating with Graphs
 
Performance By Design
Performance By DesignPerformance By Design
Performance By Design
 
Should a Graph Database Be in Your Next Data Warehouse Stack?
Should a Graph Database Be in Your Next Data Warehouse Stack?Should a Graph Database Be in Your Next Data Warehouse Stack?
Should a Graph Database Be in Your Next Data Warehouse Stack?
 
Waterloo Data Science and Data Engineering Meetup - 2018-08-29
Waterloo Data Science and Data Engineering Meetup - 2018-08-29Waterloo Data Science and Data Engineering Meetup - 2018-08-29
Waterloo Data Science and Data Engineering Meetup - 2018-08-29
 
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
 
Building Applications with a Graph Database
Building Applications with a Graph DatabaseBuilding Applications with a Graph Database
Building Applications with a Graph Database
 
Neo4j 20 minutes introduction
Neo4j 20 minutes introductionNeo4j 20 minutes introduction
Neo4j 20 minutes introduction
 
GRAKN.AI: The Hyper-Relational Database for Knowledge-Oriented Systems
GRAKN.AI: The Hyper-Relational Database for Knowledge-Oriented SystemsGRAKN.AI: The Hyper-Relational Database for Knowledge-Oriented Systems
GRAKN.AI: The Hyper-Relational Database for Knowledge-Oriented Systems
 

Mehr von Neo4j

Mehr von Neo4j (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
QIAGEN: Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
QIAGEN: Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansQIAGEN: Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
QIAGEN: Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
ISDEFE - GraphSummit Madrid - ARETA: Aviation Real-Time Emissions Token Accre...
ISDEFE - GraphSummit Madrid - ARETA: Aviation Real-Time Emissions Token Accre...ISDEFE - GraphSummit Madrid - ARETA: Aviation Real-Time Emissions Token Accre...
ISDEFE - GraphSummit Madrid - ARETA: Aviation Real-Time Emissions Token Accre...
 
BBVA - GraphSummit Madrid - Caso de éxito en BBVA: Optimizando con grafos
BBVA - GraphSummit Madrid - Caso de éxito en BBVA: Optimizando con grafosBBVA - GraphSummit Madrid - Caso de éxito en BBVA: Optimizando con grafos
BBVA - GraphSummit Madrid - Caso de éxito en BBVA: Optimizando con grafos
 
Graph Everywhere - Josep Taruella - Por qué Graph Data Science en tus modelos...
Graph Everywhere - Josep Taruella - Por qué Graph Data Science en tus modelos...Graph Everywhere - Josep Taruella - Por qué Graph Data Science en tus modelos...
Graph Everywhere - Josep Taruella - Por qué Graph Data Science en tus modelos...
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Neo4j_Exploring the Impact of Graph Technology on Financial Services.pdf
Neo4j_Exploring the Impact of Graph Technology on Financial Services.pdfNeo4j_Exploring the Impact of Graph Technology on Financial Services.pdf
Neo4j_Exploring the Impact of Graph Technology on Financial Services.pdf
 
Rabobank_Exploring the Impact of Graph Technology on Financial Services.pdf
Rabobank_Exploring the Impact of Graph Technology on Financial Services.pdfRabobank_Exploring the Impact of Graph Technology on Financial Services.pdf
Rabobank_Exploring the Impact of Graph Technology on Financial Services.pdf
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
Neo4j: Data Engineering for RAG (retrieval augmented generation)
Neo4j: Data Engineering for RAG (retrieval augmented generation)Neo4j: Data Engineering for RAG (retrieval augmented generation)
Neo4j: Data Engineering for RAG (retrieval augmented generation)
 
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
 
Enabling GenAI Breakthroughs with Knowledge Graphs
Enabling GenAI Breakthroughs with Knowledge GraphsEnabling GenAI Breakthroughs with Knowledge Graphs
Enabling GenAI Breakthroughs with Knowledge Graphs
 
Neo4j_Anurag Tandon_Product Vision and Roadmap.Benelux.pptx.pdf
Neo4j_Anurag Tandon_Product Vision and Roadmap.Benelux.pptx.pdfNeo4j_Anurag Tandon_Product Vision and Roadmap.Benelux.pptx.pdf
Neo4j_Anurag Tandon_Product Vision and Roadmap.Benelux.pptx.pdf
 
Neo4j Jesus Barrasa The Art of the Possible with Graph
Neo4j Jesus Barrasa The Art of the Possible with GraphNeo4j Jesus Barrasa The Art of the Possible with Graph
Neo4j Jesus Barrasa The Art of the Possible with Graph
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

A Little Graph Theory for the Busy Developer - Jim Webber @ GraphConnect Chicago 2013

Hinweis der Redaktion

  1. Vanity slide - Work for Neo Technology, the commercial backer of the Neo4j open source graph database
  2. We’ve all been there – trudging through 3 intermediate tables just to get the data you want.
  3. We have key-value stores, typically very highly available and scalable for simple key-value data
  4. Column stores naturally-indexed value storesContrary to common belief – Google’s big table isn’t the world’s most famous column storeBritish museum London is: it’s got columns and it’s where we stored all the stuff we nicked from the British Empire!
  5. Aggregates:No more impedance mismatch, just decompose to documents/ k-v / columnsThe data model is less expressive than RDBMS, but that’s OK because:RDBMS constraints don’t really match application concernsThe expressiveness is in your domain logic, right?
  6. People talk about Codd’s relational model being mature because it was proposed in 1969 – 42 years old.Euler’s graph theory was proposed in 1736 – 275 years old.
  7. Graphs are the most natural way to model most domains. You already know this because you draw graphs on a whiteboard, but you’ve never had the opportunity to take that down into the database before.Nodes are a bit like documents, but they’re flat at present in Neo4j.You pour data into your nodes and then connect them – easy peasy.This enables high fidelity domain modeling because this is how your domains work.And you don’t have to do this stuff in your application code – it’s right there in the databaseLet’s prove it by exploring a fun domain…
  8. Start off sketching the domain. That’s your model done – we see this when we revisit databases months after they’re been designed and put into productionNo decomposition, ER design, normalisation/denormalisation as you need with RDBMS.
  9. Predictive analytics
  10. Euler reduced the problem into an abstract formFrom geography to diagrammatic through to a graph.It’s the first documented case of representing the real world as a graph.
  11. First we need to talk about some local properties
  12. A triadic closure is a local property of (social) graphs whereby if two nodes are connected via a path involving a third node, there is an increased likelihood that the two nodes will become directly connected in future. This is a familiar enough situation for us in a social setting whereby if we happen to be friends with two people, ultimately there's an increased chance that those people will become direct friends too, since by being our friend in the first place, it's an indication of social similarity and suitability. It’s called triadic closure, because we try to close the triangle.
  13. We see this all the time – it’s likely that if we have two friends, that they will also become at least acquaintances and potentially friends themselves!In general, if a node A has relationships to B & C then the relationship between B&C is likely to form – especially if the existing relationships are both strong.This is an incredibly strong assertion and will not be typically upheld by all subgraphs in a graph. Nonetheless it is sufficiently commonplace (particularly in social networks) to be trusted as a predictive aid.
  14. Sentiment plays a role in how closures form too – there is a notion of balance.
  15. From a triadic closure perspective this is OK, but intuitively it seems odd.Cartman’s friends shouldn’t be friends with his enemies. Nor should Cartman’s enemies be friends with his friends.
  16. This makes sense – Cartman’s friend Craig is also an enemy of Cartman’s enemy TweekTwo negative sentiments and one positive sentiment is a balanced structure – and it makes sense too since we gang up with our friends on our poor beleaguered enemy
  17. Another balanced – and more pleasant – arrangement is for three positive sentiments, in this case mutual friends.
  18. A starting point for a network of friends and enemiesRed links indicate enemy of relationshipBlack links indicate friend of relationshipThe Three Emperor’s league
  19. Italy forms the with Austria and Germany – a balanced +++ triadic closureIf Italy had made only a single alliance (or enemy) it would have been unstable and another relationship would be likely to form anyway!Triple Alliance
  20. Russia becomes hostile to Austria and Germany – a balance --+ d triadic closure becomes agnostic towards France.German-Russian Lapse
  21. The French and Russians ally, forming a balanced --+ triadic closure with the UKFrench-Russian Alliance
  22. The UK and France enter into the famous Entente CordialeThis produces an unbalanced ++- triadic closure with Russia, and the graph doesn’t like it.
  23. The British and Russians form an alliance, thereby changing their previously unbalanced triadic closure into a balanced one.Other local pressures on the graph make other closures form.Italy becomes hostile to Russia, forming a balanced --+ closure with the France, and another balanced --+ closure with the UK.Germany and the UK become hostile forming a balanced --+ closure with Austria and another balanced --+ closure with ItalyBritish-Russian Alliance
  24. That WWI can be predicted without domain knowledge by iterating a graph and applying local structural constraints is nothing short of astonishing to me.Note how the network slides into a balanced labeling — and into World War I.
  25. In this case the string triadic closure property still holds – though it is a weak link that characterises the relationship between Stan and Cartman.Given a starting graph, we can apply this simple local principal to see how it would evolve.
  26. In this case the string triadic closure property still holds – though it is a weak link that characterises the relationship between Stan and Cartman.Given a starting graph, we can apply this simple local principal to see how it would evolve.
  27. A local bridge acts as a link – perhaps the only realistic link - between two otherwise distant (or separate) subgraphs.Local bridges are semantically rich – they provide conduits for information flow between otherwise independent groups.In this case DATING is a local bridge – it must also be a weak relationship according to our definition of a local bridgeIntuitively this makes sense – your girl/boyfriend is rather less important at age 8 than your regular friends, IIRC.
  28. How do we identify local bridges? Any weak link which would cause a component of the graph to become disconnected.Being able to identify local bridges is important – in this case it’s the only know conduit to allow the girls and boys to communicate.In real life local bridges are apparent in your organisation as experts (or managers); appear as nexus in fraud cases;
  29. Zachary in the Journal of Anthropological Research 1977Intuitively we can see “clumps” in this graph.But how do we separate them out? It’s called minimum cut.
  30. What’s interesting is that it’s mechanical – no domain knowledge is necessary. There’s only one failure with the method Zachary chose to partition the graph: node 9 should have gone to the instructor’s club but instead went with the original president of the club (node 34).Why? Because the student was three weeks away from completing a four-year quest to obtain a black belt, which he could only do with the instructor (node 1)Other minimum cut approaches might deliver slightly different results, but on the whole it’s amazing you get such insight from an algorithm!
  31. But is there enough information in the graph itself to predict the schism?
  32. But is there enough information in the graph itself to predict the schism?
  33. We can use graph matching to look for behavioural patterns in the graph too!
  34. The insight here is that we have a typical young father who buys beer, nappies and a game console simply by reducing subgraphWe have a pattern to search for
  35. Now we look for young fathers – implied by beer and nappies purchases – who haven’t bought a game console.
  36. START n=node(*), r=rel(*) DELETE r,nCREATE daddy1 = { name: 'Mickey Smith', dob: 19781006 }CREATE beer = { category: 'beer' } CREATE alcohol = { category: 'alcoholicdrinks' } CREATE peeweePilsner = { sku: '2555f258', product: 'PeeweePilsner' } CREATE badgersNadgers = { sku: '5e175641', product: 'BadgersNadgers Ale' }CREATE peeweePilsner-[:MEMBER_OF]->beerCREATE badgersNadgers-[:MEMBER_OF]->beerCREATE beer-[:MEMBER_OF]->alcoholCREATE daddy1-[:BOUGHT]->peeweePilsnerCREATE daddy1-[:BOUGHT]->badgersNadgersCREATE baby = { category: 'baby' }CREATE nappies = { category: 'nappies' }CREATE nappies-[:MEMBER_OF]->babyCREATE babyDryNights = { sku: '49d102bc', product: 'Baby DryNights'} CREATE babyDryNights-[:MEMBER_OF]-nappiesCREATE daddy1-[:BOUGHT]->babyDryNightsCREATE consumerElectronics = { category: 'consumerelectronics' }CREATE console = { category: 'console' }CREATE xbox = { sku: '49d102bc', product: 'XBox 360' }CREATE xbox-[:MEMBER_OF]->(console)-[:MEMBER_OF]->consumerElectronicsCREATE daddy1-[:BOUGHT]->xboxCREATE mummy11 = { name: 'Rose Tyler', dob: 19800317 }CREATE wine = { sku:'3a3f22bc', product: 'Shiraz' }CREATE mummy1-[:BOUGHT]->wineCREATE mummy1-[:BOUGHT]->babyDryNights CREATE daddy2 = { name: 'Rory Williams', dob: 19880121 }CREATE daddy2-[:BOUGHT]->peeweePilsnerCREATE daddy2-[:BOUGHT]->babyDryNightsSTART beer=node(2), nappies=node(7), xbox=node(11)MATCH (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer), (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies), (daddy)-[b?:BOUGHT]->(xbox)WHERE b isnullRETURN distinctdaddy
  37. Note that Max de Marzireimplemented a functionally better Graph Search with Neo4j and some Ruby gems for language processing in a weekend!
  38. Image: real-timeBeing able to look for all young fathers who might be tempted to buy a new game console is helpful, but not dramatically different from what we have nowIt’s much faster to process in a graph, but still a latent business activity (e.g. mailshot)But you can take the same idea and run the query in real time foran individual customer at they go through the checkout!And you can do more too – you can add in more/less dimensions to the search.Does the shop have stock?Does the young father live in the right target area (r-tree, postcode)?We can vary the number of dimensions we include to tailor the search for performance/accuracy very easily in a graph – query latency is proportional to the amount of graph searched, not data set size.