def test_level_up_nested_increase_number_of_edges(self): matrix = AcocMatrix(self.data) old_edge_count = len(matrix.edges) if self.show: plotter.plot_matrix_and_data(matrix, matrix.data, show=True) matrix.level_up() if self.show: plotter.plot_matrix_and_data(matrix, matrix.data, show=True) new_edge_count = len(matrix.edges) self.assertGreater(new_edge_count, old_edge_count)
def test_level_up_nested_increase_number_of_vertices_by_10_in_other_data_set(self): self.data = np.array([[0, 0, 0], [0, 0, 1], [3, 3, 0], [3, 3, 1]]) matrix = AcocMatrix(self.data) old_vertex_count = len(matrix.vertices) if self.show: plotter.plot_matrix_and_data(matrix, matrix.data, show=True) matrix.level_up() if self.show: plotter.plot_matrix_and_data(matrix, matrix.data, show=True) new_vertex_count = len(matrix.vertices) self.assertEqual(new_vertex_count - old_vertex_count, 10)
def test_level_up_nested_increase_number_of_vertices_by_10_in_other_data_set( self): self.data = np.array([[0, 0, 0], [0, 0, 1], [3, 3, 0], [3, 3, 1]]) matrix = AcocMatrix(self.data) old_vertex_count = len(matrix.vertices) if self.show: plotter.plot_matrix_and_data(matrix, matrix.data, show=True) matrix.level_up() if self.show: plotter.plot_matrix_and_data(matrix, matrix.data, show=True) new_vertex_count = len(matrix.vertices) self.assertEqual(new_vertex_count - old_vertex_count, 10)
def test_increase_section_granularity_preserves_pheromones_on_new_edges(self): matrix = AcocMatrix(self.data) start_vertex = matrix.vertices[0] up_edge = start_vertex.connected_edges[DIRECTION['UP']] strength = 10 up_edge.pheromone_strength = strength matrix.level_up(best_polygon=[up_edge]) new_edge = start_vertex.connected_edges[DIRECTION['UP']] if self.show: plotter.plot_matrix_and_data(matrix, matrix.data, show=True) self.assertNotEqual(up_edge, new_edge, 'New matrix edge is equal to the old matrix edge. Should be shorter.') self.assertEqual(new_edge.pheromone_strength, strength) next_new_edge = new_edge.b.connected_edges[DIRECTION['UP']] self.assertEqual(next_new_edge.pheromone_strength, strength)
def test_increase_section_granularity_preserves_pheromones_on_new_edges( self): matrix = AcocMatrix(self.data) start_vertex = matrix.vertices[0] up_edge = start_vertex.connected_edges[DIRECTION['UP']] strength = 10 up_edge.pheromone_strength = strength matrix.level_up(best_polygon=[up_edge]) new_edge = start_vertex.connected_edges[DIRECTION['UP']] if self.show: plotter.plot_matrix_and_data(matrix, matrix.data, show=True) self.assertNotEqual( up_edge, new_edge, 'New matrix edge is equal to the old matrix edge. Should be shorter.' ) self.assertEqual(new_edge.pheromone_strength, strength) next_new_edge = new_edge.b.connected_edges[DIRECTION['UP']] self.assertEqual(next_new_edge.pheromone_strength, strength)
data_set = data_manager.load_data_set('breast_cancer') data = data_set.data[:, :2] target = np.array([data_set.target]).T np.place(target, target == 4, 1) np.place(target, target == 2, 0) dt = np.concatenate((data, target), axis=1) # dt = np.array([[0, 0.02, 0], # [0.05, 0, 1], # [1, 1, 1]]) mtrx = AcocMatrix(dt) pol = mtrx.edges[:4] mtrx.edges[1].pheromone_strength = 5 mtrx.edges[0].pheromone_strength = 3 save_folder = generate_folder_name() print("Level {}: Edges {}, vertices {}".format(mtrx.level, len(mtrx.edges), len(mtrx.vertices))) if plot: # plot_pheromones(mtrx, dt, tau_min=1, tau_max=10, folder_name=save_folder, save=save, show=show) plot_matrix_and_data(mtrx, dt, show=show) for i in range(6): mtrx.level_up(pol) print("Level {}: Edges {}, vertices {}".format(mtrx.level, len(mtrx.edges), len(mtrx.vertices))) if plot: plot_matrix_and_data(mtrx, dt, show=show, save=save) # plot_pheromones(mtrx, dt, tau_min=1, tau_max=10, folder_name=save_folder, save=save, show=show)
plot = True save = True show = False data_set = data_manager.load_data_set('breast_cancer') data = data_set.data[:, :2] target = np.array([data_set.target]).T np.place(target, target == 4, 1) np.place(target, target == 2, 0) dt = np.concatenate((data, target), axis=1) # dt = np.array([[0, 0.02, 0], # [0.05, 0, 1], # [1, 1, 1]]) mtrx = AcocMatrix(dt) pol = mtrx.edges[:4] mtrx.edges[1].pheromone_strength = 5 mtrx.edges[0].pheromone_strength = 3 save_folder = generate_folder_name() print("Level {}: Edges {}, vertices {}".format(mtrx.level, len(mtrx.edges), len(mtrx.vertices))) if plot: # plot_pheromones(mtrx, dt, tau_min=1, tau_max=10, folder_name=save_folder, save=save, show=show) plot_matrix_and_data(mtrx, dt, show=show) for i in range(6): mtrx.level_up(pol) print("Level {}: Edges {}, vertices {}".format(mtrx.level, len(mtrx.edges), len(mtrx.vertices))) if plot: plot_matrix_and_data(mtrx, dt, show=show, save=save) # plot_pheromones(mtrx, dt, tau_min=1, tau_max=10, folder_name=save_folder, save=save, show=show)