0422- A Little Graph Theory for Developers

  • Upload
    juanese

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

  • 7/27/2019 0422- A Little Graph Theory for Developers

    1/62

    ALi%leGraphTheoryforthe

    BusyDeveloper

    Dr.JimWebber

    ChiefScien@st,NeoTechnologyjimwebber

  • 7/27/2019 0422- A Little Graph Theory for Developers

    2/62

    Roadmap

    Imprisoneddata Graphmodels Graphtheory

    Localproper@es,globalbehavioursPredic@vetechniques

    GraphmatchingPredic@ve,real-@meanaly@csforfunandprofit

    Fin

  • 7/27/2019 0422- A Little Graph Theory for Developers

    3/62

  • 7/27/2019 0422- A Little Graph Theory for Developers

    4/62

  • 7/27/2019 0422- A Little Graph Theory for Developers

    5/62

    h%p://www.flickr.com/photos/crazyneighborlady/355232758/

  • 7/27/2019 0422- A Little Graph Theory for Developers

    6/62

    h%p://gallery.nen.gov.uk/image82582-.html

  • 7/27/2019 0422- A Little Graph Theory for Developers

    7/62h%p://www.xtranormal.com/watch/6995033/mongo-db-is-web-scale

  • 7/27/2019 0422- A Little Graph Theory for Developers

    8/62

    Aggregate-OrientedDatah%p://[email protected]/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.

  • 7/27/2019 0422- A Little Graph Theory for Developers

    9/62

  • 7/27/2019 0422- A Little Graph Theory for Developers

    10/62

    complexity = f(size, connectedness, uniformity)

  • 7/27/2019 0422- A Little Graph Theory for Developers

    11/62h%p://www.bbc.co.uk/london/travel/downloads/tube_map.html

  • 7/27/2019 0422- A Little Graph Theory for Developers

    12/62

    Propertygraphs

    Propertygraphmodel:Nodeswithproper@esNamed,directedrela@onshipswithproper@esRela@onshipshaveexactlyonestartandendnode

    Whichmaybethesamenode

  • 7/27/2019 0422- A Little Graph Theory for Developers

    13/62

    PropertyGraphModel

  • 7/27/2019 0422- A Little Graph Theory for Developers

    14/62

    PropertyGraphModel

    TRAVELS_WITH

    TRAVELS_W

    ITH

    LOVES

  • 7/27/2019 0422- A Little Graph Theory for Developers

    15/62

    PropertyGraphModel

    TRAVELS_WITH

    TRAVELS_W

    ITH

    LOVES

    name: the Doctorage: 907

    species: Time Lord

    first name: Roselate name: Tyler

    vehicle: tardismodel: Type 40

  • 7/27/2019 0422- A Little Graph Theory for Developers

    16/62

    LabeledPropertyGraphModel(Neo4j2.0)

    TRAVELS_WITH

    TRAVELS_W

    ITH

    LOVES

    name: the Doctorage: 907

    species: Time Lord

    first name: Roselate name: Tyler

    vehicle: tardismodel: Type 40

    Label:human

    Label:timelord

  • 7/27/2019 0422- A Little Graph Theory for Developers

    17/62

    Propertygraphsareverywhiteboard-friendly

  • 7/27/2019 0422- A Little Graph Theory for Developers

    18/62h%p://blogs.adobe.com/digitalmarke@ng/analy@cs/predic@ve-analy@cs/predic@ve-analy@cs-and-the-digital-marketer/

  • 7/27/2019 0422- A Little Graph Theory for Developers

    19/62h%p://en.wikipedia.org/wiki/File:Leonhard_Euler_2.jpg

    MeetLeonhardEuler

    Swissmathema@cian InventorofGraphTheory(1736)

  • 7/27/2019 0422- A Little Graph Theory for Developers

    20/62h%p://en.wikipedia.org/wiki/Seven_Bridges_of_Knigsberg

  • 7/27/2019 0422- A Little Graph Theory for Developers

    21/62

  • 7/27/2019 0422- A Little Graph Theory for Developers

    22/62

    TriadicClosure

    name: Kyle

    name: Stan name: Kenny

  • 7/27/2019 0422- A Little Graph Theory for Developers

    23/62

    TriadicClosure

    name: Kyle

    name: Stan name: Kenny

    name: Kyle

    name: Stan name: KennyFRIEND

  • 7/27/2019 0422- A Little Graph Theory for Developers

    24/62

    StructuralBalance

    name: Cartman

    name: Craig name: Tweek

  • 7/27/2019 0422- A Little Graph Theory for Developers

    25/62

    StructuralBalance

    name: Cartman

    name: Craig name: Tweek

    name: Cartman

    name: Craig name: TweekFRIEND

  • 7/27/2019 0422- A Little Graph Theory for Developers

    26/62

    StructuralBalance

    name: Cartman

    name: Craig name: Tweek

    name: Cartman

    name: Craig name: TweekENEMY

  • 7/27/2019 0422- A Little Graph Theory for Developers

    27/62

    StructuralBalance

    name: Kyle

    name: Stan name: Kenny

    name: Kyle

    name: Stan name: KennyFRIEND

  • 7/27/2019 0422- A Little Graph Theory for Developers

    28/62

    StructuralBalanceisakey

    predic@vetechnique

    Anditsdomain-agnos@c

  • 7/27/2019 0422- A Little Graph Theory for Developers

    29/62

    AlliesandEnemies

    UK

    GermanyFrance

    Russia Italy

    Austria

  • 7/27/2019 0422- A Little Graph Theory for Developers

    30/62

    AlliesandEnemies

    UK

    GermanyFrance

    Russia Italy

    Austria

  • 7/27/2019 0422- A Little Graph Theory for Developers

    31/62

    AlliesandEnemies

    UK

    GermanyFrance

    Russia Italy

    Austria

  • 7/27/2019 0422- A Little Graph Theory for Developers

    32/62

    AlliesandEnemies

    UK

    GermanyFrance

    Russia Italy

    Austria

  • 7/27/2019 0422- A Little Graph Theory for Developers

    33/62

    AlliesandEnemies

    UK

    GermanyFrance

    Russia Italy

    Austria

  • 7/27/2019 0422- A Little Graph Theory for Developers

    34/62

    AlliesandEnemies

    UK

    GermanyFrance

    Russia Italy

    Austria

  • 7/27/2019 0422- A Little Graph Theory for Developers

    35/62

    Predic@ngWWI[EasleyandKleinberg]

  • 7/27/2019 0422- A Little Graph Theory for Developers

    36/62

    StrongTriadicClosure

    Itifanodehasstrongrela3onshipstotwo

    neighbours,thentheseneighboursmusthaveat

    leastaweakrela3onshipbetweenthem.

    [Wikipedia]

  • 7/27/2019 0422- A Little Graph Theory for Developers

    37/62

    TriadicClosure(weakrela@onship)

    name: Kenny

    name: Stan name: Cartman

  • 7/27/2019 0422- A Little Graph Theory for Developers

    38/62

    TriadicClosure(weakrela@onship)

    name: Kenny

    name: Stan name: Cartman

    name: Kenny

    name: Stan name: CartmanFRIEND 50%

  • 7/27/2019 0422- A Little Graph Theory for Developers

    39/62

    Weakrela@onships

    Rela@onshipscanhavestrengthaswellasintent

    Think:weigh@ngonarela@onshipinapropertygraph

    Weaklinksplayanothersuper-importantstructuralroleingraphtheory

    Theybridgeneighbourhoods

  • 7/27/2019 0422- A Little Graph Theory for Developers

    40/62

    LocalBridges

    FRIEND

    name: Kenny

    name: Stanname: KyleFRIENDFR

    IEND

    FRIEND

    name: Sally

    name: Bebename: WendyFRIENDF

    RIEND

    FRIEND 50%

    name: CartmanFRIEND

    ENEMY

  • 7/27/2019 0422- A Little Graph Theory for Developers

    41/62

    LocalBridgeProperty

    IfanodeAinanetworksa3sfiestheStrong

    TriadicClosurePropertyandisinvolvedinat

    leasttwostrongrela3onships,thenanylocal

    bridgeitisinvolvedinmustbeaweakrela3onship.

    [EasleyandKleinberg]

  • 7/27/2019 0422- A Little Graph Theory for Developers

    42/62

    UniversityKarateClub

  • 7/27/2019 0422- A Little Graph Theory for Developers

    43/62

    GraphPar@@oning

    (NP)HardproblemRecursivelyremovethespanninglinksbetweendenseregions

    Orrecursivelymergenodesintoeverlargersubgraphnodes

    Chooseyouralgorithmcarefullysomearebe%erthanothersforagivendomain

    Canuseto(almostexactly)predictthebreakupofthekarateclub!

  • 7/27/2019 0422- A Little Graph Theory for Developers

    44/62

    UniversityKarateClubs(predictedbyGraphTheory)

    9

  • 7/27/2019 0422- A Little Graph Theory for Developers

    45/62

    UniversityKarateClubs(whatactuallyhappened!)

  • 7/27/2019 0422- A Little Graph Theory for Developers

    46/62

  • 7/27/2019 0422- A Little Graph Theory for Developers

    47/62

    Cypher

    Declara@vegraphpa%ernmatchinglanguageSQLforgraphsColumnarresults

    Supportsgraphmatchingcommandsandqueries

    FindmestufflikethisAggrega@on,orderingandlimit,etc.

  • 7/27/2019 0422- A Little Graph Theory for Developers

    48/62

  • 7/27/2019 0422- A Little Graph Theory for Developers

    49/62

    Firstname:MickeySurname: Smith

    DoB: 19781006

    SKU: 5e175641Product:Badgers

    Nadgers Ale

    SKU: 2555f258Product:Peewee Pilsner

    Category: beer

    SKU: 49d102bcProduct: BabyDry Nights

    Category:nappies

    Category: baby Category:alcoholicdrinks

    SKU: 49d102bcProduct: XBox360

    Category:consumerelectronics

    Category:console

    BOUGHTBOUGHT

    MEMBER_

    OF

    MEMBER_OFMEMBER_OF

    MEMBER_OFMEMBER_OF

  • 7/27/2019 0422- A Little Graph Theory for Developers

    50/62

  • 7/27/2019 0422- A Little Graph Theory for Developers

    51/62

    Firstname: *Surname: *DoB: 1996 > x

    > 1972

    Category: beerCategory:nappies

    BOUGHTCategory: gameconsole

  • 7/27/2019 0422- A Little Graph Theory for Developers

    52/62

    Firstname: *Surname: *DoB: 1996 > x

    > 1972

    Category: beerCategory:nappies

    !BOUGHTCategory: gameconsole

  • 7/27/2019 0422- A Little Graph Theory for Developers

    53/62

    (beer)(nappies)

    (console)

    (daddy)

    ()()

  • 7/27/2019 0422- A Little Graph Theory for Developers

    54/62

    Fla%enthegraph

    (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies)

    (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer)

    (daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console)

  • 7/27/2019 0422- A Little Graph Theory for Developers

    55/62

    WrapinaCypherMATCHclause

    MATCH (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies),

    (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer),

    (daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console)

  • 7/27/2019 0422- A Little Graph Theory for Developers

    56/62

    CypherWHEREclause

    MATCH (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(nappies),

    (daddy)-[:BOUGHT]->()-[:MEMBER_OF]->(beer),

    (daddy)-[b:BOUGHT]->()-[:MEMBER_OF]->(console)

    WHERE b is null

  • 7/27/2019 0422- A Little Graph Theory for Developers

    57/62

    FullCypherquery

    START beer=node:categories(category=beer),nappies=de: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

  • 7/27/2019 0422- A Little Graph Theory for Developers

    58/62

    Results

    ==> +---------------------------------------------+

    ==> | daddy |

    ==> +---------------------------------------------+

    ==> | Node[15]{name:"Rory Williams",dob:19880121} |

    ==> +---------------------------------------------+

    ==> 1 row

    ==> 6 ms

    ==>

    neo4j-sh (0)$

  • 7/27/2019 0422- A Little Graph Theory for Developers

    59/62

  • 7/27/2019 0422- A Little Graph Theory for Developers

    60/62

    Whataregraphsgoodfor?

    Recommenda@ons Businessintelligence Socialcompu@ng Geospa@al MDM Datacentremanagement Webofthings Genealogy Timeseriesdata Productcatalogue

    Webanaly@cs Scien@ficcompu@ng(especiallybioinforma@cs) IndexingyourslowRDBMS Andmuchmore!

    Co

  • 7/27/2019 0422- A Little Graph Theory for Developers

    61/62

    FreeOReillyeBook!

    Visit:

    h%p://GraphDatabases.com

    Ian Robinson,Jim Webber & Emil Eifrem

    Graph

    Databases

    h

    Complim

    ents

    ofNeoTechnology

  • 7/27/2019 0422- A Little Graph Theory for Developers

    62/62

    ThanksforlisteningNeo4j:h"p://neo4j.org

    Me:@jimwebber