コード例 #1
0
ファイル: main.py プロジェクト: breeze101792/neural_network
    def __init__(self):
        self.nnetwork = None
        self.dimension = 2
        self.train_mode = True
        #self.data = []
        self.weights = []
        self.class_table = {}
        self.find_best = False
        #self.class_num
        self.dataset = dp()
        self.training_set = []
        self.testing_set = []
        self.traning_trainsformed_data = []
        self.testing_trainsformed_data = []
        #log info
        self.nninfo = info()

        #wait for ui setup
        Gtk.Window.__init__(self, title="Neural Network")
        self.set_default_size(800, 700)

        action_group = Gtk.ActionGroup("my_actions")

        #menu item
        self.add_file_menu_actions(action_group)
        self.add_about_menu_actions(action_group)

        #create ui manager
        uimanager = self.create_ui_manager()
        uimanager.insert_action_group(action_group)

        menubar = uimanager.get_widget("/MenuBar")

        main_ui = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(main_ui)
        main_ui.pack_start(menubar, False, False, 0)

        toolbar = uimanager.get_widget("/ToolBar")
        main_ui.pack_start(toolbar, False, False, 0)

        # body pannel settings
        body_panel = Gtk.Table(2, 3, True)
        main_ui.pack_start(body_panel, True, True, 0)

        #for testing/*********************************************************/
        settings_panel = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing = 10)
        body_panel.attach(settings_panel, 0, 1, 0, 2, xpadding=8, ypadding=8)

        settings_lab = Gtk.Label("Settings", xalign=0)
        settings_panel.pack_start(settings_lab, False, False, 0)

        # data settings *******************************************************/
        data_settings_lab = Gtk.Label("Data Settings", xalign=0)
        settings_panel.pack_start(data_settings_lab, False, False, 0)

        # traning_testing_rate_group
        traning_testing_rate_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(traning_testing_rate_group, False, False, 0)
        traning_testing_rate_lab = Gtk.Label("Traning & Tesgting\ndata rate(%):", xalign=0)
        traning_testing_rate_group.attach(traning_testing_rate_lab, 0, 1, 0, 1)
        traning_testing_rate_adj = Gtk.Adjustment(60, 0, 100, 5, 0, 0)
        self.traning_testing_rate_sb = Gtk.SpinButton()
        self.traning_testing_rate_sb.set_alignment(xalign=1)
        self.traning_testing_rate_sb.set_adjustment(traning_testing_rate_adj)
        traning_testing_rate_group.attach(self.traning_testing_rate_sb, 1, 2, 0, 1)
        self.traning_testing_rate_sb.set_value(66)

        # action buttom
        data_action_group = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        settings_panel.pack_start(data_action_group, False, False, 0)

        generate_button = Gtk.Button(label = "generate")
        generate_button.connect("clicked", self.on_clicked_generate)
        data_action_group.pack_start(generate_button, False, False, 0)

        # test_button = Gtk.Button(label = "Test")
        # test_button.connect("clicked", self.on_clicked_test)
        # data_action_group.pack_start(test_button, False, False, 0)

        # network settings*****************************************************
        nn_settings_lab = Gtk.Label("Network Settings", xalign=0)
        settings_panel.pack_start(nn_settings_lab, False, False, 0)

        # learning rate
        learning_rate_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(learning_rate_group, False, False, 0)
        learning_rate_lab = Gtk.Label("Learning rate(0.1):", xalign=0)
        learning_rate_group.attach(learning_rate_lab, 0, 1, 0, 1)
        learning_rate_adj = Gtk.Adjustment(2, 0, 100, 1, 10, 0)
        self.learning_rate_sb = Gtk.SpinButton()
        self.learning_rate_sb.set_alignment(xalign=1)
        self.learning_rate_sb.set_adjustment(learning_rate_adj)
        learning_rate_group.attach(self.learning_rate_sb, 1, 2, 0, 1)
        self.learning_rate_sb.set_value(6)

        # traning times
        training_times_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(training_times_group, False, False, 0)
        training_times_lab = Gtk.Label("Traning times:", xalign=0)
        training_times_group.attach(training_times_lab, 0, 1, 0, 1)
        training_times_adj = Gtk.Adjustment(50, 0, 10000, 20, 0, 0)
        self.training_times_sb = Gtk.SpinButton()
        self.training_times_sb.set_alignment(xalign=1)
        self.training_times_sb.set_adjustment(training_times_adj)
        training_times_group.attach(self.training_times_sb, 1, 2, 0, 1)
        self.training_times_sb.set_value(100)

        # training_err_rate_group
        training_err_rate_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(training_err_rate_group, False, False, 0)
        training_err_rate_lab = Gtk.Label("Traning error rate(%):", xalign=0)
        training_err_rate_group.attach(training_err_rate_lab, 0, 1, 0, 1)
        training_err_rate_adj = Gtk.Adjustment(10, 0, 100, 5, 0, 0)
        self.training_err_rate_sb = Gtk.SpinButton()
        self.training_err_rate_sb.set_alignment(xalign=1)
        self.training_err_rate_sb.set_adjustment(training_err_rate_adj)
        training_err_rate_group.attach(self.training_err_rate_sb, 1, 2, 0, 1)
        self.training_err_rate_sb.set_value(5)



        # mlp structure
        mlp_structure_group = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        settings_panel.pack_start(mlp_structure_group, False, False, 0)
        mlp_structure_lab = Gtk.Label("Specify mlp structure(3,5,1...)", xalign = 0)
        mlp_structure_group.pack_start(mlp_structure_lab, True, True, 0)
        self.mlp_structure_ety = Gtk.Entry()
        self.mlp_structure_ety.set_alignment(xalign=1)
        self.mlp_structure_ety.set_text("2,1")
        mlp_structure_group.pack_start(self.mlp_structure_ety, True, True, 0)


        # action buttom
        action_group = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        settings_panel.pack_start(action_group, False, False, 0)

        tarin_button = Gtk.Button(label = "Train")
        tarin_button.connect("clicked", self.on_clicked_train)
        action_group.pack_start(tarin_button, False, False, 0)

        test_button = Gtk.Button(label = "Test")
        test_button.connect("clicked", self.on_clicked_test)
        action_group.pack_start(test_button, False, False, 0)

        # draw_button = Gtk.Button(label = "draw")
        # draw_button.connect("clicked", self.draw_2dfig())
        # action_group.pack_start(draw_button, False, False, 0)

        # draw_button = Gtk.Button(label = "Draw")
        # draw_button.connect("clicked", self.on_clicked_draw)
        # action_group.pack_start(draw_button, False, False, 0)

        # /*******************************************************************/

        #info*****************************************************************/
        info_panel = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing = 10)
        body_panel.attach(info_panel, 1, 2, 0, 2)

        info_lab = Gtk.Label("Information", xalign=0)
        info_panel.pack_start(info_lab, False, False, 0)

        #data info
        dataset_info_lab = Gtk.Label("#Data Info", xalign=0)
        info_panel.pack_start(dataset_info_lab, False, False, 0)
        dataset_info_group = Gtk.Table(1, 2, False)
        info_panel.pack_start(dataset_info_group, False, False, 0)
        self.dataset_info_title_lab = Gtk.Label("FileName:\nData set size:\nDimension:\nClassification number:", xalign=0, yalign=0)
        dataset_info_group.attach(self.dataset_info_title_lab, 0,1,0,1)
        self.dataset_info_msg_lab = Gtk.Label("", xalign=0, yalign=0)
        dataset_info_group.attach(self.dataset_info_msg_lab, 1,2,0,1)

        #taning log
        traning_log_lab = Gtk.Label("#Traning Log", xalign=0)
        info_panel.pack_start(traning_log_lab, False, False, 0)
        traning_log_group = Gtk.Table(1, 2, False)
        info_panel.pack_start(traning_log_group, False, False, 0)
        self.traning_log_title_lab = Gtk.Label("Accuracy rate:\nTraning set size:\nIteration times:", xalign=0, yalign=0)
        traning_log_group.attach(self.traning_log_title_lab, 0,1,0,1)
        self.traning_log_msg_lab = Gtk.Label("", xalign=0, yalign=0)
        traning_log_group.attach(self.traning_log_msg_lab, 1,2,0,1)

        #testing log
        testing_log_lab = Gtk.Label("#Testing Log", xalign=0, yalign=0)
        info_panel.pack_start(testing_log_lab, False, False, 0)
        testing_log_group = Gtk.Table(1, 2, False)
        info_panel.pack_start(testing_log_group, False, False, 0)
        self.testing_title_log_lab = Gtk.Label("Accuracy rate:\nTesting set size:", xalign=0, yalign=0)
        testing_log_group.attach(self.testing_title_log_lab, 0,1,0,1)
        self.testing_log_msg_lab = Gtk.Label("", xalign=0, yalign=0)
        testing_log_group.attach(self.testing_log_msg_lab, 1,2,0,1)

        ori_draw_panel = Gtk.Box(10, 2, True)
        info_panel.pack_start(ori_draw_panel, True, True, 0)

        self.ori_paper = paper(title="After normalization(data set)")
        ori_draw_panel.pack_start(self.ori_paper.canvas, True, True, 0)

        # *********************************************************************/
        #drawing
        traning_draw_draw_panel = Gtk.Box(10, 2, True)
        body_panel.attach(traning_draw_draw_panel, 2, 3, 0, 1)

        self.traning_draw_paper = paper(title="Traning set")
        traning_draw_draw_panel.pack_start(self.traning_draw_paper.canvas, True, True, 0)
        self.traning_draw_paper.resetpaper()



        testing_draw_draw_panel = Gtk.Box(10, 2, True)
        body_panel.attach(testing_draw_draw_panel, 2, 3, 1, 2)

        self.testing_draw_paper = paper(title="Testing set")
        testing_draw_draw_panel.pack_start(self.testing_draw_paper.canvas, True, True, 0)
        self.testing_draw_paper.resetpaper()

        #post init
        self.log_refresh()
