def GENERATE_RANDOM_EXPANDERS(K, size_H, EPSILON, samples): NAME = '[RANDOM' + str(K) + ']' print NAME + " Generating " + str( samples) + " H (adjacency list matrices) of size " + str( size_H) + " x " + str(K) + " ... " print "\n" eigenvalue = 0 for sampling in range(samples): print NAME + " ## " + str(sampling) + " // " + str( samples) + " ## " H = generate_expander(K, size_H) eigenvalue_aux = helpers.generate_eigenvalue(H, size_H, K, EPSILON, NAME) eigenvalue += eigenvalue_aux eigenvalue = eigenvalue / samples print NAME + " Calculated average of second highest eigenvalue for " + str( samples) + " matrices H." helpers.write_result(NAME, size_H, K, eigenvalue) helpers.cleanup(".aux")
def GENERATE_ANGLUIN_EXPANDERS(size, A_indices, n, EPSILON): size_H = 2 * size print NAME + " Generating H (adjacency list matrix) of size " + str( size_H) + " x " + str(K) + " ... " H = numpy.empty( shape=(size_H, K), dtype=numpy.int32) # Generate H, empty adjacency list matrix for row in A_indices: for element_index in row: # Get the tuple index from the matrix of indices (A) x0 = element_index / n # Grab first value y0 = element_index % n # Grab second value i = element_index # Grab the index of the (x0, y0) element # connect to (x, y) in B x = x0 y = y0 j = (x * n + y % n) + size # add the shift in the H indexing H[i][0] = j # node with index i is connected to node with index j H[j][0] = i # vice-versa # connect to (x + y, y) in B x = (x0 + y0) % n y = y0 j = (x * n + y % n) + size H[i][1] = j H[j][1] = i # connect to (y + 1, -x) in B x = (y0 + 1) % n y = (-x0) % n j = (x * n + y % n) + size H[i][2] = j H[j][2] = i print NAME + " Generated adjacency list matrix H." print NAME + " Calculating second highest eigenvalue of H ... " eigenvalue = helpers.generate_eigenvalue(H, size_H, K, EPSILON, NAME) print NAME + " Calculated second highest eigenvalue of H." helpers.write_result(NAME, size_H, K, eigenvalue) helpers.cleanup(".aux")
def GENERATE_ANGLUIN_EXPANDERS(size, A_indices, n, EPSILON): size_H = 2 * size print NAME + " Generating H (adjacency list matrix) of size " + str(size_H) + " x " + str(K) + " ... " H = numpy.empty(shape=(size_H, K), dtype=numpy.int32) # Generate H, empty adjacency list matrix for row in A_indices: for element_index in row: # Get the tuple index from the matrix of indices (A) x0 = element_index / n # Grab first value y0 = element_index % n # Grab second value i = element_index # Grab the index of the (x0, y0) element # connect to (x, y) in B x = x0 y = y0 j = (x * n + y % n) + size # add the shift in the H indexing H[i][0] = j # node with index i is connected to node with index j H[j][0] = i # vice-versa # connect to (x + y, y) in B x = (x0 + y0) % n y = y0 j = (x * n + y % n) + size H[i][1] = j H[j][1] = i # connect to (y + 1, -x) in B x = (y0 + 1) % n y = (-x0) % n j = (x * n + y % n) + size H[i][2] = j H[j][2] = i print NAME + " Generated adjacency list matrix H." print NAME + " Calculating second highest eigenvalue of H ... " eigenvalue = helpers.generate_eigenvalue(H, size_H, K, EPSILON, NAME) print NAME + " Calculated second highest eigenvalue of H." helpers.write_result(NAME, size_H, K, eigenvalue) helpers.cleanup(".aux")
def GENERATE_RANDOM_EXPANDERS(K, size_H, EPSILON, samples): NAME = '[RANDOM' + str(K) + ']' print NAME + " Generating " + str(samples) + " H (adjacency list matrices) of size " + str(size_H) + " x " + str(K) + " ... " print "\n" eigenvalue = 0 for sampling in range(samples): print NAME + " ## " + str(sampling) + " // " + str(samples) + " ## " H = generate_expander(K, size_H) eigenvalue_aux = helpers.generate_eigenvalue(H, size_H, K, EPSILON, NAME) eigenvalue += eigenvalue_aux eigenvalue = eigenvalue / samples print NAME + " Calculated average of second highest eigenvalue for " + str(samples) + " matrices H." helpers.write_result(NAME, size_H, K, eigenvalue) helpers.cleanup(".aux")