Comments (4)
Thank you so much for your help! I managed to make it work so I will close my issue :)
from ertg3d.
Hi @alan-barzilay, thanks for your interest in the eRTG3D package.
Since movement in 2-D is a special case of movement in 3-D, the algorithm also supports two-dimensional simulations (see the Trajectory simulations in 2-D vignette). To create trajectories in 2-D just set the third dimension to zero:
library(eRTG3D)
# Dummy dataset
head(niclas)
#> x y z
#> 1 2556476 1188336 1283.736
#> 2 2558565 1189297 1359.580
#> 3 2560477 1189861 1369.713
#> 4 2562431 1190668 1391.752
#> 5 2563809 1190657 1806.566
#> 6 2567940 1192930 1764.062
# Set z dim to zero
niclas$z <- 0
And then simulate the trajectories using the wrapper function reproduce.track.3d
:
sim <- reproduce.track.3d(niclas, n.sim = 100, parallel = TRUE)
#> |TLD cube dimensions: 9 x 1 x 3
#> |Simulate UERW with 46500 steps
#> |======================================================================| 100%
#> |Elapsed time: 1.7s
#> |Extracting Q probabilities for 31 steps
#> |ForkCluster (unix): Running 15 processes in parallel
#> |======================================================================| 100%
#> |Elapsed time: 0.5s
#> |Simulate 100 CERWs with 31 steps
#> |ForkCluster (unix): Running 15 processes in parallel
#> |======================================================================| 100%
#> |Elapsed time: 2.1s
#> |Dead end tracks removed (n = 30, proportion: 0.3)
Visualize results:
plot3d.densities(niclas, sim)
plot2d(niclas, sim, titleText = "2-D trajectory simulation")
For further information on the individual steps to simulate trajectories check also the standard workflow vignette of the package.
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.5 (2021-03-31)
#> os macOS Big Sur 10.16
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Zurich
#> date 2021-05-16
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
#> cachem 1.0.4 2021-02-13 [1] CRAN (R 4.0.2)
#> callr 3.7.0 2021-04-20 [1] CRAN (R 4.0.2)
#> cli 2.5.0 2021-04-26 [1] CRAN (R 4.0.2)
#> colorspace 2.0-0 2020-11-11 [1] CRAN (R 4.0.2)
#> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.2)
#> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.0.2)
#> desc 1.3.0 2021-03-05 [1] CRAN (R 4.0.2)
#> devtools 2.4.0 2021-04-07 [1] CRAN (R 4.0.2)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2)
#> dplyr 1.0.5 2021-03-05 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.0.2)
#> eRTG3D * 0.6.3 2020-07-26 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
#> fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.2)
#> farver 2.1.0 2021-02-28 [1] CRAN (R 4.0.2)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.2)
#> ggplot2 3.3.3 2020-12-30 [1] CRAN (R 4.0.3)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.0.2)
#> htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2)
#> knitr 1.33 2021-04-24 [1] CRAN (R 4.0.2)
#> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.2)
#> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.2)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2)
#> memoise 2.0.0 2021-01-26 [1] CRAN (R 4.0.2)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0)
#> pbapply 1.4-3 2020-08-18 [1] CRAN (R 4.0.2)
#> pillar 1.6.0 2021-04-13 [1] CRAN (R 4.0.2)
#> pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
#> pkgload 1.2.1 2021-04-06 [1] CRAN (R 4.0.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
#> processx 3.5.2 2021-04-30 [1] CRAN (R 4.0.5)
#> ps 1.6.0 2021-02-28 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.0)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2)
#> remotes 2.3.0 2021-04-01 [1] CRAN (R 4.0.2)
#> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.0.5)
#> rmarkdown 2.7 2021-02-19 [1] CRAN (R 4.0.2)
#> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0)
#> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> testthat 3.0.2 2021-02-14 [1] CRAN (R 4.0.2)
#> tibble 3.1.1 2021-04-18 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.0.5)
#> usethis 2.0.1 2021-02-10 [1] CRAN (R 4.0.2)
#> utf8 1.2.1 2021-03-12 [1] CRAN (R 4.0.2)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.0.2)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.2)
#> xfun 0.22 2021-03-11 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
from ertg3d.
@munterfinger Thank you for your detailed response! I don't know how I missed that vignette, thank you.
My understanding of eRTG3D is that it can generate artificial trajectories given an example trajectory and information about the environment, right? For my use case I just need to generate random trajectories between 2 points, the idea is to simply simulate someone going from point A to point B so I don't really have an example trajectory to use as a base and the environment could be anything.
From your experience with this project, do you believe it could be a good fit for my use case or should I look for another solution? I originally mistook this tool as an implementation of this paper that seems closer to my objective, but I would rather not have to implement something from scratch haha
I was thinking about creating a simple trajectory going straight from point A to point B to test with eRTG3D, but it seems this would create trajectories that are to much "well behaved".
from ertg3d.
Hi, if I understand correctly, you have no ground truth movement data and thus no movement properties of the mover?
Therefore you have to define the properties of the mover, which could be done by correlated random walks. In the example below a correlated random walk with 0.9 correlation in turn angle and a correlation of 1 in lift angle (only 2-D) is generated. You can vary the movement behavior by changing the turn angle correlation and mean step length (meanStep
):
library(eRTG3D)
set.seed(1234)
# Define your origin A and destination B
orig <- c(50,20,0)
dest <- c(100, 50, 0)
dist_total <- sqrt(sum((dest-orig)^2))
# Correlated random walk
crw <- sim.crw.3d(
nStep = 1000,
rTurn = 0.9,
rLift = 1,
meanStep = 5,
start = orig
)
# Set third dim to zero
crw$z <- 0
plot3d.densities(crw)
plot2d(crw)
Now extract the movement properties of the mover:
# Movement characteristics (P)
P <- get.track.densities.3d(crw)
#> |TLD cube dimensions: 25 x 1 x 20
plot3d.tldCube(P$tldCube)
As the algorithm assumes constant time between the individual locations (not often the case in real GPS data…) you can easily extract the number of steps needed to reach the destination with the given movement properties using a distance approach (alternative would be time). In addition allow the mover some more flexibility by multiplying the number of steps by a factor greater 1 (increases the number of successful simulated trajectories):
# Get number of steps
flexibility <- 1.1
crw <- track.properties.3d(crw)
dist_per_step <- mean(crw$d, na.rm = TRUE)
sim_locs <- round(dist_total/dist_per_step)*flexibility
Set the boundary conditions: Initial azimuth and lift angle (pi/2 in the 2-D case):
# Boundary conditions
a0 <- crw$a[1]
g0 <- crw$g[1]
Then extract the attraction term Q
for ‘sim_locs’ steps from a long (f
times the sim_locs
) unconditional empirical random walk with movement characteristics P
:
f <- 1500
uerw <- sim.uncond.3d(
sim_locs*f,
start = orig,
a0 = a0,
g0 = g0,
densities = P)
#> |Simulate UERW with 33000 steps
#> |======================================================================| 100%
#> |Elapsed time: 1.9s
Q <- qProb.3d(uerw, sim_locs, parallel = FALSE)
#> |Extracting Q probabilities for 22 steps
#> |======================================================================| 100%
#> |Elapsed time: 0.6s
Finally you can simulate the conditional empirical random walks between A and B:
# Conditional empirical random walks between A and B
cerw_list <- n.sim.cond.3d(
n.sim = 100, sim_locs,
start = orig, end = dest,
a0 = a0, g0 = g0,
densities = P, qProbs = Q,
parallel = TRUE
)
#> |Simulate 100 CERWs with 22 steps
#> |ForkCluster (unix): Running 15 processes in parallel
#> |======================================================================| 100%
#> |Elapsed time: 2.1s
# Remove trajectories, which did not reach the destination
cerw_list <- filter.dead.ends(cerw_list)
#> |Dead end tracks removed (n = 40, proportion: 0.4)
# Visualize result
plot3d.densities(crw, cerw_list)
plot2d(cerw_list)
Let me know if this solves the issue?
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.5 (2021-03-31)
#> os macOS Big Sur 10.16
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Zurich
#> date 2021-05-16
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
#> boot 1.3-27 2021-02-12 [1] CRAN (R 4.0.5)
#> cachem 1.0.4 2021-02-13 [1] CRAN (R 4.0.2)
#> callr 3.7.0 2021-04-20 [1] CRAN (R 4.0.2)
#> CircStats 0.2-6 2018-07-01 [1] CRAN (R 4.0.0)
#> cli 2.5.0 2021-04-26 [1] CRAN (R 4.0.2)
#> colorspace 2.0-0 2020-11-11 [1] CRAN (R 4.0.2)
#> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.2)
#> crosstalk 1.1.1 2021-01-12 [1] CRAN (R 4.0.2)
#> data.table 1.14.0 2021-02-21 [1] CRAN (R 4.0.2)
#> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.0.2)
#> desc 1.3.0 2021-03-05 [1] CRAN (R 4.0.2)
#> devtools 2.4.0 2021-04-07 [1] CRAN (R 4.0.2)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2)
#> dplyr 1.0.5 2021-03-05 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.0.2)
#> eRTG3D * 0.6.3 2020-07-26 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
#> fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.2)
#> farver 2.1.0 2021-02-28 [1] CRAN (R 4.0.2)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.2)
#> ggplot2 3.3.3 2020-12-30 [1] CRAN (R 4.0.3)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.0.2)
#> htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2)
#> htmlwidgets 1.5.3 2020-12-10 [1] CRAN (R 4.0.2)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.2)
#> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.0.2)
#> knitr 1.33 2021-04-24 [1] CRAN (R 4.0.2)
#> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.2)
#> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.0.0)
#> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.2)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2)
#> MASS 7.3-53.1 2021-02-12 [1] CRAN (R 4.0.5)
#> memoise 2.0.0 2021-01-26 [1] CRAN (R 4.0.2)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0)
#> pbapply 1.4-3 2020-08-18 [1] CRAN (R 4.0.2)
#> pillar 1.6.0 2021-04-13 [1] CRAN (R 4.0.2)
#> pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
#> pkgload 1.2.1 2021-04-06 [1] CRAN (R 4.0.2)
#> plotly 4.9.3 2021-01-10 [1] CRAN (R 4.0.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
#> processx 3.5.2 2021-04-30 [1] CRAN (R 4.0.5)
#> ps 1.6.0 2021-02-28 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.0)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2)
#> remotes 2.3.0 2021-04-01 [1] CRAN (R 4.0.2)
#> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.0.5)
#> rmarkdown 2.7 2021-02-19 [1] CRAN (R 4.0.2)
#> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0)
#> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> testthat 3.0.2 2021-02-14 [1] CRAN (R 4.0.2)
#> tibble 3.1.1 2021-04-18 [1] CRAN (R 4.0.2)
#> tidyr 1.1.3 2021-03-03 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.0.5)
#> usethis 2.0.1 2021-02-10 [1] CRAN (R 4.0.2)
#> utf8 1.2.1 2021-03-12 [1] CRAN (R 4.0.2)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.0.2)
#> viridisLite 0.4.0 2021-04-13 [1] CRAN (R 4.0.2)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.2)
#> xfun 0.22 2021-03-11 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
from ertg3d.
Related Issues (16)
- Implement parallel computation also for Windows systems
- New plotly version
- Hidden functions documentation
- Parallel gliding and soaring on windows
- Roxygen example
- Package import statements
- Replace .fd.bw with r base function
- Enable 2-D
- Add package citation
- Notes in R CMD check
- Package site
- CRAN submission feedback: DOIs
- CRAN submission feedback: URLs
- CRAN submission feedback: Remove cat()
- CRAN submission feedback: nCores <= 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ertg3d.