library(ggplot2)
library(readr)
pedestrian <- read_delim("data/pedestrian.csv", ",")
pedestrian$TrajID <- as.factor(pedestrian$TrajID)
ggplot(data = pedestrian, aes(E, N, colour = TrajID)) +
facet_wrap(~ TrajID, ncol=3)+
geom_point() +
geom_path() +
geom_point() +
coord_fixed() +
theme(legend.position = "bottom")exercise_B
1 Exercise B
library(SimilarityMeasures)
traj_list <- split(pedestrian[, c("E", "N")], pedestrian$TrajID)
traj_mats <- lapply(traj_list, as.matrix)
dtw_vals <- sapply(2:6, function(i) {
DTW(traj_mats[[1]], traj_mats[[i]])
})
frechet_vals <- sapply(2:6, function(i) {
Frechet(traj_mats[[1]], traj_mats[[i]])
})
edit_vals <- sapply(2:6, function(i) {
EditDist(traj_mats[[1]], traj_mats[[i]])
})
lcss_vals <- sapply(2:6, function(i) {
LCSS(traj_mats[[1]], traj_mats[[i]],
pointSpacing = 2,
pointDistance = 3,
errorMarg = 1)
})
results <- data.frame(
Traj = 2:6,
DTW = dtw_vals,
Frechet = frechet_vals,
EditDist = edit_vals,
LCSS = lcss_vals
)
results Traj DTW Frechet EditDist LCSS
1 2 3650.025 28.54075 45 1
2 3 50785.511 2307.84366 47 1
3 4 5906.787 1069.22917 42 2
4 5 2178.411 717.98159 28 5
5 6 1152.718 38.96272 27 4
results_long <- reshape2::melt(results, id.vars = "Traj")
results_long$Traj <- as.factor(results_long$Traj)
ggplot(data = results_long, aes(Traj, value, fill = Traj)) +
facet_wrap(~ variable, ncol=2, scales = "free_y")+
geom_col()