Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdde01-ht24
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mehce338-felra653-sigjo290
tdde01-ht24
Commits
97024f7a
Commit
97024f7a
authored
3 months ago
by
Felix Ramnelöv
Browse files
Options
Downloads
Patches
Plain Diff
Lab 3: Fixes for assignment 2, according to seminar
parent
b1e49b4f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lab3/assignment2.R
+19
-7
19 additions, 7 deletions
lab3/assignment2.R
with
19 additions
and
7 deletions
lab3/assignment2.R
+
19
−
7
View file @
97024f7a
...
...
@@ -32,7 +32,7 @@ times <- c(
st
$
time
<-
strptime
(
st
$
time
,
format
=
"%H:%M:%S"
)
gaussian_kernel
<-
function
(
x
,
h
)
{
exp
(
-
(
x
^
2
)
/
(
2
*
h
^
2
))
exp
(
-
(
x
^
2
)
/
(
2
*
h
^
2
))
}
x
=
seq
(
0
,
300000
,
length.out
=
1000
)
...
...
@@ -66,7 +66,6 @@ plot(
grid
()
date_diff_ignoring_year
<-
function
(
date1
,
date2
)
{
# Generate new dates with the same year
date1
<-
strsplit
(
date1
,
"-"
)[[
1
]]
date2
<-
strsplit
(
date2
,
"-"
)[[
1
]]
...
...
@@ -78,10 +77,22 @@ date_diff_ignoring_year <- function(date1, date2) {
date2
<-
as.Date
(
paste
(
"2000"
,
month2
,
day2
,
sep
=
"-"
))
# Get difference in days
diff
<-
abs
(
as.numeric
(
date1
-
date2
))
diff
<-
abs
(
as.numeric
(
date1
-
date2
))
# If difference is greater than half a year, go other way
if
(
diff
>=
183
)
diff
<-
366
-
diff
if
(
diff
>=
183
)
diff
<-
366
-
diff
return
(
diff
)
}
difftime_ignoring_day
<-
function
(
time1
,
time2
)
{
# Get difference in hours
diff
<-
abs
(
as.numeric
(
difftime
(
time1
,
time2
,
units
=
"hours"
)))
# If difference is grater than 12 hours, go other way
if
(
diff
>
12
)
diff
<-
abs
(
diff
-
24
)
return
(
diff
)
}
...
...
@@ -96,8 +107,9 @@ for (time in times) {
# Filter out posterior dates and time
st_temp
<-
st
[
st
$
date
<
date
|
(
st
$
date
==
date
&
st
$
time
<
=
time
),
]
st
$
time
<
time
),
]
# Normalize data?
distance_kernels
<-
mapply
(
function
(
lat
,
lon
)
{
dist
<-
distHaversine
(
c
(
a
,
b
),
c
(
lat
,
lon
))
...
...
@@ -112,7 +124,7 @@ for (time in times) {
time_kernels
<-
mapply
(
function
(
time_i
)
{
dist
<-
as.numeric
(
difftime
(
time
,
time_i
,
units
=
"hours"
)
)
dist
<-
difftime_ignoring_day
(
time
,
time_i
)
gaussian_kernel
(
dist
,
h_time
)
},
st_temp
$
time
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment