A Li%le Graph Theory for the Busy Developer Dr. Jim - - PowerPoint PPT Presentation

a li le graph theory for the
SMART_READER_LITE
LIVE PREVIEW

A Li%le Graph Theory for the Busy Developer Dr. Jim - - PowerPoint PPT Presentation

A Li%le Graph Theory for the Busy Developer Dr. Jim Webber Chief Scien@st, Neo Technology @jimwebber Roadmap Imprisoned data Labeled Property Graph


slide-1
SLIDE 1

A ¡Li%le ¡Graph ¡Theory ¡for ¡the ¡ Busy ¡Developer ¡

  • Dr. ¡Jim ¡Webber ¡

Chief ¡Scien@st, ¡Neo ¡Technology ¡ @jimwebber ¡

slide-2
SLIDE 2

Roadmap ¡

  • Imprisoned ¡data ¡
  • Labeled ¡Property ¡Graph ¡Model ¡

– And ¡some ¡cultural ¡imperialism ¡

  • Graph ¡theory ¡

– South ¡East ¡London ¡ – World ¡War ¡I ¡

  • Graph ¡matching ¡

– Beer, ¡nappies ¡and ¡Xbox ¡

  • End ¡
slide-3
SLIDE 3
slide-4
SLIDE 4 h%p://www.flickr.com/photos/crazyneighborlady/355232758/ ¡
slide-5
SLIDE 5 h%p://gallery.nen.gov.uk/image82582-­‑.html ¡
slide-6
SLIDE 6
slide-7
SLIDE 7

Aggregate-­‑Oriented ¡Data ¡

h%p://mar@nfowler.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.”

slide-8
SLIDE 8
slide-9
SLIDE 9

complexity = f(size, connectedness, uniformity)

slide-10
SLIDE 10
slide-11
SLIDE 11 h%p://www.bbc.co.uk/london/travel/downloads/tube_map.html ¡
slide-12
SLIDE 12

Labeled ¡Property ¡graphs ¡

  • Property ¡graph ¡model: ¡

– Nodes ¡with ¡proper@es ¡and ¡labels ¡ – Named, ¡directed ¡rela@onships ¡with ¡proper@es ¡ – Rela@onships ¡have ¡exactly ¡one ¡start ¡and ¡end ¡node ¡

  • Which ¡may ¡be ¡the ¡same ¡node ¡
slide-13
SLIDE 13 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 ¡
slide-14
SLIDE 14 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 ¡ planet ¡ prop ¡ species ¡ species ¡ species ¡ character ¡ character ¡ character ¡ episode ¡ episode ¡
slide-15
SLIDE 15 h%p://blogs.adobe.com/digitalmarke@ng/analy@cs/predic@ve-­‑analy@cs/predic@ve-­‑analy@cs-­‑and-­‑the-­‑digital-­‑marketer/ ¡
slide-16
SLIDE 16 h%p://en.wikipedia.org/wiki/File:Leonhard_Euler_2.jpg ¡

Meet ¡Leonhard ¡Euler ¡

  • Swiss ¡mathema@cian ¡
  • Inventor ¡of ¡Graph ¡

Theory ¡(1736) ¡

16 ¡
slide-17
SLIDE 17

Königsberg ¡(Prussia) ¡-­‑ ¡1736 ¡

slide-18
SLIDE 18

A ¡ B ¡ D ¡ C ¡

slide-19
SLIDE 19

A ¡ B ¡ D ¡ C ¡

1 2 3 4 7 6 5
slide-20
SLIDE 20 h%p://en.wikipedia.org/wiki/Seven_Bridges_of_Königsberg ¡ 20 ¡
slide-21
SLIDE 21
slide-22
SLIDE 22

Triadic ¡Closure ¡

name: Kyle name: Stan name: Kenny
slide-23
SLIDE 23

Triadic ¡Closure ¡

name: Kyle name: Stan name: Kenny name: Kyle name: Stan name: Kenny FRIEND
slide-24
SLIDE 24

Structural ¡Balance ¡

name: Cartman name: Craig name: Tweek
slide-25
SLIDE 25

Structural ¡Balance ¡

name: Cartman name: Craig name: Tweek name: Cartman name: Craig name: Tweek FRIEND
slide-26
SLIDE 26

Structural ¡Balance ¡

name: Cartman name: Craig name: Tweek name: Cartman name: Craig name: Tweek ENEMY
slide-27
SLIDE 27

Structural ¡Balance ¡

name: Kyle name: Stan name: Kenny name: Kyle name: Stan name: Kenny FRIEND
slide-28
SLIDE 28

Structural ¡Balance ¡is ¡a ¡key ¡ predic@ve ¡technique ¡

And ¡it’s ¡domain-­‑agnos@c ¡

