Last updated: 2021-10-04

Checks: 7 0

Knit directory: Test/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20210926) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 8466631. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store
    Ignored:    data/Stabiliseur/
    Ignored:    data/json/
    Ignored:    data/plan/
    Ignored:    fig/
    Ignored:    workflowr.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/machine_learning.Rmd) and HTML (docs/machine_learning.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 8466631 cfcforever 2021-10-04 add new analysis
html 99b80c9 cfcforever 2021-10-04 Build site.
Rmd ed2c623 cfcforever 2021-10-04 some changes
html 5fe63f5 cfcforever 2021-10-04 Build site.
Rmd 497949e cfcforever 2021-10-04 some changes

We are using the machine learning method to stabilize the points.

Introduction

This is an example of 199 points with the frequency of 200ms. We want to use a machine learning model to recognize if any 5 consecutive points are moving or not.

# load json file
json_data <- fromJSON(file = "data/Stabiliseur/data/2021-02-12_Firminy/test1/t1_anchor1_3tags_200ms.json")

# choose tagId, x and y from json_data, and convert list to data.frame
data <- data.frame(tagId = unlist(lapply(json_data, function(x){x$tagId})),
                   x = unlist(lapply(json_data, function(x){as.numeric(x$posUnfiltered$x)})),
                   y = unlist(lapply(json_data, function(x){as.numeric(x$posUnfiltered$y)})))

# choose a tag
dd = data %>%
  filter(tagId == "82a5")

plot of data

p <- ggplot(dd) + theme_bw() +
  geom_point(aes(x=x, y=y), col="red") + 
  coord_equal(ratio = 1)
print(p)

Version Author Date
99b80c9 cfcforever 2021-10-04

Machine learning method

load model and predict data

load("data/Stabiliseur/ML/ML_model.RData")

input = as.data.frame(matrix(NA, nrow = nrow(dd)-4, ncol = 10))
for (k in 1:nrow(input)){
  input[k,] = as.numeric(dist(dd[k:(k+4), c("x","y")]))
}

dd$pred = 0
prediction = round(predict(ir, input), 3)
dd$pred[1:nrow(input)] = prediction

datatable(dd, class = 'cell-border stripe')

result

nb = length(prediction)
num = sum(prediction<=0.7)
ratio = num/nb
message(paste0(unique(dd$tagId), " - with ", nb, " points and to be predicted ", ratio*100, "% corrected of resting positions (which ", nb-num, " points are false)."))
82a5 - with 195 points and to be predicted 93.8461538461538% corrected of resting positions (which 12 points are false).

Study cases

case 1

k = 42
dk = 4

dist = round(as.matrix(dist(dd[k:(k+dk),c("x","y")])), 3)
kable(dist) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)
42 43 44 45 46
42 0.000 0.218 0.258 0.210 0.372
43 0.218 0.000 0.041 0.015 0.154
44 0.258 0.041 0.000 0.048 0.115
45 0.210 0.015 0.048 0.000 0.163
46 0.372 0.154 0.115 0.163 0.000
p <- ggplot() + theme_bw() +
  geom_point(data=dd[k:(k+dk),], aes(x=x, y=y), col="red") + 
  geom_text(data=dd[k:(k+dk),], aes(x=x, y=y, label=k:(k+dk), vjust=-0.5), size=3) + 
  geom_path(data=dd[k:(k+dk),], aes(x=x,y=y), col="red") + 
  coord_equal(ratio = 1, xlim = range(dd$x), ylim = range(dd$y))
p

Version Author Date
99b80c9 cfcforever 2021-10-04

case 2

k = 61
dk = 7

dist = round(as.matrix(dist(dd[k:(k+dk),c("x","y")])), 3)
kable(dist) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)
61 62 63 64 65 66 67 68
61 0.000 0.088 0.058 0.030 0.309 0.477 0.380 0.297
62 0.088 0.000 0.054 0.097 0.372 0.539 0.445 0.367
63 0.058 0.054 0.000 0.051 0.318 0.485 0.391 0.314
64 0.030 0.097 0.051 0.000 0.284 0.452 0.356 0.275
65 0.309 0.372 0.318 0.284 0.000 0.168 0.074 0.044
66 0.477 0.539 0.485 0.452 0.168 0.000 0.101 0.187
67 0.380 0.445 0.391 0.356 0.074 0.101 0.000 0.086
68 0.297 0.367 0.314 0.275 0.044 0.187 0.086 0.000
p <- ggplot() + theme_bw() +
  geom_point(data=dd[k:(k+dk),], aes(x=x, y=y), col="red") + 
  geom_text(data=dd[k:(k+dk),], aes(x=x, y=y, label=k:(k+dk), vjust=-0.5), size=3) + 
  geom_path(data=dd[k:(k+dk),], aes(x=x,y=y), col="red") + 
  coord_equal(ratio = 1, xlim = range(dd$x), ylim = range(dd$y))
