Chart consistency + visual cleanup
This commit is contained in:
+36
-10
@@ -1,8 +1,11 @@
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(readr)
|
||||
library(stringr)
|
||||
|
||||
# Usage: Rscript combined_comparison.r exp_abspath1 exp_abspath2 ... [resultsdata_file]
|
||||
# One coordinate system per base experiment (facet); c/aot/interp variants
|
||||
# share each facet, coloured by variant.
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
if (length(args) < 1) {
|
||||
@@ -20,17 +23,36 @@ exp_args <- if (grepl("\\.csv$", args[length(args)])) {
|
||||
args
|
||||
}
|
||||
|
||||
extract_info <- function(path) {
|
||||
dir_name <- basename(path)
|
||||
match <- str_match(
|
||||
dir_name,
|
||||
"^\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}_(.+?)_(c|aot|interp)_"
|
||||
)
|
||||
if (is.na(match[1, 1])) {
|
||||
warning(paste("Could not parse:", dir_name))
|
||||
return(NULL)
|
||||
}
|
||||
list(base_name = match[1, 2], variant = match[1, 3], path = path)
|
||||
}
|
||||
|
||||
all_data <- data.frame()
|
||||
|
||||
for (arg in exp_args) {
|
||||
csv_file <- file.path(arg, csv_suffix)
|
||||
info <- extract_info(arg)
|
||||
if (is.null(info)) {
|
||||
next
|
||||
}
|
||||
|
||||
csv_file <- file.path(info$path, csv_suffix)
|
||||
if (!file.exists(csv_file)) {
|
||||
warning(paste("Missing:", csv_file))
|
||||
next
|
||||
}
|
||||
|
||||
df <- read_csv(csv_file, col_types = cols())
|
||||
df$experiment <- basename(arg)
|
||||
df$base_name <- info$base_name
|
||||
df$variant <- info$variant
|
||||
all_data <- bind_rows(all_data, df)
|
||||
}
|
||||
|
||||
@@ -39,7 +61,7 @@ if (nrow(all_data) == 0) {
|
||||
}
|
||||
|
||||
totals <- all_data |>
|
||||
group_by(experiment, resulttype) |>
|
||||
group_by(base_name, variant, resulttype) |>
|
||||
summarise(faults = sum(faults, na.rm = TRUE), .groups = "drop") |>
|
||||
ungroup()
|
||||
|
||||
@@ -57,21 +79,25 @@ totals$resulttype <- factor(totals$resulttype, levels = marker_order)
|
||||
|
||||
plot <- ggplot(
|
||||
totals,
|
||||
aes(x = resulttype, y = faults, colour = experiment, group = experiment)
|
||||
aes(x = resulttype, y = faults, colour = variant, group = variant)
|
||||
) +
|
||||
geom_point(size = 2) +
|
||||
geom_line() +
|
||||
facet_wrap(~base_name) +
|
||||
scale_y_log10() +
|
||||
labs(
|
||||
x = "Marker",
|
||||
y = "Faults",
|
||||
title = "Combined Comparison",
|
||||
color = "Experiment"
|
||||
x = "Fault Type",
|
||||
y = "Fault Count",
|
||||
title = "Fault Count Comparison",
|
||||
color = "Variant"
|
||||
) +
|
||||
theme_minimal() +
|
||||
theme(axis.text.x = element_text(angle = 45, hjust = 1))
|
||||
theme(
|
||||
axis.text.x = element_text(angle = 90, hjust = 1),
|
||||
plot.title = element_text(size = 14, face = "bold")
|
||||
)
|
||||
|
||||
suffix <- gsub("^resultsdata|\\.csv$", "", csv_suffix)
|
||||
outfile <- paste0("injections/combined_comparison", suffix, ".svg")
|
||||
outfile <- paste0("injections/fault_count_comparison", suffix, ".svg")
|
||||
ggsave(outfile, plot = plot, width = 12, height = 6)
|
||||
print(paste("Saved", outfile))
|
||||
+38
-32
@@ -4,8 +4,8 @@ library(readr)
|
||||
library(stringr)
|
||||
library(tidyr)
|
||||
|
||||
# Usage: Rscript ratio_correlation.r exp_abspath1 exp_abspath2 ... [resultsdata_file]
|
||||
# Plots correlation between aot/c and interp/c ratios
|
||||
# Usage: Rscript combined_fault_correlation.r exp_abspath1 exp_abspath2 ... [resultsdata_file]
|
||||
# Plots correlation between raw aot and interp fault counts (no C baseline).
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
if (length(args) < 2) {
|
||||
@@ -69,48 +69,52 @@ all_data <- all_data |>
|
||||
group_by(base_name, variant, benchmark, resulttype) |>
|
||||
summarise(faults = sum(faults), .groups = "drop")
|
||||
|
||||
baseline <- all_data |> filter(variant == "c")
|
||||
comparisons <- all_data |> filter(variant != "c")
|
||||
# Only aot/interp matter; C is not used as a baseline here.
|
||||
counts <- all_data |> filter(variant %in% c("aot", "interp"))
|
||||
|
||||
ratios <- comparisons |>
|
||||
left_join(
|
||||
baseline |> select(base_name, benchmark, resulttype, faults),
|
||||
by = c("base_name", "benchmark", "resulttype"),
|
||||
suffix = c("", "_baseline")
|
||||
) |>
|
||||
filter(!is.na(faults_baseline), faults_baseline > 0) |>
|
||||
mutate(ratio = faults / faults_baseline)
|
||||
|
||||
if (nrow(ratios) == 0) {
|
||||
stop("No ratios computed (missing baseline or zero values)")
|
||||
}
|
||||
|
||||
# Pivot to get aot and interp ratios side by side
|
||||
ratio_wide <- ratios |>
|
||||
select(base_name, benchmark, resulttype, variant, ratio) |>
|
||||
pivot_wider(names_from = variant, values_from = ratio) |>
|
||||
# Pivot to get aot and interp fault counts side by side
|
||||
counts_wide <- counts |>
|
||||
select(base_name, benchmark, resulttype, variant, faults) |>
|
||||
pivot_wider(names_from = variant, values_from = faults) |>
|
||||
filter(!is.na(aot), !is.na(interp))
|
||||
|
||||
if (nrow(ratio_wide) == 0) {
|
||||
stop("No paired aot/interp ratios found")
|
||||
if (nrow(counts_wide) == 0) {
|
||||
stop("No paired aot/interp fault counts found")
|
||||
}
|
||||
|
||||
# Compute correlation
|
||||
cor_result <- cor(ratio_wide$aot, ratio_wide$interp, method = "pearson")
|
||||
cat(sprintf("Pearson correlation: %.4f\n", cor_result))
|
||||
cor_raw <- cor(counts_wide$aot, counts_wide$interp, method = "pearson")
|
||||
cor_log <- cor(
|
||||
log10(counts_wide$aot),
|
||||
log10(counts_wide$interp),
|
||||
method = "pearson"
|
||||
)
|
||||
cat(sprintf("Pearson correlation (raw): %.4f\n", cor_raw))
|
||||
cat(sprintf("Pearson correlation (log10): %.4f\n", cor_log))
|
||||
|
||||
# Create plot
|
||||
plot <- ggplot(
|
||||
ratio_wide,
|
||||
counts_wide,
|
||||
aes(x = aot, y = interp, color = base_name, shape = resulttype)
|
||||
) +
|
||||
# geom_abline(
|
||||
# slope = 1,
|
||||
# intercept = 0,
|
||||
# colour = "grey70",
|
||||
# linetype = "dotted"
|
||||
# ) +
|
||||
geom_point(size = 3, alpha = 0.7) +
|
||||
scale_x_log10(name = "AOT / C Ratio") +
|
||||
scale_y_log10(name = "Interpreter / C Ratio") +
|
||||
scale_x_log10(name = "AOT Fault Count") +
|
||||
scale_y_log10(name = "Interpreter Fault Count") +
|
||||
labs(
|
||||
title = sprintf("Ratio Correlation (r = %.4f)", cor_result),
|
||||
# title = sprintf(
|
||||
# "Fault Count Correlation (r_raw = %.4f, r_log = %.4f)",
|
||||
# cor_raw,
|
||||
# cor_log
|
||||
# ),
|
||||
title = "Fault Count Correlation",
|
||||
color = "Experiment",
|
||||
shape = "Marker"
|
||||
shape = "Fault Type"
|
||||
) +
|
||||
theme_minimal() +
|
||||
theme(
|
||||
@@ -118,5 +122,7 @@ plot <- ggplot(
|
||||
plot.title = element_text(size = 14, face = "bold")
|
||||
)
|
||||
|
||||
ggsave("injections/ratio_correlation.svg", plot = plot, width = 10, height = 8)
|
||||
print("Saved ratio_correlation.svg")
|
||||
suffix <- gsub("^resultsdata|\\.csv$", "", csv_suffix)
|
||||
outfile <- paste0("injections/fault_count_correlation", suffix, ".svg")
|
||||
ggsave(outfile, plot = plot, width = 10, height = 8)
|
||||
print(paste("Saved", outfile))
|
||||
@@ -0,0 +1,92 @@
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(readr)
|
||||
|
||||
# Usage: Rscript combined_fault_rates.r exp_abspath1 exp_abspath2 ... [faults_file]
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
if (length(args) < 1) {
|
||||
stop("Need at least 1 experiment")
|
||||
}
|
||||
|
||||
csv_suffix <- if (grepl("\\.csv$", args[length(args)])) {
|
||||
args[length(args)]
|
||||
} else {
|
||||
"faults.csv"
|
||||
}
|
||||
exp_args <- if (grepl("\\.csv$", args[length(args)])) {
|
||||
args[-length(args)]
|
||||
} else {
|
||||
args
|
||||
}
|
||||
|
||||
# Faults / instruction count, per experiment
|
||||
rates <- data.frame()
|
||||
|
||||
for (arg in exp_args) {
|
||||
faults_file <- file.path(arg, csv_suffix)
|
||||
mnem_file <- file.path(arg, "mnemonics.csv")
|
||||
|
||||
if (!file.exists(faults_file)) {
|
||||
warning(paste("Missing:", faults_file))
|
||||
next
|
||||
}
|
||||
if (!file.exists(mnem_file)) {
|
||||
warning(paste("Missing:", mnem_file))
|
||||
next
|
||||
}
|
||||
|
||||
df <- read_csv(faults_file, col_types = cols())
|
||||
mdf <- read_csv(mnem_file, col_types = cols())
|
||||
|
||||
total_faults <- df |>
|
||||
filter(resulttype != "OK_MARKER") |>
|
||||
summarise(faults = sum(faults, na.rm = TRUE)) |>
|
||||
pull(faults)
|
||||
|
||||
total_instrs <- sum(mdf$count, na.rm = TRUE)
|
||||
|
||||
if (is.na(total_instrs) || total_instrs == 0) {
|
||||
warning(paste("Zero instruction count for", arg))
|
||||
next
|
||||
}
|
||||
|
||||
rates <- bind_rows(
|
||||
rates,
|
||||
data.frame(
|
||||
experiment = basename(arg),
|
||||
fault_rate = total_faults / total_instrs
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (nrow(rates) == 0) {
|
||||
stop("No data loaded")
|
||||
}
|
||||
|
||||
# Order by fault rate
|
||||
rates <- rates |>
|
||||
arrange(desc(fault_rate)) |>
|
||||
mutate(experiment = factor(experiment, levels = experiment))
|
||||
|
||||
plot <- ggplot(
|
||||
rates,
|
||||
aes(x = experiment, y = fault_rate, fill = experiment)
|
||||
) +
|
||||
geom_col() +
|
||||
labs(
|
||||
title = "Fault Rate per Instruction",
|
||||
x = "Experiment",
|
||||
y = "Faults / Instruction Count"
|
||||
) +
|
||||
theme_minimal() +
|
||||
theme(
|
||||
axis.text.x = element_text(angle = 90, hjust = 1),
|
||||
legend.position = "none",
|
||||
plot.title = element_text(size = 14, face = "bold")
|
||||
)
|
||||
|
||||
suffix <- gsub("^faults|\\.csv$", "", csv_suffix)
|
||||
outfile <- paste0("injections/fault_rates_per_instruction", suffix, ".svg")
|
||||
ggsave(outfile, plot = plot, width = 12, height = 6)
|
||||
print(paste("Saved", outfile))
|
||||
@@ -110,14 +110,15 @@ plot <- ggplot(
|
||||
vjust = -0.8,
|
||||
check_overlap = TRUE
|
||||
) +
|
||||
scale_x_log10(name = "Instruction Execution Frequency") +
|
||||
scale_y_log10(name = "Failure-Marker Occurrences") +
|
||||
scale_x_log10(name = "Instruction Executions") +
|
||||
scale_y_log10(name = "Fault Count") +
|
||||
labs(
|
||||
title = sprintf(
|
||||
"Instruction / Fault Correlation (r_raw = %.4f, r_log = %.4f)",
|
||||
cor_raw,
|
||||
cor_log
|
||||
),
|
||||
# title = sprintf(
|
||||
# "Instruction / Fault Correlation (r_raw = %.4f, r_log = %.4f)",
|
||||
# cor_raw,
|
||||
# cor_log
|
||||
# ),
|
||||
title = "Instruction / Fault Correlation",
|
||||
colour = "Mnemonic"
|
||||
) +
|
||||
theme_minimal() +
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(readr)
|
||||
library(viridisLite)
|
||||
|
||||
# Usage: Rscript combined_instr_fault_correlation_heatmap.r exp_abspath1 ... [faults_file]
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
if (length(args) < 1) {
|
||||
stop("Need at least 1 experiment")
|
||||
}
|
||||
|
||||
csv_suffix <- if (grepl("\\.csv$", args[length(args)])) {
|
||||
args[length(args)]
|
||||
} else {
|
||||
"faults.csv"
|
||||
}
|
||||
exp_args <- if (grepl("\\.csv$", args[length(args)])) {
|
||||
args[-length(args)]
|
||||
} else {
|
||||
args
|
||||
}
|
||||
|
||||
all_data <- data.frame()
|
||||
all_mnem <- data.frame()
|
||||
|
||||
for (arg in exp_args) {
|
||||
csv_file <- file.path(arg, csv_suffix)
|
||||
if (!file.exists(csv_file)) {
|
||||
warning(paste("Missing:", csv_file))
|
||||
next
|
||||
}
|
||||
|
||||
df <- read_csv(csv_file, col_types = cols())
|
||||
df$experiment <- basename(arg)
|
||||
all_data <- bind_rows(all_data, df)
|
||||
|
||||
# TODO: This is ignoring any filters currently
|
||||
mnem_file <- file.path(arg, "mnemonics.csv")
|
||||
if (!file.exists(mnem_file)) {
|
||||
warning(paste("Missing:", mnem_file))
|
||||
next
|
||||
}
|
||||
mdf <- read_csv(mnem_file, col_types = cols())
|
||||
all_mnem <- bind_rows(all_mnem, mdf)
|
||||
}
|
||||
|
||||
if (nrow(all_data) == 0) {
|
||||
stop("No faults.csv data loaded")
|
||||
}
|
||||
|
||||
if (nrow(all_mnem) == 0) {
|
||||
stop("No mnemonics.csv data loaded")
|
||||
}
|
||||
|
||||
# no OK_MARKER, sum GROUP1 + TRAP.
|
||||
all_data <- all_data |>
|
||||
filter(!is.na(mnemonic), mnemonic != "NULL") |>
|
||||
filter(resulttype != "OK_MARKER") |>
|
||||
mutate(
|
||||
resulttype = ifelse(resulttype == "GROUP1_MARKER", "TRAP", resulttype)
|
||||
)
|
||||
|
||||
if (nrow(all_data) == 0) {
|
||||
stop("No failure-marker data to plot")
|
||||
}
|
||||
|
||||
# Sum faults per (mnemonic, marker) pair for all experiments
|
||||
heat <- all_data |>
|
||||
group_by(mnemonic, resulttype) |>
|
||||
summarise(faults = sum(faults, na.rm = TRUE), .groups = "drop")
|
||||
|
||||
# Sum mnemonic counts for all experiments
|
||||
mnem_counts <- all_mnem |>
|
||||
filter(!is.na(mnemonic), mnemonic != "NULL") |>
|
||||
group_by(mnemonic) |>
|
||||
summarise(count = sum(count, na.rm = TRUE), .groups = "drop")
|
||||
|
||||
# Normalize by mnemonic count
|
||||
heat <- heat |>
|
||||
left_join(mnem_counts, by = "mnemonic") |>
|
||||
filter(!is.na(count), count > 0) |>
|
||||
mutate(fault_rate = faults / count)
|
||||
|
||||
if (nrow(heat) == 0) {
|
||||
stop("Heat join failed")
|
||||
}
|
||||
|
||||
# Order by fault rate
|
||||
mnem_order <- heat |>
|
||||
group_by(mnemonic) |>
|
||||
summarise(total = sum(fault_rate), .groups = "drop") |>
|
||||
arrange(desc(total)) |>
|
||||
pull(mnemonic)
|
||||
|
||||
heat <- heat |>
|
||||
mutate(mnemonic = factor(mnemonic, levels = mnem_order))
|
||||
|
||||
plot <- ggplot(
|
||||
heat,
|
||||
aes(x = mnemonic, y = resulttype, fill = fault_rate)
|
||||
) +
|
||||
geom_tile(colour = "white") +
|
||||
scale_fill_viridis_c(name = "Fault rate", trans = "log10") +
|
||||
labs(
|
||||
title = "Instruction / Fault Rate Heatmap (Normalized)",
|
||||
x = "Instruction",
|
||||
y = "Fault Type"
|
||||
) +
|
||||
theme_minimal() +
|
||||
theme(
|
||||
axis.text.x = element_text(angle = 90, hjust = 1),
|
||||
panel.grid = element_blank(),
|
||||
plot.title = element_text(size = 14, face = "bold")
|
||||
)
|
||||
|
||||
suffix <- gsub("^faults|\\.csv$", "", csv_suffix)
|
||||
outfile <- paste0("injections/instr_fault_rate_heatmap", suffix, ".svg")
|
||||
ggsave(outfile, plot = plot, width = 12, height = 6)
|
||||
print(paste("Saved", outfile))
|
||||
@@ -83,12 +83,18 @@ plot <- ggplot(
|
||||
) +
|
||||
geom_point(size = 2) +
|
||||
geom_line() +
|
||||
facet_wrap(~base_name, scales = "free_x") +
|
||||
facet_wrap(~base_name) +
|
||||
scale_y_log10(name = "Ratio (to C)") +
|
||||
scale_x_discrete(name = "Marker") +
|
||||
labs(color = "Variant") +
|
||||
scale_x_discrete(name = "Fault Type") +
|
||||
labs(
|
||||
title = "Fault Count Ratios",
|
||||
color = "Variant"
|
||||
) +
|
||||
theme_minimal() +
|
||||
theme(axis.text.x = element_text(angle = 45, hjust = 1))
|
||||
theme(
|
||||
axis.text.x = element_text(angle = 90, hjust = 1),
|
||||
plot.title = element_text(size = 14, face = "bold")
|
||||
)
|
||||
|
||||
ggsave("injections/ratio_comparison.svg", plot = plot, width = 12, height = 8)
|
||||
print("Saved ratio_comparison.svg")
|
||||
|
||||
@@ -3,8 +3,8 @@ library(dplyr)
|
||||
library(readr)
|
||||
library(stringr)
|
||||
|
||||
# Usage: Rscript ratio_comparison_merged.r exp_abspath1 exp_abspath2 ... [resultsdata_file]
|
||||
# Sums all benchmarks
|
||||
# Usage: Rscript ratio_comparison_merged_trap.r exp_abspath1 exp_abspath2 ... [resultsdata_file]
|
||||
# Sums all benchmarks, merges GROUP1_MARKER into TRAP
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
if (length(args) < 2) {
|
||||
@@ -59,7 +59,9 @@ if (nrow(all_data) == 0) {
|
||||
stop("No data loaded")
|
||||
}
|
||||
|
||||
# Add all benchs together (per marker type)
|
||||
all_data <- all_data |>
|
||||
mutate(resulttype = ifelse(resulttype == "GROUP1_MARKER", "TRAP", resulttype))
|
||||
|
||||
merged_data <- all_data |>
|
||||
group_by(base_name, variant, resulttype) |>
|
||||
summarise(faults = sum(faults), .groups = "drop")
|
||||
@@ -88,15 +90,21 @@ plot <- ggplot(
|
||||
geom_line() +
|
||||
facet_wrap(~base_name) +
|
||||
scale_y_log10(name = "Ratio (to C)") +
|
||||
scale_x_discrete(name = "Marker") +
|
||||
labs(color = "Variant") +
|
||||
scale_x_discrete(name = "Fault Type") +
|
||||
labs(
|
||||
color = "Variant",
|
||||
title = "Fault Count Ratios"
|
||||
) +
|
||||
theme_minimal() +
|
||||
theme(axis.text.x = element_text(angle = 45, hjust = 1))
|
||||
theme(
|
||||
axis.text.x = element_text(angle = 90, hjust = 1),
|
||||
plot.title = element_text(size = 14, face = "bold")
|
||||
)
|
||||
|
||||
ggsave(
|
||||
"injections/ratio_comparison_merged.svg",
|
||||
"injections/ratio_comparison_merged_trap.svg",
|
||||
plot = plot,
|
||||
width = 12,
|
||||
height = 8
|
||||
)
|
||||
print("Saved ratio_comparison_merged.svg")
|
||||
print("Saved ratio_comparison_merged_trap.svg")
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(readr)
|
||||
library(stringr)
|
||||
|
||||
# Usage: Rscript ratio_comparison_merged_trap.r exp_abspath1 exp_abspath2 ... [resultsdata_file]
|
||||
# Sums all benchmarks, merges GROUP1_MARKER into TRAP
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
if (length(args) < 2) {
|
||||
stop("Need at least 2 experiments")
|
||||
}
|
||||
|
||||
csv_suffix <- if (grepl("\\.csv$", args[length(args)])) {
|
||||
args[length(args)]
|
||||
} else {
|
||||
"resultsdata.csv"
|
||||
}
|
||||
exp_args <- if (grepl("\\.csv$", args[length(args)])) args[-length(args)] else args
|
||||
|
||||
extract_info <- function(path) {
|
||||
dir_name <- basename(path)
|
||||
match <- str_match(
|
||||
dir_name,
|
||||
"^\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}_(.+?)_(c|aot|interp)_"
|
||||
)
|
||||
if (is.na(match[1, 1])) {
|
||||
warning(paste("Could not parse:", dir_name))
|
||||
return(NULL)
|
||||
}
|
||||
list(base_name = match[1, 2], variant = match[1, 3], path = path)
|
||||
}
|
||||
|
||||
all_data <- data.frame()
|
||||
|
||||
for (arg in exp_args) {
|
||||
info <- extract_info(arg)
|
||||
if (is.null(info)) {
|
||||
next
|
||||
}
|
||||
|
||||
csv_file <- file.path(info$path, csv_suffix)
|
||||
if (!file.exists(csv_file)) {
|
||||
warning(paste("Missing:", csv_file))
|
||||
next
|
||||
}
|
||||
|
||||
df <- read_csv(csv_file, col_types = cols())
|
||||
df$base_name <- info$base_name
|
||||
df$variant <- info$variant
|
||||
all_data <- bind_rows(all_data, df)
|
||||
}
|
||||
|
||||
if (nrow(all_data) == 0) {
|
||||
stop("No data loaded")
|
||||
}
|
||||
|
||||
all_data <- all_data |>
|
||||
mutate(resulttype = ifelse(resulttype == "GROUP1_MARKER", "TRAP", resulttype))
|
||||
|
||||
merged_data <- all_data |>
|
||||
group_by(base_name, variant, resulttype) |>
|
||||
summarise(faults = sum(faults), .groups = "drop")
|
||||
|
||||
baseline <- merged_data |> filter(variant == "c")
|
||||
comparisons <- merged_data |> filter(variant != "c")
|
||||
|
||||
ratios <- comparisons |>
|
||||
left_join(
|
||||
baseline |> select(base_name, resulttype, faults),
|
||||
by = c("base_name", "resulttype"),
|
||||
suffix = c("", "_baseline")
|
||||
) |>
|
||||
filter(!is.na(faults_baseline), faults_baseline > 0) |>
|
||||
mutate(ratio = faults / faults_baseline)
|
||||
|
||||
if (nrow(ratios) == 0) {
|
||||
stop("No ratios computed (missing baseline or zero values)")
|
||||
}
|
||||
|
||||
plot <- ggplot(
|
||||
ratios,
|
||||
aes(x = resulttype, y = ratio, color = variant, group = variant)
|
||||
) +
|
||||
geom_point(size = 2) +
|
||||
geom_line() +
|
||||
facet_wrap(~base_name) +
|
||||
scale_y_log10(name = "Ratio (to C)") +
|
||||
scale_x_discrete(name = "Marker") +
|
||||
labs(color = "Variant") +
|
||||
theme_minimal() +
|
||||
theme(axis.text.x = element_text(angle = 45, hjust = 1))
|
||||
|
||||
ggsave(
|
||||
"injections/ratio_comparison_merged_trap.svg",
|
||||
plot = plot,
|
||||
width = 12,
|
||||
height = 8
|
||||
)
|
||||
print("Saved ratio_comparison_merged_trap.svg")
|
||||
@@ -1,129 +0,0 @@
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(readr)
|
||||
library(stringr)
|
||||
library(tidyr)
|
||||
|
||||
# Usage: Rscript ratio_correlation_no_mem.r exp_abspath1 exp_abspath2 ... [resultsdata_file]
|
||||
# Plots correlation between aot/c and interp/c ratios, ignoring mem benchmark
|
||||
# NOTE: Just a copy of the ratio_correlation.r script where I've changed the filter in line 67
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
if (length(args) < 2) {
|
||||
stop("Need at least 2 experiments")
|
||||
}
|
||||
|
||||
csv_suffix <- if (grepl("\\.csv$", args[length(args)])) {
|
||||
args[length(args)]
|
||||
} else {
|
||||
"resultsdata.csv"
|
||||
}
|
||||
exp_args <- if (grepl("\\.csv$", args[length(args)])) {
|
||||
args[-length(args)]
|
||||
} else {
|
||||
args
|
||||
}
|
||||
|
||||
extract_info <- function(path) {
|
||||
dir_name <- basename(path)
|
||||
match <- str_match(
|
||||
dir_name,
|
||||
"^\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}_(.+?)_(c|aot|interp)_"
|
||||
)
|
||||
if (is.na(match[1, 1])) {
|
||||
warning(paste("Could not parse:", dir_name))
|
||||
return(NULL)
|
||||
}
|
||||
list(base_name = match[1, 2], variant = match[1, 3], path = path)
|
||||
}
|
||||
|
||||
all_data <- data.frame()
|
||||
|
||||
for (arg in exp_args) {
|
||||
info <- extract_info(arg)
|
||||
if (is.null(info)) {
|
||||
next
|
||||
}
|
||||
|
||||
csv_file <- file.path(info$path, csv_suffix)
|
||||
if (!file.exists(csv_file)) {
|
||||
warning(paste("Missing:", csv_file))
|
||||
next
|
||||
}
|
||||
|
||||
df <- read_csv(csv_file, col_types = cols())
|
||||
df$base_name <- info$base_name
|
||||
df$variant <- info$variant
|
||||
all_data <- bind_rows(all_data, df)
|
||||
}
|
||||
|
||||
if (nrow(all_data) == 0) {
|
||||
stop("No data loaded")
|
||||
}
|
||||
|
||||
# Ignore OK_MARKER (only plot failures) and sum GROUP1_MARKER with TRAP
|
||||
# Also ignore mem benchmark
|
||||
all_data <- all_data |>
|
||||
filter(resulttype %in% c("TRAP", "GROUP1_MARKER"), benchmark == "ip") |>
|
||||
mutate(resulttype = ifelse(resulttype == "GROUP1_MARKER", "TRAP", resulttype))
|
||||
|
||||
all_data <- all_data |>
|
||||
group_by(base_name, variant, benchmark, resulttype) |>
|
||||
summarise(faults = sum(faults), .groups = "drop")
|
||||
|
||||
baseline <- all_data |> filter(variant == "c")
|
||||
comparisons <- all_data |> filter(variant != "c")
|
||||
|
||||
ratios <- comparisons |>
|
||||
left_join(
|
||||
baseline |> select(base_name, benchmark, resulttype, faults),
|
||||
by = c("base_name", "benchmark", "resulttype"),
|
||||
suffix = c("", "_baseline")
|
||||
) |>
|
||||
filter(!is.na(faults_baseline), faults_baseline > 0) |>
|
||||
mutate(ratio = faults / faults_baseline)
|
||||
|
||||
if (nrow(ratios) == 0) {
|
||||
stop("No ratios computed (missing baseline or zero values)")
|
||||
}
|
||||
|
||||
# Pivot to get aot and interp ratios side by side
|
||||
ratio_wide <- ratios |>
|
||||
select(base_name, benchmark, resulttype, variant, ratio) |>
|
||||
pivot_wider(names_from = variant, values_from = ratio) |>
|
||||
filter(!is.na(aot), !is.na(interp))
|
||||
|
||||
if (nrow(ratio_wide) == 0) {
|
||||
stop("No paired aot/interp ratios found")
|
||||
}
|
||||
|
||||
# Compute correlation
|
||||
cor_result <- cor(ratio_wide$aot, ratio_wide$interp, method = "pearson")
|
||||
cat(sprintf("Pearson correlation: %.4f\n", cor_result))
|
||||
|
||||
# Create plot
|
||||
plot <- ggplot(
|
||||
ratio_wide,
|
||||
aes(x = aot, y = interp, color = base_name, shape = resulttype)
|
||||
) +
|
||||
geom_point(size = 3, alpha = 0.7) +
|
||||
scale_x_log10(name = "AOT / C Ratio") +
|
||||
scale_y_log10(name = "Interpreter / C Ratio") +
|
||||
labs(
|
||||
title = sprintf("Ratio Correlation (r = %.4f)", cor_result),
|
||||
color = "Experiment",
|
||||
shape = "Marker"
|
||||
) +
|
||||
theme_minimal() +
|
||||
theme(
|
||||
legend.position = "right",
|
||||
plot.title = element_text(size = 14, face = "bold")
|
||||
)
|
||||
|
||||
ggsave(
|
||||
"injections/ratio_correlation_customized.svg",
|
||||
plot = plot,
|
||||
width = 10,
|
||||
height = 8
|
||||
)
|
||||
print("Saved ratio_correlation_customized.svg")
|
||||
Reference in New Issue
Block a user