slide-29
SLIDE 29

Allies ¡and ¡Enemies ¡

UK ¡ Germany ¡ France ¡ Russia ¡ Italy ¡ Austria ¡
slide-30
SLIDE 30

Allies ¡and ¡Enemies ¡

UK ¡ Germany ¡ France ¡ Russia ¡ Italy ¡ Austria ¡
slide-31
SLIDE 31

Allies ¡and ¡Enemies ¡

UK ¡ Germany ¡ France ¡ Russia ¡ Italy ¡ Austria ¡
slide-32
SLIDE 32

Allies ¡and ¡Enemies ¡

UK ¡ Germany ¡ France ¡ Russia ¡ Italy ¡ Austria ¡
slide-33
SLIDE 33

Allies ¡and ¡Enemies ¡

UK ¡ Germany ¡ France ¡ Russia ¡ Italy ¡ Austria ¡
slide-34
SLIDE 34

Allies ¡and ¡Enemies ¡

UK ¡ Germany ¡ France ¡ Russia ¡ Italy ¡ Austria ¡
slide-35
SLIDE 35

Predic@ng ¡WWI ¡ ¡

[Easley ¡and ¡Kleinberg] ¡
slide-36
SLIDE 36

Strength ¡

  • Rela@onships ¡can ¡have ¡strength ¡as ¡well ¡as ¡

sen@ment ¡

  • This ¡gives ¡us ¡another ¡dimension ¡to ¡consider ¡in ¡
  • ur ¡triangles ¡

– I ¡love ¡you ¡versus ¡I ¡hate ¡you ¡ – I ¡like ¡you ¡versus ¡I ¡dislike ¡you ¡

  • Gives ¡rise ¡to ¡another ¡interes@ng ¡property ¡
slide-37
SLIDE 37

Strong ¡Triadic ¡Closure ¡Property ¡

It ¡if ¡a ¡node ¡has ¡strong ¡rela2onships ¡to ¡two ¡ neighbours, ¡then ¡these ¡neighbours ¡must ¡have ¡at ¡ least ¡a ¡weak ¡rela2onship ¡between ¡them. ¡ ¡ [Wikipedia] ¡

slide-38
SLIDE 38

Triadic ¡Closure ¡

(weak ¡rela@onship) ¡

name: Kenny name: Stan name: Cartman
slide-39
SLIDE 39

Triadic ¡Closure ¡

(weak ¡rela@onship) ¡

name: Kenny name: Stan name: Cartman name: Kenny name: Stan name: Cartman FRIEND 50%
slide-40
SLIDE 40

Weak ¡rela@onships ¡

  • Weak ¡links ¡play ¡another ¡super-­‑important ¡

structural ¡role ¡in ¡graph ¡theory ¡

  • They ¡bridge ¡neighbourhoods ¡
  • Which ¡is ¡allows ¡us ¡to ¡par@@on ¡graphs ¡
slide-41
SLIDE 41

Local ¡Bridge ¡Property ¡

“If ¡a ¡node ¡A ¡in ¡a ¡network ¡sa2sfies ¡the ¡Strong ¡ Triadic ¡Closure ¡Property ¡and ¡is ¡involved ¡in ¡at ¡ least ¡two ¡strong ¡rela2onships, ¡then ¡any ¡local ¡ bridge ¡it ¡is ¡involved ¡in ¡must ¡be ¡a ¡weak ¡ rela2onship.” ¡ ¡ [Easley ¡and ¡Kleinberg] ¡

slide-42
SLIDE 42

LIKES ¡is ¡a ¡local ¡bridge ¡

name: Chuck name: Bob name: Alice LOVES HATES HATES LIKES name: David
slide-43
SLIDE 43

LOVES ¡cannot ¡be ¡a ¡local ¡bridge ¡

name: Chuck name: Bob name: Alice LOVES HATES HATES LOVES name: David
slide-44
SLIDE 44

University ¡Karate ¡Club ¡

slide-45
SLIDE 45

Graph ¡Par@@oning ¡

  • (NP) ¡Hard ¡problem ¡

– Recursively ¡remove ¡bridges ¡between ¡dense ¡ regions ¡ – Choose ¡your ¡algorithm ¡carefully ¡– ¡some ¡are ¡be%er ¡ than ¡others ¡for ¡a ¡given ¡domain ¡

  • Probabilis@c ¡methods ¡are ¡cheaper ¡
  • Can ¡use ¡to ¡(almost ¡exactly) ¡predict ¡the ¡

break ¡up ¡of ¡the ¡karate ¡club! ¡

slide-46
SLIDE 46

University ¡Karate ¡Clubs ¡

(predicted ¡by ¡Graph ¡Theory) ¡

9
slide-47
SLIDE 47

University ¡Karate ¡Clubs ¡

