install.packages("rjson")
library("rjson")
ps <- "{"sequential": {"with_rp": {"rt_s": 1336.32, "rt_b": 11.33, "value": 6102.387, "n_s": 16}, "without_rp": {"rt_s": 11816.64, "rt_b": 121.18, "value": 6096.285, "n_s": 14}}, "data": {"lengths": [2205, 2205], "names": ["../data/PS1.txt", "../data/PS2.txt"], "dimensions": [2, 2]}, "parallel": {"with_rp": {"rt_s": 43.2, "rt_b": 11.36, "value": 6102.387, "n_s": 16}, "without_rp": {"rt_s": 546.56, "rt_b": 120.62, "value": 6096.285, "n_s": 14}}}"
ps <- '{"sequential": {"with_rp": {"rt_s": 1336.32, "rt_b": 11.33, "value": 6102.387, "n_s": 16}, "without_rp": {"rt_s": 11816.64, "rt_b": 121.18, "value": 6096.285, "n_s": 14}}, "data": {"lengths": [2205, 2205], "names": ["../data/PS1.txt", "../data/PS2.txt"], "dimensions": [2, 2]}, "parallel": {"with_rp": {"rt_s": 43.2, "rt_b": 11.36, "value": 6102.387, "n_s": 16}, "without_rp": {"rt_s": 546.56, "rt_b": 120.62, "value": 6096.285, "n_s": 14}}}'
ps
json_data <- fromJSON(ps, collapse=""))
json_data <- fromJSON(ps)
View(json_data)
View(json_data)
json_data.data
json_data['sequential']
json_data_frame <- as.data.frame(json_data)
View(json_data_frame)
View(json_data_frame)
json_data <- fromJSON(paste(readLines(), collapse=""))
library("rjson")
library("rstudioapi")
library("ggpubr")
library("tidyverse")
current_path = rstudioapi::getActiveDocumentContext()$path
setwd(dirname(current_path))
files <- list.files("./simplex")
frame <- data.frame(name=c(), epsilon=c(), value=c(), time=c(), algo=c(),
dimensions=c(), points=c(), searches=c(), newdim=c(), method=c())
frame2 <- data.frame(name=c(), value=c(), value_rp=c(), time=c(), method=c(), eps=c())
for (file in files) {
print(file)
json_data <- fromJSON(file=paste(getwd(), "/simplex/", file, sep=""))
json_data_frame <- as.data.frame(json_data)
datanames <- paste(json_data_frame[1, "data.names"], json_data_frame[2, "data.names"])
eps <- json_data_frame[1, "data.epsilon"]
methodtime <- json_data_frame[1, "data.methodtime"]
method <- json_data_frame[1, "data.method"]
number_points <- c(json_data_frame[1, "data.lengths"], json_data_frame[2, "data.lengths"])
number_dimensions <- c(json_data_frame[1, "data.dimensions"], json_data_frame[2, "data.dimensions"])
values <- list(json_data_frame[1, "rp.value"],
json_data_frame[1, "nrp.value"])
times_searches <- list(json_data_frame[1, "rp.rt_s"],
json_data_frame[1, "nrp.rt_s"])
times_bounds <- list(json_data_frame[1, "rp.rt_b"],
json_data_frame[1, "nrp.rt_b"])
number_searches <- list(json_data_frame[1, "rp.n_s"],
json_data_frame[1, "nrp.n_s"])
newdim <- ceiling(2 * 1/(eps*eps) * log(number_points[[1]]+number_points[[2]]))
#data <- list(datanames, values, times_searches, number_searches, times_bounds, eps)
key <- paste(datanames, eps)
print(paste("found data:", key))
#frame <- rbind(frame, data.frame(name=datanames, eps=0, value=values[[1]],
#                                 value_rp=values[[2]], time_s=times_searches[[1]]/60,
#                                 time_b=times_bounds[[1]]/60,
#                                 searches=number_searches[[1]],
#                                 algo="parallel",
#                                 dimensions=number_dimensions,
#                                 points=number_points, newdim=number_dimensions[[1]]))
frame <- rbind(frame, data.frame(name=datanames, eps=eps, value=values[[2]],
value_rp=values[[1]], time_s=times_searches[[2]]/60,
time_b=times_bounds[[2]]/60,
searches=number_searches[[2]],
algo="parallel_rp",
dimensions=number_dimensions,
points=number_points, newdim=newdim, method=method))
frame2 <- rbind(frame2, data.frame(name=datanames, value=values[[2]], value_rp=values[[1]],
time=methodtime, method=method, eps=eps, newdim=newdim))
}
data <- frame2 %>%
group_by_at(vars(method, eps)) %>%
mutate(epsilon=paste(eps, " (", newdim, ")", sep="")) %>%
mutate(deviation=abs(1-value/value_rp)) #%>%
#filter(method == "jl")
count <- data %>%
summarise(n = n())
dataj <- data %>% filter(method == "jl")
datap <- data %>% filter(method =="pca")
ggplot(data, aes(deviation, time, color=method, shape=epsilon)) +
#labs(subtitle = "PCA vs. JL") +
theme(legend.position = c(0.72, 0.695),
legend.background = element_rect(fill=alpha('blue', 0.0))) +
scale_x_continuous(name = "empirical epsilon") +
scale_y_continuous(name = "running-time [s]") +
#scale_fill_brewer(palette = "Set1") +
geom_point(size=3, alpha=0.75) +
#geom_point(data=datap, aes(deviation, time, color=factor(epsilon)), shape = 24) +
theme(text = element_text(size=20)) +
scale_shape_discrete(name="input epsilon (corr. #dimensions)")
#ggarrange(pv12, pv13, pv14, pv24, pv25, pv26,
#          pv36, pv45, pvs, ncol = 3, nrow = 3, common.legend = TRUE)
library("rjson")
library("rstudioapi")
library("ggpubr")
library("tidyverse")
current_path = rstudioapi::getActiveDocumentContext()$path
setwd(dirname(current_path))
files <- list.files("./additive")
frame <- data.frame(eps=c(), value=c(), dimensions=c(), gamma=c())
for (file in files) {
print(file)
json_data <- fromJSON(file=paste(getwd(), "/additive/", file, sep=""))
json_data_frame <- as.data.frame(json_data)
eps <- json_data_frame[1, "data.epsilon"]
gamma <- json_data_frame[1, "data.gamma"]
dimensions <- json_data_frame[1, "data.dimensions"]
value <- json_data_frame[1, "rp.value"]
frame <- rbind(frame, data.frame(eps=eps,value=value,dimensions=dimensions[[1]],gamma=gamma))
}
realvalue = sqrt(5)
data <- frame %>%
group_by_at(vars(eps, gamma)) %>%
mutate(hasadditive=abs(realvalue-value)-eps*realvalue > 0)
data_a <- data %>%
filter(hasadditive == T)
data_a2 <- data_a %>% filter(value > 0)
count <- data %>%
summarise(n = n())
count_a <- data_a %>%
summarise(m = n())
count_add <- count %>%
left_join(count_a)
count_add[is.na(count_add)] <- 0
data2 <- data %>%
left_join(count) %>%
left_join(count_a) %>%
mutate(additive = realvalue/value-1) %>%
mutate(slack = abs(realvalue-value)-eps*realvalue) %>%
mutate(epsilon = paste(eps, " (", dimensions, ")", sep = ""))
ggplot(data2, aes(factor(gamma), additive)) +
scale_x_discrete(name="alpha") +
scale_y_continuous(name="empirical epsilon") +
geom_boxplot(aes(color = factor(epsilon)), outlier.alpha=0.5) +
scale_color_discrete(name="input epsilon (corr. #dimensions)") +
theme(legend.position = c(0.275, 0.75),
legend.background = element_rect(fill=alpha('blue', 0.0))) +
theme(text = element_text(size=20), axis.text.x = element_text(angle=45, hjust = 1))
#ggplot(count_add, aes(factor(gamma), m/n)) +
#  #ggtitle(paste("Distortion")) +
#  geom_boxplot(aes(color=factor(eps))) +
#  scale_x_discrete(name="alpha") +
#  scale_y_continuous(limits=c(0,1), name="measured probability of additive error") +
#  scale_color_discrete(name = "input epsilon") +
#  theme(legend.position = c(0.1, 0.75))
library("rjson")
library("rstudioapi")
library("ggpubr")
library("tidyverse")
current_path = rstudioapi::getActiveDocumentContext()$path
setwd(dirname(current_path))
files <- list.files("./pressure")
frame <- data.frame(name=c(), eps=c(), value=c(), value_rp=c(), time=c(), algorithm=c(),
dimensions=c(), points=c(), searches_s=c(),
searches_p=c(), searches_s_rp=c(), searches_p_rp=c(), newdim=c())
for (file in files) {
print(file)
json_data <- fromJSON(file=paste(getwd(), "/pressure/", file, sep=""))
json_data_frame <- as.data.frame(json_data)
method <- json_data_frame[1, "data.method"]
datanames <- paste(json_data_frame[1, "data.names"], "/",substr(json_data_frame[2, "data.names"], 3, 3), sep="")
eps <- json_data_frame[1, "data.epsilon"]
number_points <- c(json_data_frame[1, "data.lengths"], json_data_frame[2, "data.lengths"])
number_dimensions <- c(json_data_frame[1, "data.dimensions"], json_data_frame[2, "data.dimensions"])
values <- list(json_data_frame[1, "sequential.without_rp.value"],
json_data_frame[1, "sequential.with_rp.value"])
times_searches <- list(json_data_frame[1, "sequential.without_rp.rt_s"],
json_data_frame[1, "sequential.with_rp.rt_s"],
json_data_frame[1, "parallel.without_rp.rt_s"],
json_data_frame[1, "parallel.with_rp.rt_s"])
times_bounds <- list(json_data_frame[1, "sequential.without_rp.rt_b"],
json_data_frame[1, "sequential.with_rp.rt_b"],
json_data_frame[1, "parallel.without_rp.rt_b"],
json_data_frame[1, "parallel.with_rp.rt_b"])
number_searches <- list(json_data_frame[1, "sequential.without_rp.n_s"],
json_data_frame[1, "sequential.with_rp.n_s"],
json_data_frame[1, "parallel.without_rp.n_s"],
json_data_frame[1, "parallel.with_rp.n_s"])
newdim <- ceiling(2 * 1/(eps*eps) * log(number_points[[1]]+number_points[[2]]))
data <- list(datanames, values, times_searches, number_searches, times_bounds, eps)
key <- paste(datanames, eps)
print(paste("found data:", key))
frame <- rbind(frame, data.frame(name=datanames, eps=0, value=values[[1]],
value_rp=values[[2]], time_s=times_searches[[1]]/60,
time_b=times_bounds[[1]]/60,
searches=number_searches[[1]],
algorithm="sequential",
dimensions=number_dimensions,
points=number_points, newdim=number_dimensions[[1]]))
frame <- rbind(frame, data.frame(name=datanames, eps=eps, value=values[[1]],
value_rp=values[[2]], time_s=times_searches[[2]]/60,
time_b=times_bounds[[2]]/60,
searches=number_searches[[2]],
algorithm="sequential_rp",
dimensions=number_dimensions,
points=number_points, newdim=newdim))
frame <- rbind(frame, data.frame(name=datanames, eps=0, value=values[[1]],
value_rp=values[[2]], time_s=times_searches[[3]]/60,
time_b=times_bounds[[3]]/60,
searches=number_searches[[3]],
algorithm="parallel",
dimensions=number_dimensions,
points=number_points, newdim=number_dimensions[[1]]))
frame <- rbind(frame, data.frame(name=datanames, eps=eps, value=values[[1]],
value_rp=values[[2]], time_s=times_searches[[4]]/60,
time_b=times_bounds[[4]]/60,
searches=number_searches[[4]],
algorithm="parallel_rp",
dimensions=number_dimensions,
points=number_points, newdim=newdim))
}
files <- list.files("./simplex")
cc <- 0
for (file in files) {
json_data <- fromJSON(file=paste(getwd(), "/simplex/", file, sep=""))
json_data_frame <- as.data.frame(json_data)
method <- json_data_frame[1, "data.method"]
if (method == "jl") {
datanames <- paste(json_data_frame[1, "data.names"], json_data_frame[2, "data.names"])
eps <- json_data_frame[1, "data.epsilon"]
methodtime <- json_data_frame[1, "data.methodtime"]
method <- json_data_frame[1, "data.method"]
number_points <- c(json_data_frame[1, "data.lengths"], json_data_frame[2, "data.lengths"])
number_dimensions <- c(json_data_frame[1, "data.dimensions"], json_data_frame[2, "data.dimensions"])
values <- list(json_data_frame[1, "rp.value"],
json_data_frame[1, "nrp.value"])
times_searches <- list(json_data_frame[1, "rp.rt_s"],
json_data_frame[1, "nrp.rt_s"])
times_bounds <- list(json_data_frame[1, "rp.rt_b"],
json_data_frame[1, "nrp.rt_b"])
number_searches <- list(json_data_frame[1, "rp.n_s"],
json_data_frame[1, "nrp.n_s"])
newdim <- ceiling(2 * 1/(eps*eps) * log(number_points[[1]]+number_points[[2]]))
#data <- list(datanames, values, times_searches, number_searches, times_bounds, eps)
key <- paste(datanames, eps)
print(paste("found data:", key))
#frame <- rbind(frame, data.frame(name=datanames, eps=0, value=values[[1]],
#                                 value_rp=values[[2]], time_s=times_searches[[1]]/60,
#                                 time_b=times_bounds[[1]]/60,
#                                 searches=number_searches[[1]],
#                                 algo="parallel",
#                                 dimensions=number_dimensions,
#                                 points=number_points, newdim=number_dimensions[[1]]))
frame <- rbind(frame, data.frame(name="rand. simpl.", eps=eps, value=values[[2]],
value_rp=values[[1]], time_s=times_searches[[2]]/60,
time_b=times_bounds[[2]]/60,
searches=number_searches[[2]],
algorithm="parallel_rp",
dimensions=number_dimensions,
points=number_points, newdim=newdim))
cc <- cc + 1
}
}
data <- frame %>%
group_by_at(vars(name, eps, newdim)) %>%
mutate(time = time_s + time_b) %>%
mutate(deviation = abs(1 - value_rp / value)) %>%
mutate(epsilon=paste(eps, " (", newdim, ")", sep="")) %>%
filter(eps == 0 | eps >= 0.25)
data2 <- data %>% filter(epsilon >= 0.25) %>% mutate(data=name)
data3 <- data #%>% filter(name != "random simplex")
ggplot(data3, aes(factor(epsilon), time/60)) +
scale_x_discrete(name = "input epsilon (corr. #dimensions)") +
scale_y_continuous(trans = "log10", name = "running-time [h]") +
theme(legend.position = c(0.81, 0.8),
legend.direction = "vertical",
legend.background = element_rect(fill=alpha('blue', 0.0))) +
geom_boxplot(aes(color = algorithm), outlier.alpha = 0.5) +
theme(text = element_text(size=20))+ annotation_logticks(sides="l")
ggplot(data2, aes(factor(epsilon), deviation)) +
geom_boxplot(aes(color = data), outlier.alpha=0.5) +
scale_color_discrete(name="") +
scale_x_discrete(name = "input epsilon (corr. #dimensions)") +
scale_y_continuous(name = "empirical epsilon") +
theme(legend.position = c(0.325, 0.875),
legend.background = element_rect(fill=alpha('blue', 0.0)),
legend.direction = "horizontal") + theme(text = element_text(size=20))
