-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput3modClass.txt
executable file
·437 lines (418 loc) · 15.5 KB
/
output3modClass.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> load("/research/rgs01/home/clusterHome/qtran/Semisupervised_Learning/label_data_x.RData")
> load("/research/rgs01/home/clusterHome/qtran/Semisupervised_Learning/class_label_data_y.RData")
> source("/research/rgs01/home/clusterHome/qtran/Semisupervised_Learning/Rscripts/supporting_functions.R")
> source("/research/rgs01/home/clusterHome/qtran/Semisupervised_Learning/Rscripts/predictOneNN.R")
> ###Use 70% of the Capper Reference for training
> ##first get the index of the labeled data
> acc = data.frame("Train_function" = "", "Learner"="", "Seed" = "", "Ind_ACC"="", "Trans_ACC" = "")
> main_dir = "/research/rgs01/home/clusterHome/qtran/Semisupervised_Learning_big_private_data"
> #main_dir = "/Volumes/qtran/Semisupervised_Learning_big_private_data/"
>
>
> library(caret)
> library(ssc)
> library(kernlab)
> create_class_score_output = function(pred_label, pred_score, truth_label){
+ output = data.frame(pred_label)
+ output$Sample = names(truth_label)
+ output$pred_score = apply(pred_score, 1, max)
+ output$truth_label = truth_label
+
+ return(output)
+ }
>
> seeds = c(1, 2, 20, 40, 80, 160, 320)
>
> for (s in seeds){
+ print(paste0("Start with seed = ", s))
+
+ sub_dir = paste0("seed", s, "_all")
+ output_tbl_dir <- file.path(main_dir, "processed_data/class_results", sub_dir)
+ output_fig_dir <- file.path(main_dir, "figures/class_results", sub_dir)
+ if (!dir.exists(output_tbl_dir)){
+ dir.create(output_tbl_dir)
+ } else {
+ print("Table Dir already exists!")
+ }
+ if (! dir.exists(output_fig_dir)){
+ dir.create(output_fig_dir)
+ } else {
+ print("Figure Dir already exists!")
+ }
+
+
+ load(paste0(main_dir, "/processed_data/class_results/seed", s, "_alldata_sets.RData"))
+
+ tra.idx = x$tra.idx
+
+ #tra.idx = get_sample_n_rows_idx(label_data_x, label_data_y, n=nums$min_class, replace=FALSE)
+ ####make train, test data sets#######
+ xtrain = NULL
+ ytrain = NULL
+ xtrain <- x$xtrain
+ ytrain <- x$ytrain
+
+ ###Use 50% of train instances as unlabeled set
+ tra.na.idx <- x$tra.na.idx
+ ytrain[tra.na.idx] <- NA
+
+ #Use the other 30% of instances for inductive test
+
+ xitest <- x$xitest # test instances
+ yitest <- x$yitest # classes of instances in xitest
+
+ # Use the unlabeled examples for transductive test
+ xttest <- x$xttest # transductive test instances
+ yttest <- x$yttest # classes of instances in xttest
+
+ #############base line supervised learning classifier SVM##########
+
+ ################ computing distance and kernel matrices
+ dtrain <- as.matrix(proxy::dist(x = xtrain, method = "euclidean", by_rows = TRUE))
+ ditest <- as.matrix(proxy::dist(x = xitest, y = xtrain, method = "euclidean", by_rows = TRUE))
+ dttest <- as.matrix(proxy::dist(x = xttest, y = xtrain, method = "euclidean", by_rows = TRUE))
+ ###Set up learner parameters
+ learner <- e1071::svm
+ learner.pars <- list(type = "C-classification", kernel="radial",
+ probability = TRUE, scale = TRUE)
+ pred <- function(m, x){
+ r <- predict(m, x, probability = TRUE)
+ prob <- attr(r, "probabilities")
+ return(prob)
+ }
+
+ #Training from a set of distances with 1-NN as base classifier
+ set.seed(3)
+ m.selft1 <- selfTraining(x = dtrain, y = ytrain, x.inst = FALSE,
+ learner = oneNN,
+ pred = "predict",
+ pred.pars = list(type = "prob", distance.weighting = "none"))
+
+ #Training with learning based on nearest neighbor rule and cut edges
+ set.seed(3)
+ m.snnrce <- snnrce(x = xtrain, y = ytrain, dist = "Euclidean")
+
+ ###Training with SElf-TRaining with EDiting. SETRED uses an amending scheme to avoid the introduction of noisy examples into the enlarged labeled set.
+ #For each iteration, the mislabeled examples are identified using the local information provided by the neighborhood graph.
+ set.seed(3)
+ m.setred <- setred(x = dtrain, y = ytrain, x.inst=FALSE,
+ learner = ssc::oneNN, pred = "predict",
+ pred.pars = list(type = "prob", distance.weighting = "none"))
+
+ ####Prediction###3
+ m = list(m.selft1, m.setred, m.snnrce)
+ names(m) = c("m.selft1", "m.setred", "m.snnrce")
+ rlist::list.save(m, file = paste0(output_tbl_dir, 'models_selft_setred_snnrce_1NN.RData'))
+
+ j = 0
+ i_label_data = as.data.frame(yitest)
+ colnames(i_label_data) = "TRUTH"
+ t_label_data = as.data.frame(yttest)
+ colnames(t_label_data) = "TRUTH"
+
+ source("/rgs01/home/clusterHome/qtran/Semisupervised_Learning/Rscripts/predict_setred_prob.R")
+ for (i in m){
+ trainer = attr(i, 'class')
+ learner = attr(i$model, 'class')
+ if (is.null(learner)){
+ learner = j + 1
+ }
+
+ ###perform prediction
+ ipred = get_inductive_pred(i, test_x=xitest, test_y=yitest, train_x=xtrain)
+ transpred = get_trans_pred(i, train_x = xtrain, trans_y=yttest, tra.na.idx)
+ ###create confusion matrices
+ iconM = createConfusionMatrix(ipred, yitest, mode = "everything")
+ transconM = createConfusionMatrix(transpred, yttest, mode="everything")
+
+ write.csv(iconM$byClass, file=paste0(output_tbl_dir,"/Inductive_metrics_", trainer, "_", learner, ".csv"))
+ write.csv(transconM$byClass, file=paste0(output_tbl_dir, "/Transductive_metrics_", trainer, "_", learner, ".csv"))
+
+ ####plot confusion matrices
+ iPT = create_plotTable(iconM)
+ plot_CM(iPT, filename = paste0(output_fig_dir, "/Inductive_", trainer, "_", learner, ".pdf"))
+ pPT = create_plotTable(transconM)
+ plot_CM(pPT, filename = paste0(output_fig_dir, "/Transductive_", trainer, "_", learner, ".pdf"))
+
+ ###accuracy
+ acc = rbind(acc, c(trainer, learner, s, iconM$overall[1], transconM$overall[1]))
+ write.csv(acc, file =paste0(output_tbl_dir, "/ACC_ALL_SELFT_SNNRCE_1NN.csv"))
+
+ ###get predicted labels
+ j = j + 1
+ i_label_data = cbind(i_label_data, createLabelData(rownames(xitest), ipred)$class)
+ colnames(i_label_data)[j+1] = paste0(trainer, "_", learner)
+ t_label_data = cbind(t_label_data, createLabelData(rownames(xttest), transpred)$class)
+ colnames(t_label_data)[j+1] = paste0(trainer, "_", learner)
+
+
+ ###get predicted probabilities
+ print(paste("j=",j))
+ #
+ if(trainer =="selfTraining" || trainer =="snnrce" || trainer =="setred"){
+ ipred_score = predProb.OneNN(i, ditest[, i$instances.index])
+ rownames(ipred_score) = rownames(ditest)
+ tpred_score = predProb.OneNN(i, dttest[, i$instances.index])
+ rownames(tpred_score) = rownames(dttest)
+ write.csv(ipred_score, file=paste0(output_tbl_dir,"/Inductive_scores_", trainer, "_", learner, ".csv"), row.names=TRUE)
+ write.csv(tpred_score, file = paste0(output_tbl_dir,"/Transductive_scores_", trainer, "_", learner, ".csv"), row.names=TRUE)
+
+ ioutscores = create_class_score_output(ipred, ipred_score, yitest)
+ toutscores = create_class_score_output(transpred, tpred_score, yttest)
+ write.csv(ioutscores, file=paste0(output_tbl_dir,"/Inductive_MaxScores_", trainer, "_", learner, ".csv"), row.names=TRUE)
+ write.csv(toutscores, file = paste0(output_tbl_dir,"/Transductive_MaxScores_", trainer, "_", learner, ".csv"), row.names=TRUE)
+ }
+ }
+ #write.csv(acc, file =paste0(output_tbl_dir, "/ACC_SELFT.csv"))
+ write.csv(i_label_data, file=paste0(output_tbl_dir, "/Inductive_predicted_SELFT_SNNRCE_SETRED_labels.csv"), row.names=TRUE)
+ write.csv(t_label_data, file=paste0(output_tbl_dir, "/Transductive_predicted_SELFT_SNNRCE_SETRED_labels.csv"), row.names=TRUE)
+
+ print(paste0("Complete run for seed = ", s))
+ }
[1] "Start with seed = 1"
[1] "Table Dir already exists!"
[1] "Figure Dir already exists!"
[1] "Inductive testing for selfTraining using OneNN"
[1] "Transductive testing for selfTraining using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 1"
[1] "Inductive testing for setred using OneNN"
[1] "Transductive testing for setred using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 2"
[1] "Inductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Transductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 3"
[1] "Complete run for seed = 1"
[1] "Start with seed = 2"
[1] "Table Dir already exists!"
[1] "Figure Dir already exists!"
[1] "Inductive testing for selfTraining using OneNN"
[1] "Transductive testing for selfTraining using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 1"
[1] "Inductive testing for setred using OneNN"
[1] "Transductive testing for setred using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 2"
[1] "Inductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Transductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 3"
[1] "Complete run for seed = 2"
[1] "Start with seed = 20"
[1] "Table Dir already exists!"
[1] "Figure Dir already exists!"
[1] "Inductive testing for selfTraining using OneNN"
[1] "Transductive testing for selfTraining using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 1"
[1] "Inductive testing for setred using OneNN"
[1] "Transductive testing for setred using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 2"
[1] "Inductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Transductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 3"
[1] "Complete run for seed = 20"
[1] "Start with seed = 40"
[1] "Table Dir already exists!"
[1] "Figure Dir already exists!"
[1] "Inductive testing for selfTraining using OneNN"
[1] "Transductive testing for selfTraining using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 1"
[1] "Inductive testing for setred using OneNN"
[1] "Transductive testing for setred using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 2"
[1] "Inductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Transductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 3"
[1] "Complete run for seed = 40"
[1] "Start with seed = 80"
[1] "Table Dir already exists!"
[1] "Figure Dir already exists!"
[1] "Inductive testing for selfTraining using OneNN"
[1] "Transductive testing for selfTraining using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 1"
[1] "Inductive testing for setred using OneNN"
[1] "Transductive testing for setred using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 2"
[1] "Inductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Transductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 3"
[1] "Complete run for seed = 80"
[1] "Start with seed = 160"
[1] "Table Dir already exists!"
[1] "Figure Dir already exists!"
[1] "Inductive testing for selfTraining using OneNN"
[1] "Transductive testing for selfTraining using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 1"
[1] "Inductive testing for setred using OneNN"
[1] "Transductive testing for setred using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 2"
[1] "Inductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Transductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 3"
[1] "Complete run for seed = 160"
[1] "Start with seed = 320"
[1] "Table Dir already exists!"
[1] "Figure Dir already exists!"
[1] "Inductive testing for selfTraining using OneNN"
[1] "Transductive testing for selfTraining using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 1"
[1] "Inductive testing for setred using OneNN"
[1] "Transductive testing for setred using OneNN"
[1] "dtrain"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 2"
[1] "Inductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Transductive testing for snnrce using OneNN"
[1] "SNNRCE"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "Create table for plotting"
[1] "Plot CM"
[1] "j= 3"
[1] "Complete run for seed = 320"
>
------------------------------------------------------------
Sender: LSF System <lsfadmin@noderome159>
Subject: Job 157310123: <threemod_class> in cluster <hpcf_research_cluster> Done
Job <threemod_class> was submitted from host <splprhpc05> by user <qtran> in cluster <hpcf_research_cluster> at Thu Apr 14 13:29:54 2022
Job was executed on host(s) <noderome159>, in queue <standard>, as user <qtran> in cluster <hpcf_research_cluster> at Thu Apr 14 13:29:56 2022
</home/qtran> was used as the home directory.
</home/qtran> was used as the working directory.
Started at Thu Apr 14 13:29:56 2022
Terminated at Thu Apr 14 16:04:28 2022
Results reported at Thu Apr 14 16:04:28 2022
Your job looked like:
------------------------------------------------------------
# LSBATCH: User input
R --vanilla < /research/rgs01/home/clusterHome/qtran/Semisupervised_Learning/Rscripts/run_SELFT_SNNRCE_SETRED_1NN_subclass.R
------------------------------------------------------------
Successfully completed.
Resource usage summary:
CPU time : 9245.85 sec.
Max Memory : 1241 MB
Average Memory : 1032.11 MB
Total Requested Memory : 16382.00 MB
Delta Memory : 15141.00 MB
Max Swap : -
Max Processes : 6
Max Threads : 7
Run time : 9268 sec.
Turnaround time : 9274 sec.
The output (if any) is above this job summary.
PS:
Read file </research/rgs01/home/clusterHome/qtran/Semisupervised_Learning/error3modsClass.txt> for stderr output of this job.