Description Usage References Examples
This is just an example of how to use destim to compute the posterior location probabilities of the devices.
1 | example1()
|
https://github.com/MobilePhoneESSnetBigData
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 | # Local probabilities of transition
mask <- matrix(c(0.00001, 0.00320, 0.00001,
0.00320, 0.98716, 0.00320,
0.00001, 0.00320, 0.00001), ncol = 3)
#Complete transition matrix
P <- createTM(c(20,20), mask)
#Towers position
data(towers)
# Function S for Tennekes's model
S <- function(x) if (x > 5) return(0) else return(20*log(5/x))
# Complete events matrix
E <- createEM(c(20,20), towers, S)
# Load detection events
data(events)
# Estimate filtered states
FS <- fstates(P, E, events)
# Estimate smooth states
SS <- sstates(P, E, events, FS)
# Load some required packages
library(raster)
library(RColorBrewer)
library(animation)
library(ggplot2)
# Create the animations
# Filtered states
saveGIF({
pal <- colorRampPalette(c("white","red"))
ani.options(interval = 0.02)
for (i in 1:198) {
plot(raster(matrix(FS[,i], ncol = 20)), zlim = c(0,1), col = pal(100))
ani.pause()
}}, movie.name = 'filteredest.gif')
# Smooth states
saveGIF({
pal <- colorRampPalette(c("white","red"))
ani.options(interval = 0.02)
for (i in 1:198) {
plot(raster(matrix(SS[,i], ncol = 20)), zlim = c(0,1), col = pal(100))
ani.pause()
}}, movie.name = 'smoothest.gif')
# The matrix GRID relates the states with coordinates
GRID <- matrix(1, nrow = 2, ncol = 400)
GRID[1,] <- rep(1:20,20)
GRID[2,] <- rep(1:20, each = 20)
# Calculate square distance mean
fdist <- sapply (1:198, function (x)
sum(apply(GRID - matrix(c(x %/% 10 + 1,14), nrow = 2, ncol = 400), 2,norm,type = "2") * FS[,x]))
sdist <- sapply (1:198, function (x)
sum(apply(GRID - matrix(c(x %/% 10 + 1,14), nrow = 2, ncol = 400),2,norm,type = "2") * SS[,x]))
dists <- data.frame(T = 1:198, fdist = fdist, sdist = sdist)
ggplot() +
geom_line(data = dists, aes(x = T, y = sdist), colour = "green") +
geom_line(data = dists, aes(x = T, y = fdist), colour = "red")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.