def transform2(self, test_data, mode=None): if self.norm == True: t_data = self.normalizer.norm(test_data) else: t_data = test_data if mode == None: mode = self.mode if mode == 'v1': similarity_result = SCCI.get_MD( t_data, self.node_mean, self.node_sigma) pred_table = np.zeros([len(test_data), self.num_classes]) for i, sim_result in enumerate(similarity_result): pred_cls = sim_result.argmax() pred = self.node_to_class_dict[pred_cls] pred_table[i][pred] = 1 else: boundary = 0.0 SCCI_enhance.set_alpha(self.alpha) node_output = SCCI_enhance.get_MD( t_data, self.node_mean, self.node_sigma) node_output = np.append(node_output, np.ones( (np.size(node_output, 0), 1)), axis=1) target_output = np.matmul(node_output, self.weights) pred_table = self.matrix2Binary(target_output, boundary) ylabel = [] for i in pred_table: ylabel.append(i.argmax()) ylabel = np.array(ylabel) return ylabel
def train(self, train_data, train_label): self.data = self.preprocess_data(train_data, train_label) self.tar_matrix = self.target2matrix(train_label, self.num_classes) self.get_hidden_nodes(self.data, train_label) SCCI_enhance.set_alpha(self.alpha) node_output = SCCI_enhance.get_MD( self.data, self.node_mean, self.node_sigma) self.node_output = np.append(node_output, np.ones( (np.size(node_output, 0), 1), dtype=float), axis=1) if self.mode == 'v1': pass elif self.mode == 'v2': self.get_network_weights(self.node_output, self.tar_matrix) class_output = np.matmul(self.node_output, self.weights) self.error.append(self.error_estimate( class_output, self.tar_matrix)) elif self.mode == 'v4': self.get_network_weights(self.node_output, self.tar_matrix) class_output = np.matmul(self.node_output, self.weights) self.error.append(self.error_estimate( class_output, self.tar_matrix)) # Check train result pred_table = self.matrix2Binary(class_output) self.train_target = self.target2matrix( train_label, self.num_classes, neg_note=0) self.error_train.append( 1 - accuracy_score(pred_table, self.train_target))
threshold = 0.55 sigma_init = 0.2 alpha = math.sqrt(2) beta = 2 learning_rate = 1 lambda_i = 0 tra_label = RBF_ISCC.target2matrix(Y_train, 2, neg_note=0) rbf_iscc = RBF_ISCC_update_once(threshold=threshold, sigma_init=sigma_init, alpha=alpha, beta=beta, lambda_i=lambda_i, learning_rate=learning_rate, mode='v4', norm=False) rbf_iscc.train(X_train, Y_train) w = rbf_iscc.weights SCCI_enhance.set_alpha(alpha) node_output = SCCI_enhance.get_MD( X_train, rbf_iscc.node_mean, rbf_iscc.node_sigma) node_output = np.append(node_output, np.ones( (np.size(node_output, 0), 1), dtype=float), axis=1) cls_output = np.matmul(node_output, rbf_iscc.weights) pred_label_tr = rbf_iscc.transform(X_train) score_tr = performance_measure(pred_label_tr, tra_label) error_tr = [1 - score_tr["AACC"]] flag = 0 end_flag = 1 if error_tr[-1] == 0: flag = end_flag while flag < end_flag: