Skip to content

Commit 5e7f387

Browse files
Add updates
1 parent 3a9c4b6 commit 5e7f387

File tree

1 file changed

+7
-50
lines changed

1 file changed

+7
-50
lines changed

analyses/patter_03_algorithms.R

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ library(tictoc)
3030
dv::src()
3131

3232
#### Load data
33-
# map <- terra::rast(here_input("map.tif"))
33+
if (!os_linux()) {
34+
map <- terra::rast(here_input("map.tif"))
35+
}
3436
map_len <- qs::qread(here_input("map_len.qs"))
3537
timelines <- qs::qread(here_input("timelines.qs"))
3638
paths <- qs::qread(here_input("paths.qs"))
@@ -70,7 +72,7 @@ asd <- parameters$model_move$angle$sd
7072
state <- "StateXY"
7173
model_move <- move_xy(mobility = mobility,
7274
dbn_length = glue("truncated(Gamma({sshape}, {sscale}), lower = 0.0, upper = {mobility})"),
73-
dbn_angle = glue("Normal({amean}, {asd})"))
75+
dbn_angle = glue("Uniform(-pi, pi)"))
7476

7577
#### Define observation models
7678
# Assemble acoustics (0, 1)
@@ -100,13 +102,11 @@ args <- list(.timeline = timeline,
100102
.xinit = NULL,
101103
.yobs = yobs_fwd,
102104
.model_move = model_move,
103-
.n_particle = 1e4L,
105+
.n_particle = 2e4L,
104106
.direction = "forward"
105107
)
106108

107109
#### Run forward filter
108-
# * NB: Setting observations is slow (1 min)
109-
# > Weights from filter (1 -> 208292) are zero at time 62367
110110
fwd <- do.call(pf_filter, args, quote = TRUE)
111111

112112
#### Run backward filter
@@ -115,51 +115,8 @@ args$.direction <- "backward"
115115
do.call(pf_filter, args, quote = TRUE)
116116

117117
#### Run smoother
118-
out_smo <- pf_smoother_two_filter()
119-
120-
121-
###########################
122-
###########################
123-
#### Quick residency analysis
124-
125-
#### True residency in each region
126-
path_res <-
127-
path |>
128-
group_by(region) |>
129-
summarise(n = n()) |>
130-
mutate(residency = (n / sum(n)) * 100,
131-
estimate = "path",
132-
sim_id = id) |>
133-
as.data.table()
134-
135-
#### Particle residency estimates
136-
part_res <-
137-
out_smo |>
138-
mutate(region = terra::extract(map, cbind(x, y))) |>
139-
group_by(region) |>
140-
mutate(residency = (n / sum(n)) * 100,
141-
estimate = "smoother",
142-
sim_id = id) |>
143-
as.data.table()
144-
145-
#### Collect data
146-
res <- rbind(path_res, part_res)
147-
qs::qsave(res, "data/patter/output/residency/qresidency/", paste0(id, ".qs"))
148-
149-
150-
###########################
151-
###########################
152-
#### Synthesis
153-
154-
# Read residency data for each individual
155-
residency <-
156-
lapply(unique(paths$sim_id), function(id) {
157-
qs::qread("data/patter/qresidency.qs")
158-
}) |> rbindlist()
159-
160-
# Visualise residency ~ individual, coloured by truth/algorithm
161-
#
162-
# > TO DO
118+
smo <- pf_smoother_two_filter()
119+
qs::qsave(smo, here_output("particles", paste0(id, ".qs")))
163120

164121

165122
#### End of code.

0 commit comments

Comments
 (0)