forked from nikiitin/RING-5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize.R
executable file
·61 lines (53 loc) · 1.79 KB
/
normalize.R
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
#!/usr/bin/Rscript
library(readr)
source("util.R")
# Parse arguments
arguments = commandArgs(trailingOnly = TRUE)
currArg <- 1
statsFile <- arguments[currArg]
currArg <- increment(currArg)
normalize <- arguments[currArg]
currArg <- increment(currArg)
sdNorm <- arguments[currArg]
currArg <- increment(currArg)
# Until here all arguments are fixed
if (normalize == "False") {
stop("Normalize is not set, skipping this step")
}
nStats <- arguments[currArg]
currArg <- increment(currArg)
stats <- NULL
for (stat in 1:nStats) {
stats <- c(stats, arguments[currArg])
currArg <- increment(currArg)
}
# Finish argument parsing
parsed_data <- read.table(statsFile, sep = " ", header=TRUE)
# Normalize data
if (normalize == "True") {
# Create the sd name
# Create new row (sum of all stacked variables)
parsed_data["total"] <- 0
for (stat in stats) {
parsed_data["total"] <- parsed_data["total"] + parsed_data[stat]
}
for (bench in unique(parsed_data[,"benchmark_name"])){
dataToNorm <- parsed_data[parsed_data["benchmark_name"] == bench,]
# It is already ordered, take first element
normalizer <- dataToNorm[1,]
# Apply normalization
for (i in 1:length(dataToNorm[,1])) {
for (stat in stats) {
stat.sd <- paste("sd", stat, sep=".")
parsed_data[parsed_data["benchmark_name"] == bench & parsed_data["confName"] == as.character(dataToNorm[i, "confName"]),stat] <-
dataToNorm[i,stat] / normalizer["total"]
if (sdNorm == "True") {
parsed_data[parsed_data["benchmark_name"] == bench & parsed_data["confName"] == as.character(dataToNorm[i, "confName"]),stat.sd] <-
dataToNorm[i,stat.sd] / normalizer[stat]
}
}
}
}
}
# Write data onto csv file
write.table(parsed_data, statsFile, sep=" ", row.names = F)