Last updated: 2022-06-06
Checks: 7 0
Knit directory: gsmash/
This reproducible R Markdown analysis was created with workflowr (version 1.7.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(20220606)
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 06b638b. 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
Untracked files:
Untracked: analysis/normal_mean_penalized_optimization.Rmd
Untracked: analysis/poisson_mean_loglik_expansion.Rmd
Untracked: analysis/poisson_mean_loglik_expansion_optim.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 repository in which changes were
made to the R Markdown (analysis/log_lmm_concave.Rmd
) and
HTML (docs/log_lmm_concave.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 | 06b638b | Dongyue Xie | 2022-06-06 | Publish the initial files for myproject |
Plot log of density function
\[g(x) = \sum_k w_k \text{Laplace}(x;0,\sigma^2_k).\]
A concave function \(f(\cdot)\) satisfies for any \(\alpha\in[0,1]\),
\[f((1-\alpha)x+\alpha y)\geq (1-\alpha)f(x)+\alpha f(y)\]
#'density of laplace distribution x~Laplace(mu,b)
dlap = function(x,mu,b){
return(1/2/b*exp(-abs(x-mu)/b))
}
#'density of log g(x)
#'x is a scalar
lg = function(x,w,s2){
return(log(sum(w*dlap(x,0,s2))))
}
#'density of log g(x)
#'x is a vector
lg_vec = function(x,w,s2){
n = length(x)
out = rep(0,n)
for(i in 1:n){
out[i] = lg(x[i],w,s2)
}
return(out)
}
plot_lg = function(x,w,s2){
plot(x,lg_vec(x,w,s2),type='l',xlab='x',ylab='log(g)',
main=paste('w=(',paste(w,collapse = ", "),'); s2=(',paste(s2,collapse = ", "),')',sep=''))
}
lg_p = expression(log(w1*1/2/b1*exp(-x/b1)+w2*1/2/b2*exp(-x/b2)))
lg_n = expression(log(w1*1/2/b1*exp(x/b1)+w2*1/2/b2*exp(x/b2)))
lg2_p = D(D(lg_p,'x'),'x')
lg2_n = D(D(lg_n,'x'),'x')
plot_lg_d2 = function(r,w1,
b1 = 0.1,
b2 = 2){
w2 = 1-w1
xx = c()
x = seq(-r,0,length.out = 500)
xx = c(xx,x)
y_n = eval(lg2_n)
x = seq(0,r,length.out = 500)
xx = c(xx,x)
y_p = eval(lg2_p)
plot(xx,c(y_n,y_p),type='l',ylab="(log g)''",xlab='x')
print(range(c(y_n,y_p)))
}
x = seq(-5,5,length.out = 1000)
w = c(0.9,0.1)
s2 = c(0.1,3)
plot_lg(x,w,s2)
plot_lg_d2(5,w[1],s2[1],s2[2])
[1] 1.387779e-17 2.335889e+01
x = seq(-5,5,length.out = 1000)
w = c(0.1,0.9)
s2 = c(0.1,3)
plot_lg(x,w,s2)
plot_lg_d2(5,w[1],s2[1],s2[2])
[1] -2.775558e-17 2.335098e+01
#'softmax
softmax = function(a){
exp(a-max(a))/sum(exp(a-max(a)))
}
s2 = exp(seq(-8,5,by=log(2)))
w = softmax(log(1/s2))
#plot(w,type='l')
#plot(s2,type='l')
plot_lg(x,w,s2)
more cases, let mixture components be close
x = seq(-20,20,length.out = 1000)
w = c(0.5,0.5)
s2 = c(2,3)
plot_lg(x,w,s2)
plot_lg_d2(20,w[1],s2[1],s2[2])
[1] 0.001339252 0.006944437
x = seq(-20,20,length.out = 1000)
w = c(0.1,0.9)
s2 = c(2,3)
plot_lg(x,w,s2)
plot_lg_d2(20,w[1],s2[1],s2[2])
[1] 0.0001632108 0.0034013605
x = seq(-20,20,length.out = 1000)
w = c(0.5,0.5)
s2 = c(2.9,3)
plot_lg(x,w,s2)
plot_lg_d2(20,w[1],s2[1],s2[2])
[1] 3.271432e-05 3.302946e-05
sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur/Monterey 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/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] workflowr_1.7.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8.3 highr_0.9 bslib_0.3.1 compiler_4.2.0
[5] pillar_1.7.0 later_1.3.0 git2r_0.30.1 jquerylib_0.1.4
[9] tools_4.2.0 getPass_0.2-2 digest_0.6.29 jsonlite_1.8.0
[13] evaluate_0.15 tibble_3.1.6 lifecycle_1.0.1 pkgconfig_2.0.3
[17] rlang_1.0.2 cli_3.3.0 rstudioapi_0.13 yaml_2.3.5
[21] xfun_0.30 fastmap_1.1.0 httr_1.4.2 stringr_1.4.0
[25] knitr_1.38 sass_0.4.1 fs_1.5.2 vctrs_0.4.1
[29] rprojroot_2.0.3 glue_1.6.2 R6_2.5.1 processx_3.5.3
[33] fansi_1.0.3 rmarkdown_2.13 callr_3.7.0 magrittr_2.0.3
[37] whisker_0.4 ps_1.7.0 promises_1.2.0.1 htmltools_0.5.2
[41] ellipsis_0.3.2 httpuv_1.6.5 utf8_1.2.2 stringi_1.7.6
[45] crayon_1.5.1