Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template List silently allows a matrix of values #13

Open
muschellij2 opened this issue Aug 9, 2023 · 0 comments · May be fixed by #14 or #15
Open

Template List silently allows a matrix of values #13

muschellij2 opened this issue Aug 9, 2023 · 0 comments · May be fixed by #14 or #15

Comments

@muschellij2
Copy link
Contributor

It seems as though the checks for template are not correct since it allows numeric matrices:

library(adept)
library(adeptdata)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

Getting some data from adeptdata to show what happens

xyz = adeptdata::acc_walking_IU
xyz = xyz %>% 
  filter(loc_id == "left_wrist") %>% 
  filter(subj_id == subj_id[1])
xyz = xyz %>% 
  select(x, y, z)

Grabbing a Template from Adept Data

template = stride_template$left_wrist[[2]]
class(template)
#> [1] "matrix" "array"
dim(template)
#> [1]   2 200

Wee see that it is indeed a matrix

template[, 1:5]
#>          [,1]     [,2]     [,3]     [,4]     [,5]
#> [1,] 1.741446 1.709791 1.674425 1.613533 1.547839
#> [2,] 1.763806 1.653034 1.542068 1.414503 1.287220

Here are the conditions from segmentPattern:

template.cond1 <- all(is.numeric(template)) & is.atomic(template)
. The first condition comes up TRUE, but it shouldn't:

template.cond1 <- all(is.numeric(template)) & is.atomic(template)
template.cond1
#> [1] TRUE
template.cond2 <- is.list(template) & all(sapply(template, 
                                                 function(vec) all(is.numeric(vec)) & is.atomic(vec)))
template.cond2
#> [1] FALSE

If we change is.atomic to is.vector, it gives the correct fails

template.cond1 <- all(is.numeric(template)) & is.vector(template)
template.cond1
#> [1] FALSE
template.cond2 <- is.list(template) & all(sapply(template, 
                                                 function(vec) all(is.numeric(vec)) & is.vector(vec)))
template.cond2
#> [1] FALSE

Running with the matrix

out_lw <- segmentWalking(
  xyz = xyz,
  xyz.fs = 100,
  template = template,
  compute.template.idx = TRUE)
out_lw %>% 
  count(template_i)
#>   template_i   n
#> 1          1 198

Running with a list of vectors

template_list = apply(template, 1, identity, simplify = FALSE)
class(template_list)
#> [1] "list"
length(template_list)
#> [1] 2

out_lw <- segmentWalking(
  xyz = xyz,
  xyz.fs = 100,
  template = template_list,
  compute.template.idx = TRUE)
out_lw %>% 
  count(template_i)
#>   template_i   n
#> 1          1 148
#> 2          2  50

Created on 2023-08-09 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.1 (2022-06-23)
#>  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       America/New_York
#>  date     2023-08-09
#>  pandoc   3.1.5 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  adept       * 1.2     2021-02-01 [1] CRAN (R 4.2.0)
#>  adeptdata   * 1.1     2021-03-28 [1] CRAN (R 4.2.0)
#>  cli           3.6.1   2023-03-23 [1] CRAN (R 4.2.0)
#>  colorspace    2.1-0   2023-01-23 [1] CRAN (R 4.2.0)
#>  data.table    1.14.8  2023-02-17 [1] CRAN (R 4.2.0)
#>  DBI           1.1.3   2022-06-18 [1] CRAN (R 4.2.0)
#>  digest        0.6.33  2023-07-07 [1] CRAN (R 4.2.0)
#>  dplyr       * 1.1.2   2023-04-20 [1] CRAN (R 4.2.0)
#>  dvmisc        1.1.4   2019-12-16 [1] CRAN (R 4.2.0)
#>  evaluate      0.21    2023-05-05 [1] CRAN (R 4.2.0)
#>  fansi         1.0.4   2023-01-22 [1] CRAN (R 4.2.0)
#>  fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.2.0)
#>  fs            1.6.3   2023-07-20 [1] CRAN (R 4.2.0)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.2.0)
#>  ggplot2       3.4.2   2023-04-03 [1] CRAN (R 4.2.0)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
#>  gtable        0.3.3   2023-03-21 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.5   2023-03-23 [1] CRAN (R 4.2.0)
#>  httr          1.4.6   2023-05-08 [1] CRAN (R 4.2.0)
#>  kableExtra    1.3.4   2021-02-20 [1] CRAN (R 4.2.0)
#>  knitr         1.43    2023-05-25 [1] CRAN (R 4.2.0)
#>  lattice       0.21-8  2023-04-05 [1] CRAN (R 4.2.0)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.2.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
#>  MASS          7.3-60  2023-05-04 [1] CRAN (R 4.2.0)
#>  Matrix        1.6-0   2023-07-08 [1] CRAN (R 4.2.1)
#>  mitools       2.4     2019-04-26 [1] CRAN (R 4.2.0)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.2.0)
#>  mvtnorm       1.2-2   2023-06-08 [1] CRAN (R 4.2.0)
#>  pillar        1.9.0   2023-03-22 [1] CRAN (R 4.2.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.0)
#>  pracma        2.4.2   2022-09-22 [1] CRAN (R 4.2.0)
#>  purrr         1.0.1   2023-01-10 [1] CRAN (R 4.2.0)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.2.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils       2.12.2  2022-11-11 [1] CRAN (R 4.2.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
#>  rbenchmark    1.0.0   2012-08-30 [1] CRAN (R 4.2.0)
#>  Rcpp          1.0.11  2023-07-06 [1] CRAN (R 4.2.0)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.2.0)
#>  rlang         1.1.1   2023-04-28 [1] CRAN (R 4.2.0)
#>  rmarkdown     2.23    2023-07-01 [1] CRAN (R 4.2.0)
#>  rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.2.0)
#>  rvest         1.0.3   2022-08-19 [1] CRAN (R 4.2.0)
#>  scales        1.2.1   2022-08-20 [1] CRAN (R 4.2.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi       1.7.12  2023-01-11 [1] CRAN (R 4.2.0)
#>  stringr       1.5.0   2022-12-02 [1] CRAN (R 4.2.0)
#>  styler        1.10.1  2023-06-05 [1] CRAN (R 4.2.0)
#>  survey        4.2-1   2023-05-03 [1] CRAN (R 4.2.0)
#>  survival      3.5-5   2023-03-12 [1] CRAN (R 4.2.0)
#>  svglite       2.1.1   2023-01-10 [1] CRAN (R 4.2.0)
#>  systemfonts   1.0.4   2022-02-11 [1] CRAN (R 4.2.0)
#>  tab           5.1.1   2021-08-02 [1] CRAN (R 4.2.0)
#>  tibble        3.2.1   2023-03-20 [1] CRAN (R 4.2.0)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.2.0)
#>  utf8          1.2.3   2023-01-31 [1] CRAN (R 4.2.0)
#>  vctrs         0.6.3   2023-06-14 [1] CRAN (R 4.2.0)
#>  viridisLite   0.4.2   2023-05-02 [1] CRAN (R 4.2.0)
#>  webshot       0.5.5   2023-06-26 [1] CRAN (R 4.2.0)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.39    2023-04-20 [1] CRAN (R 4.2.0)
#>  xml2          1.3.5   2023-07-06 [1] CRAN (R 4.2.0)
#>  yaml          2.3.7   2023-01-23 [1] CRAN (R 4.2.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
This was referenced Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant