continue source = dh.preProcessSamplesCyTOFData(source) # De-noising the source. denoiseSource = dae.predictDAE(source, DAE, denoise) denoiseSource, _ = dh.standard_scale(denoiseSource, preprocessor=preprocessor) # Predict the cell type of the source. print('Run the classifier on source ', str(sourceIndex), 'without calibration') start = time.time() acc[i, 0], F1[i, 0], predLabel = net.prediction(denoiseSource, mode, i, cellClassifier) end = time.time() print(end - start) if not os.path.isdir(os.path.dirname(fname)): os.mkdir(os.path.dirname(fname)) np.savetxt(fname, predLabel, delimiter=',', fmt='%i') ''' sourceInds = np.random.randint(low=0, high=source.X.shape[0], size=1000) targetInds = np.random.randint(low=0, high=target.X.shape[0], size=1000) mmd_before[i] = K.eval(cf.MMD(denoiseSource.X, denoiseTarget.X).cost( K.variable(value=denoiseSource.X[sourceInds]), K.variable(value=denoiseTarget.X[targetInds])) ) # f = open(dataPath + "/predlabel_nocal" + str(sourceIndex) + ".csv", 'w') # for item in predLabel:
sourceIndex = testIndex[i] source = dh.loadDeepCyTOFData(dataPath, sourceIndex, relevantMarkers, mode) if choice!=5: source = dh.preProcessSamplesCyTOFData(source) # De-noising the source. denoiseSource = dae.predictDAE(source, DAE, denoise) denoiseSource, _ = dh.standard_scale(denoiseSource, preprocessor = preprocessor) # Predict the cell type of the source. print('Run the classifier on source ', str(sourceIndex), 'without calibration') start = tm.time() acc[i,0], F1[i,0], predLabel = net.prediction(denoiseSource, mode, i, cellClassifier) Testing_time[i,0] = tm.time()-start sourceInds = np.random.randint(low=0, high = source.X.shape[0], size = 1000) targetInds = np.random.randint(low=0, high = target.X.shape[0], size = 1000) mmd_before[i] = K.eval(cf.MMD(denoiseSource.X, denoiseTarget.X).cost( K.variable(value=denoiseSource.X[sourceInds]), K.variable(value=denoiseTarget.X[targetInds]))) print('MMD before: ', str(mmd_before[i])) if isCalibrate: if loadModel: calibMMDNet = mmd.loadModel(denoiseTarget, denoiseSource, sourceIndex, predLabel, dataSet[choice]) calibrateSource = Sample(calibMMDNet.predict(denoiseSource.X), denoiseSource.y) calibMMDNet = None
# Pre-process sample. print('Pre-process sample ', str(i + 1)) sample = dh.preProcessSamplesCyTOFData(sample) sample, preprocessor = dh.standard_scale(sample, preprocessor=None) # Split data into training and testing. print('Split data into training and testing.') trainSample, testSample = dh.splitData(sample, test_size=.75) # Train a feed-forward neural net classifier on the training data. print('Train a feed-forward neural net classifier on the training data.') classifier = net.trainClassifier(trainSample, dataSet[choice], i, hiddenLayersSizes, activation=activation, l2_penalty=l2_penalty) # Run the classifier on the testing data. print('Run the classifier on the testing data.') acc[i - 1], F1[i - 1], _ = net.prediction(testSample, dataSet[choice], i, classifier) ''' Output the overall results. ''' CI = np.zeros(10000) for i in range(10000): CI[i] = np.mean(np.random.choice(F1, size=30)) CI = np.sort(CI) print(dataSet[choice], ', ', np.mean(CI), ' (', CI[250], CI[9750], ')')