Let’s improve the initialization methods for the the Markov Chain. The idea is to give up on respecting maximum constraints for the heterogeneous and homogeneous methods. Also, we want to generate homogeneous matrices with the lowest variance.
sum_row <- round(200 * rexp(10))
mat_homo_old <- generate_matrix_homo_old(sum_row)
mat_homo <- generate_matrix_homo(sum_row)
mat_homo_better <- generate_matrix_homo_better(sum_row)
mat_hetero <- generate_matrix_hetero(sum_row)
mat_prop <- generate_matrix_prop(sum_row)
sapply(list(mat_homo_old, mat_homo, mat_homo_better, mat_hetero, mat_prop),
function(x) var(c(x)))
## [1] 1600.6925 720.5511 717.0562 5117.2178 846.5309
The new method is fast (usable) and meets the objectives.
## R version 3.4.3 (2017-11-30)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.4 LTS
##
## Matrix products: default
## BLAS: /usr/lib/openblas-base/libblas.so.3
## LAPACK: /usr/lib/libopenblasp-r0.2.18.so
##
## locale:
## [1] LC_CTYPE=fr_FR.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=fr_FR.UTF-8 LC_COLLATE=fr_FR.UTF-8
## [5] LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=fr_FR.UTF-8
## [7] LC_PAPER=fr_FR.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] bindrcpp_0.2 ggplot2_2.2.1 dplyr_0.7.4 tidyr_0.2.0 purrr_0.2.4
## [6] stringr_1.2.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.10 knitr_1.15.1 bindr_0.1 magrittr_1.5
## [5] munsell_0.4 colorspace_1.2-2 R6_2.1.0 rlang_0.1.6
## [9] plyr_1.8.1 tools_3.4.3 grid_3.4.3 gtable_0.1.2
## [13] pacman_0.4.6 htmltools_0.3.6 lazyeval_0.2.0 yaml_2.1.13
## [17] rprojroot_1.2 digest_0.6.3 assertthat_0.1 tibble_1.3.1
## [21] glue_1.2.0 evaluate_0.10 rmarkdown_1.8 stringi_0.5-5
## [25] compiler_3.4.3 scales_0.4.1 backports_1.0.5 pkgconfig_2.0.1