Last updated: 2019-10-15

Checks: 7 0

Knit directory: ebpmf_demo/

This reproducible R Markdown analysis was created with workflowr (version 1.4.0). 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(20190923) 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 version displayed above was the version of the Git repository at the time these results were generated.

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/

Untracked files:
    Untracked:  analysis/.ipynb_checkpoints/
    Untracked:  analysis/ebpmf_demo.Rmd
    Untracked:  analysis/ebpmf_rank1_demo2.Rmd
    Untracked:  analysis/softmax_experiments.ipynb
    Untracked:  data/trash/
    Untracked:  docs/figure/Experiment_ebpmf_rankk.Rmd/
    Untracked:  docs/figure/test.Rmd/

Unstaged changes:
    Modified:   analysis/ebpmf_rank1_demo.Rmd
    Modified:   analysis/ebpmf_rankk_demo.Rmd
    Modified:   analysis/softmax_experiments.Rmd

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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
Rmd 95f7212 zihao12 2019-10-15 rank1 issue

Issues

In my experiments with rank-1 ebpmf-point-gamma, I observe the following things (reproduced below):
* After the first iteration, ELBO only has small changes (not monotonic!!) and \(\sum_i <l_i>\), \(\sum_j <f_j>\) also only has small changes.
* Different initialization results in similar ELBO (though estimates for L, F are very different individually) adn similar estimate of \(\Lambda\)

Discussion

  • first, after writing down the update euqation for \(s : =\sum_i <l_i>\), it should be changing each iteration (it is a very complicated form). If we simplify and suppose the point mass at 0 are all 0, we have \[s_{t+1} = \frac{n a_L + \sum_{ij} X_{ij}}{b_L + \frac{pa_F + \sum_{ij} X_{ij}}{b_F + s_t}}\] As in our data we have \(\sum_{ij} X_{ij >>n a_L, pa_F}\) and \(s >> b_L, b_F\), we can see \(s_{t+1} \approx s_t\). But analytically we cannot draw the equivalence. Thus the changes in ELBO probably are not just due to numerical issues, and we need to checkj if the ELBO is wrong.\

  • we can draw the connection to the EM for the MLE of PMF (lee’s multiplicative update). In the rank one case, we can arrive at optimal in one step. Why? Since, given \(f_j\)s, the optimal \(l_i\) is \(l_i = \frac{\sum_j X_{ij}}{\sum_j f_{j}}\). This is equivalent to the MLE for the poisson mean problem, where \(x_i := \sum_j X_{ij}\) and \(s_i := \sum_j f_j\). Then we can easily see that \(\sum_i l_i\), \(\sum_j f_j\) stays the same throught iterations, so \(l_i, f_j\) will not be changing after the first iteration. But in ebpmf-point-gamma, we have a nonlinear shrinkage operator on the the MLE result, so we don’t expect to see the same constant bahavior here.

rm(list  = ls())

library(NNLM)
#library(gtools)
#library(ebpmf)

simulate_data <- function(n, p, K, params, seed = 123){
  set.seed(seed)
  L = matrix(rgamma(n = n*K, shape = params$al, rate = params$bl), ncol = K)
  F = matrix(rgamma(n = p*K, shape = params$af, rate = params$bf), ncol = K)
  Lam =  L %*% t(F)
  X = matrix(rpois(n*p, Lam), nrow = n)
  Y = matrix(rpois(n*p, Lam), nrow = n)
  return(list(params = params,Lam = Lam,X = X, Y = Y))
}

n = 100
p = 200
K = 5
params = list(al = 10, bl =  10, af = 10, bf = 10, a = 1)


sim = simulate_data(n, p, K, params)

init1 = list(mean = runif(n, 0, 1))
init100 = list(mean = 100*runif(n, 0, 1))
out_ebpmf1 = ebpmf::ebpmf_rank1_point_gamma(sim$X, maxiter = 10, init = init1, verbose = T)
[1] "iter              ELBO             KL_L              KL_F           sum_El           sum_Ef"
[1] " 1 -511495.957052  568708.0442338070  213.2413395753 49.3418228878 1957.9536062943"
[1] " 2 -511495.957052  568708.0442340682  213.2413395758 49.3418228693 1957.9536071596"
[1] " 3 -511495.957052  568708.0442340955  213.2413395651 49.3418228959 1957.9536060949"
[1] " 4 -511495.957676  568708.0454792172  213.2413395722 49.3418229227 1957.9536051548"
[1] " 5 -511495.957051  568708.0442301770  213.2413395485 49.3418263234 1957.9534701104"
[1] " 6 -511495.957052  568708.0442337667  213.2413395706 49.3418263465 1957.9534691747"
[1] " 7 -511495.957052  568708.0442341160  213.2413395621 49.3418263724 1957.9534681764"
[1] " 8 -511495.957053  568708.0442341956  213.2413395700 49.3418263994 1957.9534670471"
[1] " 9 -511495.957696  568708.0455181362  213.2413395641 49.3418264274 1957.9534660565"
[1] "10 -511495.957052  568708.0442340459  213.2413395680 49.3418318155 1957.9532522913"
out_ebpmf100 = ebpmf::ebpmf_rank1_point_gamma(sim$X, maxiter = 10, init = init100, verbose = T)
[1] "iter              ELBO             KL_L              KL_F           sum_El           sum_Ef"
[1] " 1 -511495.957252  568708.0450631959  213.2413423988 4705.7240442140 20.5301032735"
[1] " 2 -511495.957252  568708.0450622196  213.2412989758 4705.7241134741 20.5301017279"
[1] " 3 -511495.956826  568708.0442109936  213.2413422507 4705.7244674216 20.5301014132"
[1] " 4 -511495.957252  568708.0450626983  213.2413418952 4705.7244714504 20.5301014106"
[1] " 5 -511495.957252  568708.0450628576  213.2413424034 4705.7245406111 20.5301011088"
[1] " 6 -511495.957253  568708.0450643523  213.2413424149 4705.7246100241 20.5301008050"
[1] " 7 -511495.957252  568708.0450631579  213.2413309093 4705.7246793734 20.5301008415"
[1] " 8 -511495.957252  568708.0450627547  213.2413424975 4705.7246710149 20.5301005235"
[1] " 9 -511495.957253  568708.0450639572  213.2413423800 4705.7247441811 20.5301002223"
[1] "10 -511495.957252  568708.0450622501  213.2413288995 4705.7248132644 20.5300996850"

Let’s see compare the posterior estimate of \(\Lambda\) from different initializations.

lam1 = out_ebpmf1$ql$mean %*% t(out_ebpmf1$qf$mean)

lam100 = out_ebpmf100$ql$mean %*% t(out_ebpmf100$qf$mean)

max(abs((lam1 - lam100)/(lam1 + lam100)))
[1] 2.331426e-06

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14

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

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

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

other attached packages:
[1] NNLM_0.4.2

loaded via a namespace (and not attached):
 [1] workflowr_1.4.0 Rcpp_1.0.2      gtools_3.8.1    digest_0.6.21  
 [5] rprojroot_1.3-2 ebpmf_0.1.0     backports_1.1.5 git2r_0.25.2   
 [9] magrittr_1.5    evaluate_0.14   ebpm_0.0.0.9001 stringi_1.4.3  
[13] fs_1.3.1        whisker_0.3-2   rmarkdown_1.13  tools_3.5.1    
[17] stringr_1.4.0   glue_1.3.1      mixsqp_0.1-121  xfun_0.8       
[21] yaml_2.2.0      compiler_3.5.1  htmltools_0.3.6 knitr_1.25