BSPBSS-vignette

library(BSPBSS)

A toy example

This is a basic example which shows you how to solve a common problem.

First we load the package and generate simulated images with a probabilistic ICA model:

library(BSPBSS)
set.seed(612)
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6)

The true source signals are three 2D geometric patterns (set smooth=0 to generate patterns with sharp edges).

levelplot2D(sim$S,lim = c(-0.04,0.04), sim$coords)
#> Warning: Removed 177 rows containing missing values or values outside the scale range
#> (`geom_tile()`).

which generate observed images such as

levelplot2D(sim$X[1:3,], lim = c(-0.12,0.12), sim$coords)
#> Warning: Removed 177 rows containing missing values or values outside the scale range
#> (`geom_tile()`).

Then we generate initial values for mcmc,

ini = init_bspbss(sim$X, sim$coords, q = 3, ker_par = c(0.1,50), num_eigen = 50)

and run!

res = mcmc_bspbss(ini$X,ini$init,ini$prior,ini$kernel,n.iter=2000,n.burn_in=1000,thin=10,show_step=100)
#> iter 100 Thu Oct 31 06:52:32 2024
#> 
#> zeta0.122581 stepsize_zeta 0.00712258 accp_rate_zeta 0.37
#> iter 200 Thu Oct 31 06:52:32 2024
#> 
#> zeta0.211029 stepsize_zeta 0.00783484 accp_rate_zeta 0.37
#> iter 300 Thu Oct 31 06:52:32 2024
#> 
#> zeta0.197884 stepsize_zeta 0.00861832 accp_rate_zeta 0.4
#> iter 400 Thu Oct 31 06:52:32 2024
#> 
#> zeta0.171109 stepsize_zeta 0.00948015 accp_rate_zeta 0.43
#> iter 500 Thu Oct 31 06:52:33 2024
#> 
#> zeta0.249452 stepsize_zeta 0.0104282 accp_rate_zeta 0.36
#> iter 600 Thu Oct 31 06:52:33 2024
#> 
#> zeta0.210928 stepsize_zeta 0.011471 accp_rate_zeta 0.33
#> iter 700 Thu Oct 31 06:52:33 2024
#> 
#> zeta0.184828 stepsize_zeta 0.0126181 accp_rate_zeta 0.33
#> iter 800 Thu Oct 31 06:52:33 2024
#> 
#> zeta0.216677 stepsize_zeta 0.0138799 accp_rate_zeta 0.32
#> iter 900 Thu Oct 31 06:52:34 2024
#> 
#> zeta0.176593 stepsize_zeta 0.0152679 accp_rate_zeta 0.32
#> iter 1000 Thu Oct 31 06:52:34 2024
#> 
#> zeta0.20419 stepsize_zeta 0.0167947 accp_rate_zeta 0.25
#> iter 1100 Thu Oct 31 06:52:34 2024
#> 
#> zeta0.172148 stepsize_zeta 0.0167947 accp_rate_zeta 0.24
#> iter 1200 Thu Oct 31 06:52:34 2024
#> 
#> zeta0.143202 stepsize_zeta 0.0167947 accp_rate_zeta 0.26
#> iter 1300 Thu Oct 31 06:52:35 2024
#> 
#> zeta0.152024 stepsize_zeta 0.0167947 accp_rate_zeta 0.22
#> iter 1400 Thu Oct 31 06:52:35 2024
#> 
#> zeta0.183014 stepsize_zeta 0.0167947 accp_rate_zeta 0.18
#> iter 1500 Thu Oct 31 06:52:35 2024
#> 
#> zeta0.231091 stepsize_zeta 0.0167947 accp_rate_zeta 0.28
#> iter 1600 Thu Oct 31 06:52:35 2024
#> 
#> zeta0.171254 stepsize_zeta 0.0167947 accp_rate_zeta 0.25
#> iter 1700 Thu Oct 31 06:52:36 2024
#> 
#> zeta0.17859 stepsize_zeta 0.0167947 accp_rate_zeta 0.33
#> iter 1800 Thu Oct 31 06:52:36 2024
#> 
#> zeta0.190647 stepsize_zeta 0.0167947 accp_rate_zeta 0.31
#> iter 1900 Thu Oct 31 06:52:36 2024
#> 
#> zeta0.217872 stepsize_zeta 0.0167947 accp_rate_zeta 0.22
#> iter 2000 Thu Oct 31 06:52:36 2024
#> 
#> zeta0.242055 stepsize_zeta 0.0167947 accp_rate_zeta 0.32

Then the results can be summarized by

res_sum = sum_mcmc_bspbss(res, ini$X, ini$kernel, start = 101, end = 200, select_p = 0.5)

and shown by

levelplot2D(res_sum$S, lim = c(-1.3,1.3), sim$coords)
#> Warning: Removed 177 rows containing missing values or values outside the scale range
#> (`geom_tile()`).

For comparison, we show the estimated sources provided by informax ICA here.

levelplot2D(ini$init$ICA_S, lim = c(-1.7,1.7), sim$coords)
#> Warning: Removed 177 rows containing missing values or values outside the scale range
#> (`geom_tile()`).