-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.R
140 lines (112 loc) · 4.64 KB
/
benchmark.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
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
K_values <- seq(5, 25, 1)
T_values <- seq(5, 300, 25)
# Function to create a random haplotype matrix
generate_haps <- function(K, T) {
matrix(sample(0:1, K * T, replace = TRUE),
nrow = K,
ncol = T)
}
# Measure execution time for varying K (keeping T constant)
results_K <- data.frame(K = integer(), Time = numeric())
for (K in K_values) {
haps <- generate_haps(K, 100) # Keeping T constant at 100
hap <- sample(0:1, 100, replace = TRUE)
time_taken <- microbenchmark(forward(haps, hap), times = 10)$time
results_K <- rbind(results_K, data.frame(K, Time = mean(time_taken)))
}
# Measure execution time for varying T (keeping K constant)
results_T <- data.frame(T = integer(), Time = numeric())
for (T in T_values) {
haps <- generate_haps(10, T) # Keeping K constant at 10
hap <- sample(0:1, T, replace = TRUE)
time_taken <- microbenchmark(forward(haps, hap), times = 10)$time
results_T <- rbind(results_T, data.frame(T, Time = mean(time_taken)))
}
# Measure execution time for varying K (keeping T constant)
results_K_back <- data.frame(K = integer(), Time = numeric())
for (K in K_values) {
haps <- generate_haps(K, 100) # Keeping T constant at 100
hap <- sample(0:1, 100, replace = TRUE)
time_taken <- microbenchmark(backward(haps, hap), times = 10)$time
results_K_back <- rbind(results_K_back, data.frame(K, Time = mean(time_taken)))
}
# # Measure execution time for varying T (keeping K constant)
results_T_back <- data.frame(T = integer(), Time = numeric())
for (T in T_values) {
haps <- generate_haps(10, T) # Keeping K constant at 10
hap <- sample(0:1, T, replace = TRUE)
time_taken <- microbenchmark(backward(haps, hap), times = 10)$time
results_T_back <- rbind(results_T_back, data.frame(T, Time = mean(time_taken)))
}
ggplot(data = results_K, aes(x = K, y = Time)) +
geom_line() +
geom_point() +
ggtitle("Execution Time vs. Number of Haplotypes (K)",
subtitle = "Forward Function") +
xlab("Number of Haplotypes (K)") +
ylab("Execution Time (microseconds)")
# Plot for varying T (keeping K constant)
ggplot(data = results_T, aes(x = T, y = Time)) +
geom_line() +
geom_point() +
ggtitle("Execution Time vs. Number of Loci (T)",
subtitle = "Forward Function") +
xlab("Number of Loci (T)") +
ylab("Execution Time (microseconds)")
# Print tables for results_K and results_T
print(xtable(results_K, caption = "Tabular Results for Forward Function varying K"), type = "latex", comment = FALSE)
print(xtable(results_T, caption = "Tabular Results for Forward Function varying T"), type = "latex", comment = FALSE)
# Plot for varying K (keeping T constant)
ggplot(data = results_K_back, aes(x = K, y = Time)) +
geom_line() +
geom_point() +
ggtitle("Execution Time vs. Number of Haplotypes (K)",
subtitle = "Backward Function") +
xlab("Number of Haplotypes (K)") +
ylab("Execution Time (microseconds)")
# Plot for varying T (keeping K constant)
ggplot(data = results_T_back, aes(x = T, y = Time)) +
geom_line() +
geom_point() +
ggtitle("Execution Time vs. Number of Loci (T)",
subtitle = "Backward Function") +
xlab("Number of Loci (T)") +
ylab("Execution Time (microseconds)")
# Print tables for results_K_back and results_T_back
print(xtable(results_K_back, caption = "Tabular Results for Backward Function varying K"), type = "latex", comment = FALSE)
print(xtable(results_T_back, caption = "Tabular Results for Backward Function varying T"), type = "latex", comment = F)
K_values <- seq(5, 50, 10) # Varying K values
T <- 10 # Fixed T value for simplicity
# Function to create a random haplotype matrix
generate_haps <- function(K, T) {
matrix(sample(0:1, K * T, replace = TRUE),
nrow = K,
ncol = T)
}
# Measure execution time
results <-
data.frame(K = integer(),
Time = numeric(),
Function = character())
for (K in K_values) {
haps <- generate_haps(K, T)
hap <- sample(0:1, T, replace = TRUE)
time_gamma <- microbenchmark(gamma(haps, hap), times = 10)$time
results <-
rbind(results, data.frame(K, Time = mean(time_gamma), Function = "gamma"))
time_gamma2 <- microbenchmark(gamma2(haps, hap), times = 10)$time
results <-
rbind(results, data.frame(K, Time = mean(time_gamma2), Function = "gamma2"))
}
# Create a plot
ggplot(results, aes(x = K, y = Time, color = Function)) +
geom_line() +
geom_point() +
ggtitle("Execution Time of Gamma and Gamma2") +
xlab("Number of Haplotypes (K)") +
ylab("Execution Time (microseconds)") +
scale_color_viridis_d() +
theme_minimal()
# Print the results table
print(results)
print(xtable(results, by = "Region_Name"), type = "latex", comment = FALSE)