-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_imposters_analysis.R
More file actions
152 lines (101 loc) · 5.29 KB
/
Copy path04_imposters_analysis.R
File metadata and controls
152 lines (101 loc) · 5.29 KB
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
### Imposters_analysis
library(stylo)
methods_combination <- read.csv("Methods_combination_parallel.csv", stringsAsFactors = F)
load(paste("Preprocessed_dataset_", methods_combination$unit[1], ".RData", sep = ""))
args <- commandArgs(trailingOnly=TRUE)
args_split <- unlist(strsplit(args, " "))
start_loop <- as.numeric(args_split[1])
end_loop <- as.numeric(args_split[2])
validation_rounds <- as.numeric(args_split[3])
filename <- paste("Final_results_", methods_combination$unit[1], "_", start_loop, ".csv", sep = "")
### 0. Functions
# new minmax function
dist.minmaxfast = function(x){
# test if the input dataset is acceptable
if(is.matrix(x) == FALSE & is.data.frame(x) == FALSE) {
stop("cannot apply a distance measure: wrong data format!")
}
# then, test whether the number of rows and cols is >1
if(length(x[1,]) < 2 | length(x[,1]) < 2) {
stop("at least 2 cols and 2 rows are needed to compute a distance!")
}
# getting the size of the input table
rows = length(x[,1])
# starting a new matrix
y = matrix(nrow = rows, ncol = rows)
rownames(y) = rownames(x)
colnames(y) = rownames(x)
# iterating over rows and columns
for(i in 1:rows) {
for(j in i:rows ) {
y[j,i] = 1 - sum(pmin(x[i,], x[j,])) / sum(pmax(x[i,], x[j,]))
}
}
# converting the matrix to the class 'dist'
y = as.dist(y)
return(y)
}
### 1. First phase: testing
full_results <- data.frame()
for(method in start_loop:end_loop){
# cat("\n######\n######\n###### Configuration", method, "\n\n")
# cat("\n######\n######\n Right author\n\n")
for(candidate_id in unique(full_corpus_metadata$candidate_id)){
# cat("\n######\n no.", candidate_id, "\n\n")
available_corpora <- which(full_corpus_metadata$analysis_type == "verifications" &
full_corpus_metadata$impostors == methods_combination$n_imposters[method] &
full_corpus_metadata$candidate_id == candidate_id)
for(validation in 1:validation_rounds){
# select random text
selected_id <- sample(available_corpora, 1)
# load preprocessed dataset
data <- full_corpus_list[[selected_id]]
# culling
data <- perform.culling(data, culling.level = methods_combination$culling[method])
if(dim(data)[2] > methods_combination$MFU[method])
data <- data[,1:methods_combination$MFU[method]]
# apply the imposters
imposters_results <- imposters(reference.set = data[-c(1,2),], test = data[1,], candidate.set = data[2,], distance = methods_combination$distance[method])
# save incrementally
full_results <- rbind(full_results, data.frame(configuration = methods_combination$configuration[method], repetition = ((candidate_id-1)*validation_rounds)+validation, analysis_type = "green", value = imposters_results))
}
}
# cat("\n######\n######\n Wrong author\n\n")
for(candidate_id in unique(full_corpus_metadata$candidate_id)){
# cat("\n######\n no.", candidate_id, "\n\n")
available_corpora <- which(full_corpus_metadata$analysis_type == "convalidations" &
full_corpus_metadata$impostors == methods_combination$n_imposters[method] &
full_corpus_metadata$candidate_id == candidate_id)
for(validation in 1:validation_rounds){
# select random text
selected_id <- sample(available_corpora, 1)
# load preprocessed dataset
data <- full_corpus_list[[selected_id]]
# culling
data <- perform.culling(data, culling.level = methods_combination$culling[method])
if(dim(data)[2] > methods_combination$MFU[method])
data <- data[,1:methods_combination$MFU[method]]
# apply the imposters
imposters_results <- imposters(reference.set = data[-c(1,2),], test = data[1,], candidate.set = data[2,], distance = methods_combination$distance[method])
# save incrementally
full_results <- rbind(full_results, data.frame(configuration = methods_combination$configuration[method], repetition = ((candidate_id-1)*validation_rounds)+validation, analysis_type = "red", value = imposters_results))
}
}
# cat("\n######\n######\n Actual analysis\n\n")
available_corpus <- which(full_corpus_metadata$analysis_type == "actual" &
full_corpus_metadata$impostors == methods_combination$n_imposters[method])
for(validation in 1:validation_rounds){
# load preprocessed dataset
data <- full_corpus_list[[available_corpus]]
# culling
data <- perform.culling(data, culling.level = methods_combination$culling[method])
if(dim(data)[2] > methods_combination$MFU[method])
data <- data[,1:methods_combination$MFU[method]]
# apply the imposters
imposters_results <- imposters(reference.set = data[-c(1,2),], test = data[1,], candidate.set = data[2,], distance = methods_combination$distance[method])
# save incrementally
full_results <- rbind(full_results, data.frame(configuration = methods_combination$configuration[method], repetition = validation, analysis_type = "actual", value = imposters_results))
}
# Save results incrementally
write.csv(full_results, file = filename, row.names = F)
}