p

Version Author Date
99b80c9 cfcforever 2021-10-04

case 3

k = 71
dk = 5

dist = round(as.matrix(dist(dd[k:(k+dk),c("x","y")])), 3)
kable(dist) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)
71 72 73 74 75 76
71 0.000 0.043 0.164 0.186 0.333 0.197
72 0.043 0.000 0.207 0.228 0.376 0.239
73 0.164 0.207 0.000 0.034 0.169 0.032
74 0.186 0.228 0.034 0.000 0.152 0.029
75 0.333 0.376 0.169 0.152 0.000 0.137
76 0.197 0.239 0.032 0.029 0.137 0.000
p <- ggplot() + theme_bw() +
  geom_point(data=dd[k:(k+dk),], aes(x=x, y=y), col="red") + 
  geom_text(data=dd[k:(k+dk),], aes(x=x, y=y, label=k:(k+dk), vjust=-0.5), size=3) + 
  geom_path(data=dd[k:(k+dk),], aes(x=x,y=y), col="red") + 
  coord_equal(ratio = 1, xlim = range(dd$x), ylim = range(dd$y))
p

Version Author Date
99b80c9 cfcforever 2021-10-04

case 4

k = 75
dk = 4

dist = round(as.matrix(dist(dd[k:(k+dk),c("x","y")])), 3)
kable(dist) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)
75 76 77 78 79
75 0.000 0.137 0.239 0.317 0.379
76 0.137 0.000 0.102 0.181 0.243
77 0.239 0.102 0.000 0.080 0.141
78 0.317 0.181 0.080 0.000 0.062
79 0.379 0.243 0.141 0.062 0.000
p <- ggplot() + theme_bw() +
  geom_point(data=dd[k:(k+dk),], aes(x=x, y=y), col="red") + 
  geom_text(data=dd[k:(k+dk),], aes(x=x, y=y, label=k:(k+dk), vjust=-0.5), size=3) + 
  geom_path(data=dd[k:(k+dk),], aes(x=x,y=y), col="red") + 
  coord_equal(ratio = 1, xlim = range(dd$x), ylim = range(dd$y))
p

Version Author Date
99b80c9 cfcforever 2021-10-04

case 5

k = 79
dk = 4

dist = round(as.matrix(dist(dd[k:(k+dk),c("x","y")])), 3)
kable(dist) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)
79 80 81 82 83
79 0.000 0.231 0.371 0.267 0.176
80 0.231 0.000 0.141 0.045 0.056
81 0.371 0.141 0.000 0.106 0.196
82 0.267 0.045 0.106 0.000 0.093
83 0.176 0.056 0.196 0.093 0.000
p <- ggplot() + theme_bw() +
  geom_point(data=dd[k:(k+dk),], aes(x=x, y=y), col="red") + 
  geom_text(data=dd[k:(k+dk),], aes(x=x, y=y, label=k:(k+dk), vjust=-0.5), size=3) + 
  geom_path(data=dd[k:(k+dk),], aes(x=x,y=y), col="red") + 
  coord_equal(ratio = 1, xlim = range(dd$x), ylim = range(dd$y))
p

Version Author Date
99b80c9 cfcforever 2021-10-04

case 6

k = 81
dk = 4

dist = round(as.matrix(dist(dd[k:(k+dk),c("x","y")])), 3)
kable(dist) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)
81 82 83 84 85
81 0.000 0.106 0.196 0.285 0.366
82 0.106 0.000 0.093 0.182 0.265
83 0.196 0.093 0.000 0.089 0.172
84 0.285 0.182 0.089 0.000 0.083
85 0.366 0.265 0.172 0.083 0.000
p <- ggplot() + theme_bw() +
  geom_point(data=dd[k:(k+dk),], aes(x=x, y=y), col="red") + 
  geom_text(data=dd[k:(k+dk),], aes(x=x, y=y, label=k:(k+dk), vjust=-0.5), size=3) + 
  geom_path(data=dd[k:(k+dk),], aes(x=x,y=y), col="red") + 
  coord_equal(ratio = 1, xlim = range(dd$x), ylim = range(dd$y))
