-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_SKWD_dataframe.R
54 lines (41 loc) · 1.23 KB
/
test_SKWD_dataframe.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
# @fileoverview Copyright (c) 2020, Stefano Gualandi,
# via Ferrata, 1, I-27100, Pavia, Italy
#
# @author stefano.gualandi@gmail.com (Stefano Gualandi)
library(SpatialKWD)
# Random coordinates
N = 900
x <- as.integer(runif(N, 0, 31))
y <- as.integer(runif(N, 0, 31))
# Random weights
h1 <- runif(N, 0, 1)
h2 <- runif(N, 0, 1)
# Data frame with four columns named: "x", "y", "h1", "h2"
df <- data.frame(x, y, h1, h2)
# Compute distance
print("Test with data frame:")
d <- distanceDF(df, 3)
print(d)
# Data table
require(data.table)
# The table needs to have at least the four columns: "x", "y", "h1", "h2"
dt <- data.table(x=x, y=y, h1=h1, h2=h2)
# Compute distance
print("Test with data table:")
d <- distanceDF(dt, 3)
print(d)
# Increasing the second value, it increase the precision of
# the computed distance, but it can slow down the runtime speed
print("Benchmarking precision versus speed:")
start_time <- Sys.time()
d <- distanceDF(dt, 4)
print(c(d, Sys.time()-start_time))
start_time <- Sys.time()
d <- distanceDF(dt, 5)
print(c(d, Sys.time()-start_time))
start_time <- Sys.time()
d <- distanceDF(dt, 20)
print(c(d, Sys.time()-start_time))
start_time <- Sys.time()
d <- distanceDF(dt, 30)
print(c(d, Sys.time()-start_time))