Skip to content
Snippets Groups Projects
Commit 3e67bb68 authored by Felix Ramnelöv's avatar Felix Ramnelöv
Browse files

Lab 3: Updated distance computations for assignment 3

parent eae5a4f3
No related branches found
No related tags found
No related merge requests found
......@@ -29,39 +29,41 @@ times <- c(
)
st <- st[st$date <= date, ] # Filter out posterior dates
st$time <- strptime(st$time, format = "%H:%M:%S")
gaussian_kernel <- function(x, h) {
exp(-(x ^ 2) / (2 * h ^ 2))
}
dist = seq(0, 300000, length.out = 1000)
x = seq(0, 300000, length.out = 1000)
plot(
gaussian_kernel(dist, h_distance),
gaussian_kernel(x, h_distance),
type = 'l',
xlab = "Physical distance",
ylab = "Kernel value",
main = "Gaussian distance kernel"
)
grid()
dist = seq(0, 60)
x = seq(0, 60)
plot(
gaussian_kernel(dist, h_date),
gaussian_kernel(x, h_date),
type = 'l',
xlab = "Distance in days",
ylab = "Kernel value",
main = "Gaussian date kernel"
)
grid()
dist = seq(0, 18)
x = seq(0, 18)
plot(
gaussian_kernel(dist, h_time),
gaussian_kernel(x, h_time),
type = 'l',
xlab = "Distance in hours",
ylab = "Kernel value",
main = "Gaussian time kernel"
)
grid()
temp_add <- c()
temp_mult <- c()
......@@ -70,7 +72,7 @@ for (time in times) {
time <- strptime(time, format = "%H:%M:%S")
# Filter out posterior time
# Filter out posterior dates and time
st_temp <- st[st$date < date |
(st$date == date &
st$time <= time), ]
......@@ -117,6 +119,7 @@ axis(
at = 1:length(times),
labels = times
)
grid()
plot(
temp_mult,
......@@ -130,4 +133,5 @@ axis(
1,
at = 1:length(times),
labels = times
)
\ No newline at end of file
)
grid()
\ No newline at end of file
......@@ -90,10 +90,9 @@ err3
# 3. Implementation of SVM predictions.
gaussian_kernel <- function(x_i, x_star, sigma) {
return(exp(-sum((x_i - x_star)^2) / (2 * sigma^2)))
exp(-(dist(rbind(x_i, x_star)) ^ 2) / (2 * sigma ^ 2))
}
sv <- alphaindex(filter3)[[1]]
co <- coef(filter3)[[1]]
inte <- -b(filter3)
......@@ -119,4 +118,4 @@ for (i in 1:10) {
# Only first correct, close to decision boundary (0.006292512).
k
predict(filter3,spam[1:10,-58], type = "decision")
\ No newline at end of file
predict(filter3, spam[1:10, -58], type = "decision")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment