def main(): # Make printing a bit nicer for visualizing np.set_printoptions(threshold=sys.maxsize, linewidth=sys.maxsize) layout = np.array([[-2, -2, -2, -2, -2, -2, -2, -2, -2], [-2, -2, -2, -2, -2, -2, -2, -2, -2], [-2, -2, -2, -2, -2, -2, -2, -2, -2], [-2, -2, -2, -1, -1, -1, -2, -2, -2], [-2, -2, -2, -1, -1, -1, -2, -2, -2], [-2, -2, -2, -1, -1, -1, -2, -2, -2], [-2, -2, -2, -2, -2, -2, -2, -2, -2], [-2, -2, -2, -2, -2, -2, -2, -2, -2], [-2, -2, -2, -2, -2, -2, -2, -2, -2]]) plt.imshow(layout) plt.show() coordinates = shared.index_layout(layout) print(layout) adjacency_list = get_adjacency_list(layout, coordinates) print(adjacency_list) laplacian = shared.compute_laplacian(adjacency_list) potentials = compute_harmonic_function(laplacian, 3, 3, 1) #print(potentials) harmonic_function = shared.display_harmonic_function(potentials, coordinates, 9, display_type='grid') print('resistance', 1/shared.get_energy(adjacency_list, potentials, 1))
def setup(b, l, crosswires, level): # Begin Setup for Calculating Harmonic Function print( 'Beginning Setup for + Graph Approximation using b=%d, l=%d, crosswires=%d, level=%d ...' % (b, l, crosswires, level)) grid_size = plus.get_grid_size(b, crosswires, level) layout = plus.get_grid_layout(b, l, crosswires, level) # Visualization of Fractal shared.display_grid_layout(layout, display_type='matplotlib') # Possibly need to clear some memory, insert `del layout` at some point coordinates = shared.index_layout(layout) adjacency_list = plus.get_adjacency_list(layout, coordinates, crosswires) laplacian = shared.compute_laplacian(adjacency_list) return grid_size, layout, coordinates, adjacency_list, laplacian
def main(): ''' Executed with `python cross.py`. This takes parameters from the user and generates the associated harmonic function potentials. ''' # Make printing a bit nicer for visualizing np.set_printoptions(threshold=sys.maxsize, linewidth=sys.maxsize) # Algorithm Parameters (Type -h for usage) parser = argparse.ArgumentParser( description= 'Generates the x Graph Approximations for the Sierpinski Carpet') parser.add_argument( '-b', default=3, type=int, help='The number of sections to divide the carpet into') parser.add_argument( '-l', default=1, type=int, help='The number of sections to remove from the carpet center') parser.add_argument('-a', '--level', type=int, default=3, help='Number of pre-carpet contraction iterations') args = parser.parse_args() # Begin Computation of Harmonic Function print('Generating x Graph Approximation for b=%d, l=%d, level=%d ...' % (args.b, args.l, args.level)) grid_size = get_grid_size(args.b, args.level) layout = get_grid_layout(args.b, args.l, args.level) # Visualization of Fractal shared.display_grid_layout(layout, display_type='matplotlib') # Possibly need to clear some memory, insert `del layout` at some point coordinates = shared.index_layout(layout) adjacency_list = get_adjacency_list(layout, coordinates) laplacian = shared.compute_laplacian(adjacency_list) potentials = left_to_right_potentials(args.b, args.level, coordinates, laplacian)
def main(): # Make printing a bit nicer for visualizing np.set_printoptions(threshold=sys.maxsize, linewidth=sys.maxsize) # Algorithm Parameters (Type -h for usage) parser = argparse.ArgumentParser(description='Generates the + Graph Approximations for the Sierpinski Carpet') parser.add_argument('-b', type=int, default=3, help='The number of sections to divide the carpet into') parser.add_argument('-l', type=int, default=1, help='The number of sections to remove from the carpet center') parser.add_argument('-r', '--resolution', type=int, default=1, help='The number of vertices per square') parser.add_argument('-a', '--level', type=int, default=2, help='Number of pre-carpet contraction iterations') args = parser.parse_args() # Begin Computation of Harmonic Function print('Generating Basic Graph Approximation for b=%d, l=%d, resolution=%d, level=%d ...' % (args.b, args.l, args.resolution, args.level)) coordinates = get_coordinates(args.b, args.l, args.level, args.resolution) adjacency_list = get_adjacency_list(coordinates) laplacian = shared.compute_laplacian(adjacency_list) top_to_bottom_potentials(args.b, args.level, args.resolution, laplacian)
def main(): print('sdf') # Make printing a bit nicer for visualizing np.set_printoptions(threshold=sys.maxsize, linewidth=sys.maxsize) #print('asdfsadf') base_layout = np.array([[-1, -2, -2, -2, -1], [-2, -2, -2, -2, -2], [-2, -2, -2, -2, -2], [-2, -2, -2, -2, -2], [-1, -2, -2, -2, -1]]) blank_layout = np.full((5, 5), -1) x = np.hstack((base_layout, base_layout, base_layout)) y = np.hstack((base_layout, blank_layout, base_layout)) z = np.hstack((base_layout, base_layout, base_layout)) layout = np.vstack((x, y, z)) print(layout) plt.imshow(layout) plt.show() coordinates = shared.index_layout(layout) print(layout) adjacency_list = get_adjacency_list(layout, coordinates, 3) print(adjacency_list) laplacian = shared.compute_laplacian(adjacency_list) #plt.imshow(laplacian.todense()) #print(laplacian.todense()) #plt.show() potentials = compute_harmonic_function(laplacian, 3, 3, 1) #print(potentials) harmonic_function = shared.display_harmonic_function(potentials, coordinates, 15, display_type='grid') print('resistance', 1 / shared.get_energy(adjacency_list, potentials, 1))
def main(): # Make printing a bit nicer for visualizing np.set_printoptions(threshold=sys.maxsize, linewidth=sys.maxsize) # Algorithm Parameters (Type -h for usage) parser = argparse.ArgumentParser( description= 'Generates the + Graph Approximations for the Sierpinski Carpet') parser.add_argument( '-b', default=3, type=int, help='The number of sections to divide the carpet into') parser.add_argument( '-l', default=1, type=int, help='The number of sections to remove from the carpet center') parser.add_argument('-c', '--crosswires', type=int, default=1, help='The number of crosswires') parser.add_argument('-a', '--level', type=int, default=3, help='Number of pre-carpet contraction iterations') args = parser.parse_args() # Begin Computation of Harmonic Function print( 'Generating + Graph Approximation for b=%d, l=%d, crosswires=%d, level=%d ...' % (args.b, args.l, args.crosswires, args.level)) grid_size = get_grid_size(args.b, args.crosswires, args.level) layout = get_grid_layout(args.b, args.l, args.crosswires, args.level) # Visualization of Fractal shared.display_grid_layout(layout, display_type='matplotlib') # Possibly need to clear some memory, insert `del layout` at some point coordinates = shared.index_layout(layout) adjacency_list = get_adjacency_list(layout, coordinates, args.crosswires) laplacian = shared.compute_laplacian(adjacency_list) # 0 -> 1 Harmonic Function # Set Dirichlet Boundary Indices edge_length = args.crosswires * args.b**args.level boundary_indices = [] boundary_indices.extend(range(edge_length)) boundary_indices.extend(range(2 * edge_length, 3 * edge_length)) # Set Dirichlet Boundary boundary = np.zeros((2 * edge_length)) boundary[edge_length:] = 1 potentials = shared.compute_harmonic_function(laplacian, boundary_indices, boundary) harmonic_function = shared.display_harmonic_function(potentials, coordinates, grid_size, display_type='grid') # Energy Calculation #print('resistance', 1/shared.get_energy(adjacency_list, potentials, 1)) # Max Edge Portion '''max_edges = shared.max_edges(adjacency_list, potentials, coordinates, grid_size) print(max_edges) min_coordinate = (-1, -1) for edge in max_edges: print('------') print('left edge', coordinates[edge[0], 0], coordinates[edge[0], 1]) print('right edge', coordinates[edge[1], 0], coordinates[edge[1], 1]) print('left potential', potentials[edge[0]]) print('right potential', potentials[edge[1]]) print('------')''' # Exit Distribution # Set Dirichlet Boundary Indices #boundary_indices = [] #boundary_indices.extend(range(4*edge_length)) #boundary_indices.append(random.randint(4*edge_length, len(coordinates)-1)) # Set Dirichlet Boundary #boundary = np.full((4*edge_length+1), 0) #boundary[-1] = 1 #potentials2 = shared.compute_harmonic_function(laplacian, boundary_indices, boundary) #harmonic_function2 = shared.display_harmonic_function(potentials2, coordinates, grid_size, display_type='grid') #print(coordinates) #print(potentials2) #edge_diff_distribution = np #for i, row in enumerate(adjacency_list) #print() ## INTERPOLATION PORTION '''print('------------------------------------------------') print('Beginning Interpolation of cell for ...') interpolation_level = 4 # Finding maximum edge max_edges = shared.max_edges(adjacency_list, potentials, coordinates, grid_size) #print(max_edges) print(max_edges) # Fetching max_cell sublevel = 1 subcell_size = get_grid_size(args.b, args.crosswires, sublevel) print(max_edges[0,0]) print(coordinates[max_edges[0,0],0]) subcoordinate = (coordinates[max_edges[0,0],0]//(subcell_size-1), coordinates[max_edges[0,0],1]//(subcell_size-1)) print(subcoordinate) #print(subcoordinate) cell = get_max_subcell(harmonic_function, args.b, args.crosswires, args.level, subcoordinate, sublevel=sublevel) #generate_interpolation(cell, args.b, args.crosswires, interpolation_level) # Begin Computation of Harmonic Function interpolation_grid_size = get_grid_size(args.b, args.crosswires, interpolation_level) interpolation_layout = get_grid_layout(args.b, args.l, args.crosswires, interpolation_level) # Visualization of Fractal shared.display_grid_layout(interpolation_layout, display_type='matplotlib') # Possibly need to clear some memory, insert `del layout` at some point interpolation_coordinates = shared.index_layout(interpolation_layout) interpolation_adjacency_list = get_adjacency_list(interpolation_layout, interpolation_coordinates, args.crosswires) interpolation_laplacian = shared.compute_laplacian(interpolation_adjacency_list) dirichlet = generate_interpolation(cell, args.b, args.crosswires, interpolation_level, interpolation_layout) interpolation_potentials = compute_interpolation_harmonic_function(interpolation_laplacian, args.b, args.crosswires, interpolation_level, dirichlet) interpolation_harmonic_function = shared.display_harmonic_function(interpolation_potentials, interpolation_coordinates, interpolation_grid_size, display_type='grid') ''' '''potentials = compute_harmonic_function(laplacian, args.b, args.crosswires, args.level)''' '''