(what ¡actually ¡happened!) ¡

slide-48
SLIDE 48

Produc@ve ¡Predic@ve ¡Analy@cs ¡in ¡2 ¡Years ¡

(says ¡ ¡Gartner ¡predic@on) ¡

slide-49
SLIDE 49
slide-50
SLIDE 50

Cypher ¡

  • Declara@ve ¡graph ¡pa%ern ¡matching ¡language ¡

– “SQL ¡for ¡graphs” ¡ – A ¡humane ¡tool ¡pioneered ¡by ¡a ¡tamed ¡SQL ¡DBA ¡

  • A ¡pa%ern ¡graph ¡matching ¡language ¡

– Find ¡me ¡stuff ¡like… ¡

slide-51
SLIDE 51
slide-52
SLIDE 52 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 BOUGHT BOUGHT MEMBER_OF MEMBER_OF MEMBER_OF MEMBER_OF MEMBER_OF
slide-53
SLIDE 53
slide-54
SLIDE 54 Firstname: * Surname: * DoB: 1996 > x > 1972 Category: beer Category: nappies BOUGHT Category: game console
slide-55
SLIDE 55 Firstname: * Surname: * DoB: 1996 > x > 1972 Category: beer Category: nappies !BOUGHT Category: game console
slide-56
SLIDE 56 (beer) (nappies) (console) (daddy) () () <
  • [
b : B O U G H T ]
  • ()
slide-57
SLIDE 57

Fla%en ¡the ¡graph ¡

(daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies) (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer) (daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console)
slide-58
SLIDE 58

Wrap ¡in ¡a ¡Cypher ¡MATCH ¡clause ¡

MATCH (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies), (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer), (daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console)
slide-59
SLIDE 59

Cypher ¡WHERE ¡clause ¡

MATCH (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies), (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer), (daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console) WHERE b is null
slide-60
SLIDE 60

Cypher ¡1.x ¡recommenda@ons ¡

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
slide-61
SLIDE 61

Cypher ¡2.0 ¡ ¡recommenda@ons ¡

MATCH (d:Person)-[:BOUGHT]->()-[:MEMBER_OF]->(n:Category), (d:Person)-[:BOUGHT]->()-[:MEMBER_OF]->(b:Category), (c:Category) WHERE n.category = "nappies" AND b.category = "beer" AND c.category = "console" AND NOT((d)-[:BOUGHT]->()-[:MEMBER_OF]->(c)) RETURN DISTINCT d AS daddy
slide-62
SLIDE 62

Results ¡

==> +---------------------------------------------+ ==> | daddy | ==> +---------------------------------------------+ ==> | Node[15]{name:"Rory Williams",dob:19880121} | ==> +---------------------------------------------+ ==> 1 row ==> 0 ms ==> neo4j-sh (0)$
slide-63
SLIDE 63
slide-64
SLIDE 64

Facebook ¡Graph ¡Search ¡

Which ¡sushi ¡restaurants ¡in ¡ NYC ¡do ¡my ¡friends ¡like? ¡

See ¡h%p://maxdemarzi.com/ ¡
slide-65
SLIDE 65

Graph ¡Structure ¡

slide-66
SLIDE 66

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
slide-67
SLIDE 67

Search ¡structure ¡

slide-68
SLIDE 68
slide-69
SLIDE 69

What’s ¡Neo4j ¡good ¡for? ¡

  • Data ¡centre ¡management ¡
  • Supply ¡chain/provenance ¡
  • Recommenda@ons ¡
  • Business ¡intelligence ¡
  • Social ¡compu@ng ¡
  • MDM ¡
  • Web ¡of ¡things ¡
  • Time ¡series/event ¡data ¡
  • Product/engineering ¡catalogue ¡
  • Web ¡analy@cs, ¡user ¡journeys ¡
  • Scien@fic ¡compu@ng ¡
  • Spa@al ¡
  • Geo/Seismic/Meteorological ¡
  • Bio/Pharma ¡
  • And ¡many, ¡many ¡more… ¡
slide-70
SLIDE 70

42? ¡

Can ¡Neo4j ¡compute ¡

slide-71
SLIDE 71

MATCH (you)-[:HAPPINESS]->(answer) RETURN answer

slide-72
SLIDE 72

Free ¡O’Reilly ¡book! ¡

Come ¡to ¡the ¡ ¡ Neo ¡Technology ¡Stand ¡

  • r ¡visit ¡ ¡

h%p://graphdatabases.com ¡

Ian Robinson, Jim Webber & Emil Eifrem

Graph Databases h

Compliments
  • f Neo Technology
slide-73
SLIDE 73

Thanks ¡for ¡listening ¡

@jimwebber ¡ h7p://neo4j.org ¡