示例#1
0
 def __init__(self):
     # config
     self.cfg = config.Configuration()
     # ROC params
     self.__truePos = 0
     self.__falsePos = 0
     self.__trueNeg = 0
     self.__falseNeg = 0
     self.__rec = []  # recall
     self.__far = []  # false alarm rate
示例#2
0
    def __init__(self):
        cfg = config.Configuration()
        self.mlp = MLP(cfg.mlp_n_in, cfg.mlp_n_out)
        self.n_epochs = cfg.mlp_n_epochs
        self.patience = cfg.mlp_patience
        self.learning_rate = cfg.mlp_learning_rate
        self.batch_size = cfg.mlp_batch_size
        self.l2_reg = cfg.mlp_l2_reg
        self.improvement_threshold = cfg.mlp_improvement_threshold
        self.patience_increase = cfg.mlp_patience_increase

        # load data
        dataset = 'mnist.pkl.gz'
        datasets = load_data(dataset)

        self.train_set_x, self.train_set_y = datasets[0]
        self.valid_set_x, self.valid_set_y = datasets[1]
        self.test_set_x, self.test_set_y = datasets[2]
示例#3
0
    def __init__(self, n_in, n_out):

        self.cfg = config.Configuration()
        self.n_class = n_out
        self.W = np.zeros((n_in, n_out), dtype=np.float)
        self.b = np.zeros((n_out, ), dtype=np.float)
        self.learning_rate = self.cfg.lr_learning_rate
        self.n_epochs = self.cfg.lr_n_epoch
        self.batch_size = self.cfg.lr_batch_size

        # compute p_y given x
        self.p_y_given_x = None
        self.exp_x_multiply_w_plus_b = None

        # gradient_w_b
        self.delta_W = 0
        self.delta_b = 0

        # train
        self.patience = self.cfg.lr_patience
        self.patience_increase = self.cfg.lr_patience_increase
        self.improvement_threshold = self.cfg.lr_improvement_threshold
        self.lamda = self.cfg.lr_weight_decay_lamda

        # data set
        self.train_set_x = None
        self.train_set_y = None
        self.valid_set_x = None
        self.valid_set_y = None
        self.test_set_x = None
        self.test_set_y = None

        # params
        self.is_weight_decay = self.cfg.lr_weight_decay
        self.is_line_search = self.cfg.lr_line_search
        self.is_momentum = self.cfg.is_momentum
        self.momentum_vW = 0
        self.momentum_vb = 0

        # line search test
        self.num_test_epoch = 200
        self.test_result = np.zeros((self.num_test_epoch + 1, 4),
                                    dtype=np.float32)
示例#4
0
        plt.legend(loc='upper right')
        plt.show()

    def printEval(self):
        print("Threshold = {:.2f}".format(self.__classifier.getThreshold()))
        print("True Positive = {:}".format(self.__truePos))
        print("False Negtive = {:}".format(self.__falseNeg))
        print("True Negtive = {:}".format(self.__trueNeg))
        print("False Positive = {:}".format(self.__falsePos))

        self.__calculate()
        print("Accuracy = {:.2f}%".format(self.accuracy))
        print("Precision = {:.2f}%".format(self.precision))
        print("Recall = {:.2f}%".format(self.recall))
        print("False alarm rate = {:.2f}%".format(self.falseAlarmRate))
        print()


if __name__ == '__main__':
    cfg = config.Configuration()
    if cfg.task == 'train':

        ########## train the classifier ############
        ###### neg as center
        classifier = Classifier(cfg)

        ########## testROC ############################
        myTest = TestROC(cfg)
        myTest.setClassifier(classifier)
        myTest.compute()
        myTest.draw()