def Process(self, sourcex, sourcey, targetx, targety, subsize): # fixed size windows for source stream and target stream #kpca = KernelPCA(n_components=3, kernel = 'rbf',gamma = 15) #print("sourcex.shape", sourcex.shape) #x_kpca = kpca.fit_transform(sourcex) #print("x_kpca.shape", x_kpca.shape) #sourcex = np.matrix(x_kpca) #y_kpca = kpca.fit_transform(targetx) #targetx = np.matrix(y_kpca) src_size, _ = sourcex.shape tgt_size, _ = targetx.shape #true_label = [] ### get the initial model by using the first source and target windows alpha = 0.5 b = targetx.T.shape[1] fold = 5 sigma_list = Classification.sigma_list(np.array(targetx.T), np.array(sourcex.T)) lambda_list = Classification.lambda_list() srcx_array = np.array(sourcex.T) trgx_array = np.array(targetx.T) #(thetah_old, w, sce_old, sigma_old) = Classification.R_ULSIF(trgx_array, srcx_array, alpha, sigma_list, lambda_list, b, fold) self.Ensemble.generateNewModelRULSIF(targetx, sourcex, sourcey, alpha, sigma_list, lambda_list, b, fold, subsize) # print "update model", src_size, source.shape truelablecount = 0.0 totalcount = 0.0 for i in range(0, len(targety)): #print("targetx[i]", targetx[i]) instanceresult = self.Ensemble.evaluateEnsembleRULSIF(targetx[i]) #print("instanceresult", instanceresult) #print("instanceresult[0]", instanceresult[0]) #print("truelabel[i]", targety[i]) if instanceresult[0] == targety[i]: truelablecount += 1.0 totalcount += 1.0 if i % 100 == 0: print("truelabelcount", truelablecount) print("totalcount", totalcount) print("tmp acc", truelablecount / totalcount) with open('accuracynormgroup3datafilegame0726.csv', 'a+') as f: writer = csv.writer(f) writer.writerow([ len(targety), truelablecount, totalcount, truelablecount / totalcount ])
def Process(self, sourcex: np.matrix, sourcey: List[int], targetx: np.matrix, targety: List[int], subsize: int) -> None: # fixed size windows for source stream and target stream # kpca = KernelPCA(n_components=3, kernel = 'rbf',gamma = 15) # x_kpca = kpca.fit_transform(sourcex) # sourcex = np.matrix(x_kpca) # y_kpca = kpca.fit_transform(targetx) # targetx = np.matrix(y_kpca) src_size, _ = sourcex.shape tgt_size, _ = targetx.shape # get the initial model by using the first source and target windows alpha = 0.5 b = targetx.T.shape[1] fold = 5 sigma_list = Classification.sigma_list(np.array(targetx.T), np.array(sourcex.T)) lambda_list = Classification.lambda_list() # srcx_array = np.array(sourcex.T) # trgx_array = np.array(targetx.T) # (thetah_old, w, sce_old, sigma_old) = Classification.R_ULSIF(trgx_array, srcx_array, alpha, sigma_list, lambda_list, b, fold) # todo self.Ensemble.generateNewModelRULSIF(targetx, sourcex, sourcey, alpha, sigma_list, lambda_list, b, fold, subsize) # test model trueLableCount = 0.0 totalCount = 0.0 for i in range(0, len(targety)): instanceResult = self.Ensemble.evaluateEnsembleRULSIF(targetx[i]) if instanceResult[0] == targety[i]: trueLableCount += 1.0 totalCount += 1.0 if i % 100 == 0: print("test size", i) print("true label count", trueLableCount) print("total count", totalCount) print("tmp acc", trueLableCount / totalCount) # write result to file with open('output/accuracy_norm15group1player.csv', 'a+') as f: writer = csv.writer(f) writer.writerow([ len(targety), trueLableCount, totalCount, trueLableCount / totalCount ])