from createGraph import createGraph,createUser, createFriends from queryGraph import checkConnectivity, getDegree a = createGraph() g = a.createGraph() m = a.createMapping() count = 0 while 1: if count==0 or count==1: choice = raw_input("\n\nChoose:\n0. Exit\n1. Add a user\n") elif count>=2: choice = raw_input("\n\nChoose:\n0. Exit\n1. Add a user\n2. Add a friend link\n3. Check connectivity\n4. Check degree of connection\n") count = count+1 if choice=='0': break elif choice=='1': username=raw_input("Enter a username:\t") b = createUser(username,g,m) if b.makeNode(): print "User created" else: print "User already exists" elif choice=='2': user1,user2 = raw_input("Enter the usernames of each user seperated by a tab:\t").split('\t') c = createFriends(user1,user2,g,m) if c.makeLinks(): print "Friendship link established" else:
edge_list.append((node, nbhr, w)) # Sort list using edge weight as key and return in reverse of asc. order return sorted(edge_list, key = lambda edge : edge[2], reverse=True) """ Get random node """ def getRandomNode(self): index = randint(0, len(self.node_list) - 1) return self.node_list[index] if __name__ == '__main__': # Create biparitite graph from existing Advertisement and Keywords (g, list_of_test_sessions) = createGraph() # Convert bipartite graph to directed graph using similarity function # of ads g_new = Graph() g_new.bipartiteConversion(g) # Get list of sorted edges by weight sorted_edge_list = g_new.sortedListOfEdges() # create list of singleton clusters cluster_list = [] node_cluster_dict = {} for node in g_new.node_list: cluster = Cluster(node) node_cluster_dict[node] = cluster
for cluster in list_1: l.append(cluster) else: l.append(list_1) if isinstance(list_2, list): for cluster in list_2: l.append(cluster) else: l.append(list_2) return l if __name__ == '__main__': # Create SPECTRAL biparitite graph from existing Advertisement and Keywords (spectralG, list_of_test_sessions) = createGraph(True) spectralG.setWeightMatrix() #cluster1, cluster2 = spectralG.partition() list_of_clusters = produceClusters(spectralG) # print number of clusters print "Number of clusters:", len(list_of_clusters) # map each test session to its keyword list_test_keywords = map(lambda x : Keyword(x.keyword_id), list_of_test_sessions) # compute predictions for CTR list_CTR_predictions = [] count = 0 for kw in list_test_keywords:
#createGraph(xaxis,yaxis,start,end,size) (length, xaxis, yaxis, cdf, cdfW) = StandardizeDistributionW(xaxis, yaxis) ylimStart = 0 ylimEnd = 1 plt.figure(1) multiplier = -10 plt.subplot(4, 2, 1) fromN = 10**(0 + multiplier) fromN = 0 toN = 10**(2 + multiplier) plt.title(str(fromN) + ' - ' + str(toN)) (x, y) = createGraph(xaxis, yaxis, fromN, toN, 1000) plt.ylim(ylimStart, ylimEnd) plt.plot(x, y) plt.subplot(4, 2, 2) fromN = 10**(2 + multiplier) fromN = 0 toN = 10**(4 + multiplier) plt.title(str(fromN) + ' - ' + str(toN)) (x, y) = createGraph(xaxis, yaxis, fromN, toN, 1000) plt.ylim(ylimStart, ylimEnd) plt.plot(x, y) plt.subplot(4, 2, 3) fromN = 10**(4 + multiplier) fromN = 0