graph-theory

Using the apriori algorithm for recommendations

放肆的年华 提交于 2020-01-23 07:46:11
问题 So a recent question made me aware of the rather cool apriori algorithm. I can see why it works, but what I'm not sure about is practical uses. Presumably the main reason to compute related sets of items is to be able to provide recommendations for someone based on their own purchases (or owned items, etcetera). But how do you go from a set of related sets of items to individual recommendations? The Wikipedia article finishes: The second problem is to generate association rules from those

Using the apriori algorithm for recommendations

旧街凉风 提交于 2020-01-23 07:45:17
问题 So a recent question made me aware of the rather cool apriori algorithm. I can see why it works, but what I'm not sure about is practical uses. Presumably the main reason to compute related sets of items is to be able to provide recommendations for someone based on their own purchases (or owned items, etcetera). But how do you go from a set of related sets of items to individual recommendations? The Wikipedia article finishes: The second problem is to generate association rules from those

How to draw parallel edges in Networkx / Graphviz

北城余情 提交于 2020-01-22 15:12:21
问题 I am trying to add parallel edges between two nodes using NetworkX but it fails with the below error. What am I doing wrong? import networkx as nx import graphviz g1 = nx.MultiGraph() node1 = 'a' node2 = 'b' g1.add_edge(node1,node2,key='one') g1.add_edge(node1,node2,key='two') A = nx.to_agraph(g1) A.add_subgraph() A.draw('test2.png', prog='dot') Error: Traceback (most recent call last): File "test2.py", line 12, in <module> A = nx.to_agraph(g1) File "C:\python27\lib\site-packages\networkx-1

How to delete all related nodes in a directed graph using networkx?

情到浓时终转凉″ 提交于 2020-01-22 12:44:50
问题 I'm not sure exactly sure what the correct terminology is for my question so I'll just explain what I want to do. I have a directed graph and after I delete a node I want all independently related nodes to be removed as well. Here's an example: Say, I delete node '11', I want node '2' to be deleted as well(and in my own example, they'll be nodes under 2 that will now have to be deleted as well) because its not connected to the main graph anymore. Note, that node '9' or '10' should not be

How to find two disjoint spanning trees of an undirected graph

纵然是瞬间 提交于 2020-01-22 09:51:07
问题 Is there any applicable approach to find two disjoint spanning trees of an undirected graph or to check if a certain graph has two disjoint spanning trees 回答1: This is an example of Matroid union. Consider the graphic matroid where the basis are given by the spanning trees. Now the union of this matroid with itself is again a matroid. Your question is about the size of the basis of this matroid. (whether there exist a basis of size $2(|V|-1)$. The canonical algorithm for this is Matroid

Dijkstra's algorithm with back tracking?

感情迁移 提交于 2020-01-21 09:14:49
问题 In a related thread, it was suggested that I impliment Dijkstra's algorithm for finding the shortest path on a graph. Looking at this .gif of the algorithm from wikipedia: What if the path 1,3,6,5 turned out to be very low cost? For example, the weight on 3-6 was 1, and the weight on 6-5 was 2? Dijkstra's algorithm would not consider this path because it only looks one step ahead; it skipped node 3. Is it acceptable to specify a parameter that makes the algorithm look 2,3,4...n steps ahead

C++ Linked List Printing… I get the infinite loop

梦想与她 提交于 2020-01-16 19:07:29
问题 I used this in my main function but it's not working void LinkedList::TraPrinHead(const LinkedList& p) { Nodes* currentNodes = header->next; while( currentNodes != tail ) { cout << currentNodes->elem << " ----> "; currentNodes = currentNodes->next; } } I expect to print the whole list from this... but I keep getting the infinite loop. cout << currentNodes->elem << " ----> "; currentNodes = currentNodes->next; cout << currentNodes->elem << " ----> "; currentNodes = currentNodes->next; And even

C++ Linked List Printing… I get the infinite loop

穿精又带淫゛_ 提交于 2020-01-16 19:07:09
问题 I used this in my main function but it's not working void LinkedList::TraPrinHead(const LinkedList& p) { Nodes* currentNodes = header->next; while( currentNodes != tail ) { cout << currentNodes->elem << " ----> "; currentNodes = currentNodes->next; } } I expect to print the whole list from this... but I keep getting the infinite loop. cout << currentNodes->elem << " ----> "; currentNodes = currentNodes->next; cout << currentNodes->elem << " ----> "; currentNodes = currentNodes->next; And even

clique number of a graph

Deadly 提交于 2020-01-15 12:09:49
问题 I would like to know a fast algorithm to find only the clique number(without actually finding the clique) of a graph with about 100 vertices. I am trying to solve the following problem. http://uva.onlinejudge.org/external/1/193.html 回答1: This is NP-complete, and you can't do it much better than actually finding the maximum clique and counting its vertices. From Wikipedia: Clique problems include: solving the decision problem of testing whether a graph contains a clique larger than N These

how to connect edges to nodes in a image using minimum spanning tree approach

a 夏天 提交于 2020-01-15 01:54:08
问题 I am doing my project on graph matching in hand written image, i want to represent a given word image in graph, am using the below algorithm Algorithm: input: Binary image B, Grid width w, Grid height h Output: Graph g = (V, E) with nodes V and edges E 1: function Grid(B,w,h) 2: for i ← 1 to number of columns C = Width of B/w do 3: for j ← 1 to number of rows R = Height of B/h do 4: V = V ∪ {(xm, ym) | (xm, ym) is the centre of mass of segment sij} 5: for Each pair of nodes (u, v) ∈ V × V do