コード例 #2
0
ファイル: smain.py プロジェクト: breeze101792/neural_network
    def __init__(self):
        self.nnetwork = None
        self.dimension = 2
        self.train_mode = True
        #self.data = []
        self.weights = []
        self.class_table = {}
        self.find_best = False
        #self.class_num
        self.dataset = dp()
        self.training_set = []
        self.testing_set = []
        self.traning_trainsformed_data = []
        self.testing_trainsformed_data = []
        #log info
        self.nninfo = info()

        #wait for ui setup
        Gtk.Window.__init__(self, title="Neural Network")
        self.set_default_size(1000, 700)

        action_group = Gtk.ActionGroup("my_actions")

        #menu item
        self.add_file_menu_actions(action_group)
        self.add_about_menu_actions(action_group)

        #create ui manager
        uimanager = self.create_ui_manager()
        uimanager.insert_action_group(action_group)

        menubar = uimanager.get_widget("/MenuBar")

        main_ui = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(main_ui)
        main_ui.pack_start(menubar, False, False, 0)

        toolbar = uimanager.get_widget("/ToolBar")
        main_ui.pack_start(toolbar, False, False, 0)

        # body pannel settings
        body_panel = Gtk.Table(2, 3, True)
        main_ui.pack_start(body_panel, True, True, 0)


        settings_panel = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing = 10)
        body_panel.attach(settings_panel, 0, 1, 0, 2, xpadding=8, ypadding=8)

        settings_lab = Gtk.Label("Settings", xalign=0)
        settings_panel.pack_start(settings_lab, False, False, 0)
        # *********************************************************************
        nn_settings_lab = Gtk.Label("Network Settings", xalign=0)
        settings_panel.pack_start(nn_settings_lab, False, False, 0)

        # net_size_x_group
        net_size_x_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(net_size_x_group, False, False, 0)
        net_size_x_lab = Gtk.Label("Net Size(x):", xalign=0)
        net_size_x_group.attach(net_size_x_lab, 0, 1, 0, 1)
        net_size_x_adj = Gtk.Adjustment(10, 0, 100, 5, 0, 0)
        self.net_size_x_sb = Gtk.SpinButton()
        self.net_size_x_sb.set_alignment(xalign=1)
        self.net_size_x_sb.set_adjustment(net_size_x_adj)
        net_size_x_group.attach(self.net_size_x_sb, 1, 2, 0, 1)
        self.net_size_x_sb.set_value(50)

        # net_size_y_group
        net_size_y_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(net_size_y_group, False, False, 0)
        net_size_y_lab = Gtk.Label("Net Size(y):", xalign=0)
        net_size_y_group.attach(net_size_y_lab, 0, 1, 0, 1)
        net_size_y_adj = Gtk.Adjustment(10, 0, 100, 5, 0, 0)
        self.net_size_y_sb = Gtk.SpinButton()
        self.net_size_y_sb.set_alignment(xalign=1)
        self.net_size_y_sb.set_adjustment(net_size_y_adj)
        net_size_y_group.attach(self.net_size_y_sb, 1, 2, 0, 1)
        self.net_size_y_sb.set_value(50)

        # learning rate
        learning_rate_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(learning_rate_group, False, False, 0)
        learning_rate_lab = Gtk.Label("Learning rate(0.1):", xalign=0)
        learning_rate_group.attach(learning_rate_lab, 0, 1, 0, 1)
        learning_rate_adj = Gtk.Adjustment(2, 0, 100, 1, 10, 0)
        self.learning_rate_sb = Gtk.SpinButton()
        self.learning_rate_sb.set_alignment(xalign=1)
        self.learning_rate_sb.set_adjustment(learning_rate_adj)
        learning_rate_group.attach(self.learning_rate_sb, 1, 2, 0, 1)
        self.learning_rate_sb.set_value(6)

        # traning times
        training_times_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(training_times_group, False, False, 0)
        training_times_lab = Gtk.Label("Traning times:", xalign=0)
        training_times_group.attach(training_times_lab, 0, 1, 0, 1)
        training_times_adj = Gtk.Adjustment(50, 0, 10000, 20, 0, 0)
        self.training_times_sb = Gtk.SpinButton()
        self.training_times_sb.set_alignment(xalign=1)
        self.training_times_sb.set_adjustment(training_times_adj)
        training_times_group.attach(self.training_times_sb, 1, 2, 0, 1)
        self.training_times_sb.set_value(2)

        # standar_diviison_group
        standar_diviison_group = Gtk.Table(1, 2, True)
        settings_panel.pack_start(standar_diviison_group, False, False, 0)
        standar_diviison_lab = Gtk.Label("Standar Division(0.01):", xalign=0)
        standar_diviison_group.attach(standar_diviison_lab, 0, 1, 0, 1)
        standar_diviison_adj = Gtk.Adjustment(10, 0, 100, 5, 0, 0)
        self.standar_diviison_sb = Gtk.SpinButton()
        self.standar_diviison_sb.set_alignment(xalign=1)
        self.standar_diviison_sb.set_adjustment(standar_diviison_adj)
        standar_diviison_group.attach(self.standar_diviison_sb, 1, 2, 0, 1)
        self.standar_diviison_sb.set_value(20)


        # action buttom
        action_group = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        settings_panel.pack_start(action_group, False, False, 0)

        tarin_button = Gtk.Button(label = "Train")
        tarin_button.connect("clicked", self.on_clicked_train)
        action_group.pack_start(tarin_button, False, False, 0)

        abort_button = Gtk.Button(label = "Abort")
        abort_button.connect("clicked", self.on_clicked_abort)
        action_group.pack_start(abort_button, False, False, 0)

        self.ori_draw_panel = Gtk.Box(10, 2, True)
        settings_panel.pack_start(self.ori_draw_panel, True, True, 0)

        self.ori_paper = paper(title="Data set")
        self.ori_draw_panel.pack_start(self.ori_paper.canvas, True, True, 0)


        # *********************************************************************/
        #drawing
        self.traning_draw_panel = Gtk.Box(10, 2, True)
        body_panel.attach(self.traning_draw_panel, 1, 3, 0, 2)

        self.traning_draw_paper = paper(title="SOM")
        self.traning_draw_panel.pack_start(self.traning_draw_paper.canvas, True, True, 0)
        self.traning_draw_paper.resetpaper()

        self.training_set = None
        self.status_flag = [False]