Last updated: 2021-07-11

Checks: 7 0

Knit directory: VSA_altitude_hold/

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(20210617) 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 e040157. 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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    renv/library/
    Ignored:    renv/staging/

Unstaged changes:
    Modified:   R/functions.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/vsa_basic_operators.Rmd) and HTML (docs/vsa_basic_operators.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 e040157 Ross Gayler 2021-07-11 WIP

This notebook characterises data generated by the simulation of the classically implemented altitude hold controller. We need to understand the properties of the signals in order to design VSA implementations of them.

The values to be characterised are all the real scalars corresponding to the nodes in the data flow diagram for Design 01.

# function to add (weighted sum) an arbitrary number of VSA vectors
# Weighted add is implemented as weighted sampling from the source vectors

vsa_add <- function(
  vec_list, # list of >= 2 VSA vectors of identical dimension
  wt = rep(1, length.out = length(vec_list)), # vector of sampling weights
  seed = NULL # seed for reproducibility of random sampling
) # value # one VSA vector, the weighted sum (sample) of the argument vectors
{
  # OCD error checking that is mores useful as documentation
  if(!is.list(vec_list)) 
    stop("source VSA vectors must be supplied as a list")
  
  if(length(vec_list) < 2) 
    stop("number of source VSA vectors must be >= 2")
  
  if(!all(sapply(vec_list, is.vector, mode = "integer"))) 
    stop("all source VSA vectors must be integer vectors")
  
  if(!all(length(vec_list[[1]]) == sapply(vec_list, length)))
    stop("all source VSA vectors must have the same length")
  
  # if(length(wt) != length(vec_list))
  #   stop("number of weights must equal number of source VSA vectors")
  
  if(min(wt) < 0)
    stop("all weights must be >= 0")
  
  if(max(wt) <= 0)
    stop("at least one weight must be > 0")
  
  # for each element of the result work out which source VSA to sample
  vsa_dim <- length(vec_list[[1]])
  
  # if a seed is specified the save and restore the RNG state
  # copied and modified from http://www.cookbook-r.com/Numbers/Saving_the_state_of_the_random_number_generator/#saving-and-restoring-the-state-of-the-rng-in-functions
  if(!is.null(seed) && exists(".Random.seed", .GlobalEnv))
  {
    oldseed <- .GlobalEnv$.Random.seed
    set.seed(seed)
  }
  else
    oldseed <- NULL
  
  vsa_source <- sample.int(length(vec_list), size = vsa_dim, replace = TRUE, prob = wt)
  
  if (!is.null(oldseed)) 
      .GlobalEnv$.Random.seed <- oldseed
    # else
    #   rm(".Random.seed", envir = .GlobalEnv)
  
  vsa_source

}

sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 21.04

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] here_1.0.1 fs_1.5.0  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        whisker_0.4       knitr_1.33        magrittr_2.0.1   
 [5] workflowr_1.6.2   R6_2.5.0          rlang_0.4.11      fansi_0.5.0      
 [9] stringr_1.4.0     tools_4.1.0       xfun_0.24         utf8_1.2.1       
[13] git2r_0.28.0      htmltools_0.5.1.1 ellipsis_0.3.2    rprojroot_2.0.2  
[17] yaml_2.2.1        digest_0.6.27     tibble_3.1.2      lifecycle_1.0.0  
[21] bookdown_0.22     crayon_1.4.1      later_1.2.0       vctrs_0.3.8      
[25] promises_1.2.0.1  glue_1.4.2        evaluate_0.14     rmarkdown_2.9    
[29] stringi_1.6.2     compiler_4.1.0    pillar_1.6.1      httpuv_1.6.1     
[33] renv_0.13.2       pkgconfig_2.0.3