-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathknor_final.Rmd
121 lines (75 loc) · 1.65 KB
/
knor_final.Rmd
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
---
title: "Knor Benchmark"
output:
pdf_document: default
html_notebook: default
---
# Benchmarking Results From Knor package
## Load Data
```{r}
# Load libraries
library(knor)
```
```{r}
## Installed packages
installed.packages()[names(sessionInfo()$otherPkgs), "Version"]
```
```{r}
## R Version
version[['version.string']]
```
```{r}
X_1m = as.matrix(read.csv("data_1m.csv", header = FALSE))
```
```{r}
X_100k = as.matrix(read.csv("data_100k.csv", header = FALSE))
```
```{r}
X_10k = as.matrix(read.csv("data_10k.csv", header = FALSE))
```
```{r}
X_1k = as.matrix(read.csv("data_1k.csv", header = FALSE))
```
## Elbow Method Speed Test
```{r}
# Just a convenient function to test execution speed of the 'Elbow method'
test_multicore_speed <- function(x){
rng <- 2:10
iters <- rng * 0
for (i in rng) {
m <- knor::Kmeans(data = x, centers = i,
iter.max = 100000, nthread = -1,
init = "kmeanspp",
tolerance = 1e-06,
dist.type = "eucl")
iters[i] = m$iters
}
return(iters)
}
```
```{r}
check_run_time_speed <- function(x){
# Replicate the number samples to get a mean time
time.taken <- c(1:7)*0
for (i in 1:7) {
start.time <- Sys.time()
test_multicore_speed(x)
end.time <- Sys.time()
time.taken[i] <- (as.numeric(end.time) - as.numeric(start.time))
}
return(summary(time.taken))
}
```
## Check Speed For Each Sample
```{r}
check_run_time_speed(X_1m)
```
```{r}
check_run_time_speed(X_100k)
```
```{r}
check_run_time_speed(X_10k)
```
```{r}
check_run_time_speed(X_1k)
```