def graphMSEarrays(self, epochs): # x (array-like): a list of x-coordinates # y (array-like): a list of y-coordinates # labels (array-like): a list of integers corresponding to classes # title (str): Title of graph # xlabel (str): X-axis title # ylabel (str): Y-axis title, .5 # points (bool): True will plot points, False a line # style: Plot style (e.g. ggplot, fivethirtyeight, classic etc.) # xlim (2-tuple): x-min, x-max # ylim (2-tuple): y-min, y-max # save_path (str): where graph should be saved x = np.arange(0, epochs, 1) print("MSEARRAY", self.mseArray) print(len(self.mseArray)) print(x) graph_tools.graph(x=x, y=self.mseArray, y2=self.validMseArray, title="Training MSE", xlabel="epochs", ylabel="MSE", xlim=(0, epochs), style="classic", save_path="graphs/mse")
def sparsify_graph(G, p): processed_edges = {} numedges = 0 # Create a new graph G_sparse = graph_tools.graph() for node1 in G.vertices: neighbors = G.adj_list[node1] # Get all neighbors of node1 for eachneighbor in neighbors: # if the processed_edges dictionary has the entry for edge (node1, eachneighbor) or (eachneighbor, node1) if (processed_edges.has_key((node1, eachneighbor)) or processed_edges.has_key((eachneighbor, node1))): if (processed_edges.has_key((node1, eachneighbor))): if not processed_edges.has_key((eachneighbor, node1)): processed_edges[(eachneighbor, node1)] = 1 else: if not processed_edges.has_key((eachneighbor, node1)): processed_edges[(node1, eachneighbor)] = 1 else: # If there is no entry for (node1,eachneighbor), then add the edge to the processed_edges dict # Generate a random number for the edge. # If the generated random number is less than input 'p', include the edge to G_sparse processed_edges[(eachneighbor, node1)] = 1 processed_edges[(node1, eachneighbor)] = 1 randno = random.uniform(0, 1) if (randno <= p): numedges = numedges + 1 G_sparse.Add_und_edge(node1, eachneighbor) G_sparse.Add_und_edge(eachneighbor, node1) print "number of edges in the sparse graph = ", numedges return G_sparse
import graph_tools import eigen_triangle_count import triangle_counters print('Creating empty graph G') # Create empty graph #for f in os.listdir('../graphs'): G = graph_tools.graph() fname = '../graphs/facebook_combined.txt' # Enter file name print('Reading edges from file', fname, 'into G') G.Read_edges( '../graphs/' + fname) # Read edges from file (in this case it is from amazon0312.txt) #print('Computing degeneracy ordering/orientation into D') #D = G.Degeneracy() # Compute degeneracy DAG #print('Computing degreee distributions of G and D') #dd = G.Deg_dist('amazon-dd.txt') # Compute degree distribution of G in dd, and output that in 'amazon-dd.txt' #dd_degen = D.Deg_dist('amazon-degen-dd.txt') # Compute degree distribution of D in dd, and output that in 'amazon-degen-dd.txt' G_size = G.Size() # Output size of G print('Size of G: vertices = ', G_size[0], ', sum of degrees = ', G_size[1], ', wedges =', G_size[2]) #D_size = D.Size() # Output size of D #print('Size of D: vertices = ',D_size[0],', sum of degrees = ',D_size[1],', wedges =',D_size[2]) #dg_count = triangle_counters.wedge_enum(D) # Perform wedge enumeration on D to count triangles #print('Running wedge enumeration on D, triangle count =',dg_count)
import graph_tools import triangle_counters import color_coding print('Creating empty graph G') G = graph_tools.graph() # Create empty graph # fname = input('Enter file name: ') # Enter file name (../graphs/amazon0312.txt) fname = '../graphs/cit-HepPh.txt' print('Reading edges from file', fname, 'into G') G.Read_edges( fname ) # Read edges from file (in this case it is from '../graphs/cit-HepPh.txt' ) G_size = G.Size() # Output size of G print('Size of G: vertices = ', G_size[0], ', sum of degrees = ', G_size[1], ', wedges =', G_size[2]) g_count = triangle_counters.wedge_enum( G ) # Perform wedge enumeration on G to count triangles. Note that this is three times the number of triangles. print('Running wedge enumeration on G, triangle count =', g_count) ## Run the color coding algorithm multiple times to get an average: print('Running color coding and wedge enumeration on G') tcounts = [] runs = input('Enter the number of runs: ') for run in range(0, runs): # Get the count for the number of triangles. For 3 random colors chosen, the number of triangles # estimated from this algorithm, is 2/9 times the actual number of triangles obtained from wedge enumeration. g_colorcoding_count = color_coding.color_coding(G)
def test_DAGs(gfnames, iterations=1, verbose=False): orderings = ['RandomOrder', 'DegreeOrder', 'DegenOrder'] stats = {} for gfname in gfnames: stats[gfname] = { 'G': { 'read': [], 'wedges': [], 'triangles': [], 'time': [] } } for ordering in orderings: stats[gfname][ordering] = { 'create': [], 'wedges': [], 'triangles': [], 'time': [] } for iteration in range(0, iterations): for gfname in gfnames: G = graph_tools.graph() if verbose: print('Reading edges from file %s' % gfname) start = time.clock() G.Read_edges(gfname) end = time.clock() ellapsed = end - start stats[gfname]['G']['read'].append(ellapsed) if verbose: print(" Time to read graph (%s): %.2fs" % (gfname, ellapsed)) print start = time.clock() (triangles, wedges) = triangle_counters.wedge_enum(G, wedges=True) triangles /= 3 end = time.clock() ellapsed = end - start stats[gfname]['G']['triangles'].append(triangles) stats[gfname]['G']['wedges'].append(wedges) stats[gfname]['G']['time'].append(ellapsed) if verbose: print( ' Running wedge enumeration on G, triangle count=%d (time=%.2fs)' % (triangles, ellapsed)) print for order in orderings: start = time.clock() D = eval('G.%s()' % order) end = time.clock() ellapsed = end - start stats[gfname][order]['create'].append(ellapsed) if verbose: print(" Time to create DAG (%s): %.2fs" % (order, ellapsed)) start = time.clock() (triangles, wedges) = triangle_counters.wedge_enum(D, wedges=True) end = time.clock() ellapsed = end - start stats[gfname][order]['triangles'].append(triangles) stats[gfname][order]['wedges'].append(wedges) stats[gfname][order]['time'].append(ellapsed) if verbose: print( ' Running wedge enumeration on D (%s), triangle count=%d (time=%.2fs)' % (order, triangles, ellapsed)) print return stats