110 likes | 209 Views
Graph Algorithms and Databases. Du šan Zeleník. Common Tasks. Sorting Searching Inferring Routing. Entities and their properties. Single attribute entities Simple ordinal values Relatively easy to sort or search Low complexity Indexing Multi attribute entities
E N D
GraphAlgorithms and Databases DušanZeleník
Common Tasks • Sorting • Searching • Inferring • Routing
Entities and their properties • Single attribute entities • Simple ordinal values • Relatively easy to sort or search • Low complexity • Indexing • Multi attribute entities • Relations among entities • Calculating distances (similarity) • Discovering properties
Trees and Graphs • Tree is a graph • Balancing • Lowering the complexity ( O(log n) ) • Graph • Triplets (S - P - O) • Complex structure with properties • Polynomial compelxity ( O(n^k) )
Spreading Activation • Select initial nodes and fill them with energy • Spread energy from nodes • Split energy among associated nodes • Mark nodes as already used • Do not spread if energy is under threshold • Repeat spreading until convergence
Page Rank • Each node receives initial rank • Count outgoing edges C(node) • Page Rank for Node A is PR(A) = =(1- d) + d (PR(T1)/C(T1) + ... + PR(Tn)/C(Tn)) PR(A) is the PageRank of page A, PR(Ti) is the PageRankof pages Ti which link to page A, C(Ti) is the number of outbound links on page Ti d is a damping factor which can be set between 0 and 1.
Neo4J Database • Java • SPARQL, cypher, gremlin • ACID • Multiplatform • Opensource • Plugins • Already implements many algorithms • REST
Neo4J Hello World Node f = graphDb.createNode(); f.setProperty("message","Hello"); Node s = graphDb.createNode(); s.setProperty("message","World!"); Relationship r = f.createRelationshipTo(s, RelTypes.KNOWS ); r.delete(); f.delete(); s.delete();
Neo4J Graph Algorithms PathFinder<WeightedPath> finder = GraphAlgoFactory.dijkstra( Traversal.expanderForTypes( ExampleTypes.MY_TYPE, Direction.BOTH ), "cost" ); WeightedPathpath = finder.findSinglePath( nodeA, nodeB ); path.weight();
Neo4J Plugin publicclassShortestPathextendsServerPlugin{ @Description( "Findtheshortestpathbetweentwonodes." ) @PluginTarget( Node.class ) publicIterable<Path> shortestPath(@SourceNodesource, @Parameter( name = "target" ) Nodetarget, @Parameter( name = "types", optional = true ) String[] types, @Parameter( name = "depth", optional = true ) Integerdepth ) { Expanderexpander; if ( types == null ) expander = Traversal.expanderForAllTypes(); else { expander = Traversal.emptyExpander(); for ( int i = 0; i < types.length; i++ ) expander = expander.add( DynamicRelationshipType.withName( types[i] ) ); } PathFinder<Path> shortestPath = GraphAlgoFactory.shortestPath( expander, depth == null ? 4 : depth.intValue() ); returnshortestPath.findAllPaths( source, target ); } } curl -X POST http://localhost:7474/db/data/ext/GetAll/node/123/shortestPath \ -H "Content-Type: application/json" \ -d '{"target":"http://localhost:7474/db/data/node/456&depth=5"}'
Research and Graphs • Z. Huang, W. Chung, T.-H. Ong, and H. Chen, “A graphbased recommender system for digital library,” in Proceedings of the 2nd ACM/IEEE-CS joint conference on Digital libraries, ser. JCDL ’02. New York, NY, USA: ACM, 2002,pp. 65–73. • I. Mele, F. Bonchi, and A. Gionis, “The early-adopter graph and its application to web-page recommendation.” New York, New York, USA: ACM Press, 2012, p. 1682. • S. D. Kamvar, T. H. Haveliwala, C. D. Manning, and G. H. Golub, “Extrapolation methods for accelerating pagerank computations,” in Proceedings of the 12th international conference on World Wide Web, ser. WWW ’03. New York, NY, USA: ACM, 2003, pp. 261–270. • Y. Deng, Z. Wu, C. Tang, H. Si, H. Xiong, and Z. Chen, “A Hybrid Movie Recommender Based on Ontology and Neural Networks.” Ieee, Dec. 2010, pp. 846–851. • B. Chen, J. Wang, Q. Huang, and T. Mei, “Personalized video recommendation through tripartite graph propagation.” New York, New York, USA: ACM Press, 2012, p. 1133.