p

Version Author Date
99b80c9 cfcforever 2021-10-04

case 7

k = 88
dk = 4

dist = round(as.matrix(dist(dd[k:(k+dk),c("x","y")])), 3)
kable(dist) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)
88 89 90 91 92
88 0.000 0.142 0.231 0.303 0.343
89 0.142 0.000 0.090 0.162 0.201
90 0.231 0.090 0.000 0.072 0.113
91 0.303 0.162 0.072 0.000 0.044
92 0.343 0.201 0.113 0.044 0.000
p <- ggplot() + theme_bw() +
  geom_point(data=dd[k:(k+dk),], aes(x=x, y=y), col="red") + 
  geom_text(data=dd[k:(k+dk),], aes(x=x, y=y, label=k:(k+dk), vjust=-0.5), size=3) + 
  geom_path(data=dd[k:(k+dk),], aes(x=x,y=y), col="red") + 
  coord_equal(ratio = 1, xlim = range(dd$x), ylim = range(dd$y))
p

Version Author Date
99b80c9 cfcforever 2021-10-04

case 8

k = 94
dk = 6

dist = round(as.matrix(dist(dd[k:(k+dk),c("x","y")])), 3)
kable(dist) %>%
  kable_styling(bootstrap_options = "striped", full_width = F)
94 95 96 97 98 99 100
94 0.000 0.120 0.341 0.246 0.147 0.103 0.061
95 0.120 0.000 0.227 0.135 0.049 0.027 0.060
96 0.341 0.227 0.000 0.096 0.194 0.239 0.281
97 0.246 0.135 0.096 0.000 0.098 0.143 0.185
98 0.147 0.049 0.194 0.098 0.000 0.047 0.088
99 0.103 0.027 0.239 0.143 0.047 0.000 0.042
100 0.061 0.060 0.281 0.185 0.088 0.042 0.000
p <- ggplot() + theme_bw() +
  geom_point(data=dd[k:(k+dk),], aes(x=x, y=y), col="red") + 
  geom_text(data=dd[k:(k+dk),], aes(x=x, y=y, label=k:(k+dk), vjust=-0.5), size=3) + 
  geom_path(data=dd[k:(k+dk),], aes(x=x,y=y), col="red") + 
  coord_equal(ratio = 1, xlim = range(dd$x), ylim = range(dd$y))
p


sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] DT_0.17          readxl_1.3.1     lubridate_1.7.10 dplyr_1.0.6     
 [5] nnet_7.3-14      kableExtra_1.1.0 rjson_0.2.20     cowplot_1.1.0   
 [9] gifski_0.8.6     gganimate_1.0.7  ggplot2_3.3.3    workflowr_1.6.2 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        prettyunits_1.1.1 assertthat_0.2.1  rprojroot_1.3-2  
 [5] digest_0.6.25     utf8_1.1.4        R6_2.4.1          cellranger_1.1.0 
 [9] backports_1.1.8   evaluate_0.14     httr_1.4.2        highr_0.8        
[13] pillar_1.6.0      rlang_0.4.11      progress_1.2.2    rstudioapi_0.13  
[17] whisker_0.4       rmarkdown_2.10    labeling_0.3      webshot_0.5.2    
[21] readr_1.4.0       stringr_1.4.0     htmlwidgets_1.5.1 munsell_0.5.0    
[25] compiler_4.0.2    httpuv_1.5.4      xfun_0.25         pkgconfig_2.0.3  
[29] htmltools_0.5.0   tidyselect_1.1.0  tibble_3.1.1      fansi_0.4.1      
[33] viridisLite_0.3.0 crayon_1.4.1      withr_2.4.2       later_1.1.0.1    
[37] grid_4.0.2        jsonlite_1.7.2    gtable_0.3.0      lifecycle_1.0.0  
[41] DBI_1.1.1         git2r_0.28.0      magrittr_2.0.1    scales_1.1.1     
[45] stringi_1.4.6     farver_2.0.3      fs_1.5.0          promises_1.1.1   
[49] xml2_1.3.2        ellipsis_0.3.1    generics_0.1.0    vctrs_0.3.8      
[53] tools_4.0.2       glue_1.4.1        tweenr_1.0.1      purrr_0.3.4      
[57] hms_1.0.0         crosstalk_1.1.0.1 yaml_2.2.1        colorspace_1.4-1 
[61] rvest_1.0.0       knitr_1.33