Title: | Bayesian Spatial Blind Source Separation |
---|---|
Description: | Gibbs sampling for Bayesian spatial blind source separation (BSP-BSS). BSP-BSS is designed for spatially dependent signals in high dimensional and large-scale data, such as neuroimaging. The method assumes the expectation of the observed images as a linear mixture of multiple sparse and piece-wise smooth latent source signals, and constructs a Bayesian nonparametric prior by thresholding Gaussian processes. Details can be found in our paper: Wu et al. (2022+) "Bayesian Spatial Blind Source Separation via the Thresholded Gaussian Process" <doi:10.1080/01621459.2022.2123336>. |
Authors: | Ben Wu [aut, cre], Ying Guo [aut], Jian Kang [aut] |
Maintainer: | Ben Wu <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.5 |
Built: | 2024-10-31 06:52:39 UTC |
Source: | CRAN |
Generate initial values, set up priors and perform kernel decomposition for the MCMC algorithm.
init_bspbss( X, coords, rescale = TRUE, center = FALSE, q = 2, dens = 0.5, ker_par = c(0.05, 20), num_eigen = 500, noise = 0 )
init_bspbss( X, coords, rescale = TRUE, center = FALSE, q = 2, dens = 0.5, ker_par = c(0.05, 20), num_eigen = 500, noise = 0 )
X |
Data matrix with n rows (sample) and p columns (voxel). |
coords |
Cordinate matrix with p rows (voxel) and d columns (dimension). |
rescale |
If TRUE, rows of X are rescaled to have unit variance. |
center |
If TRUE, rows of X are mean-centered. |
q |
Number of latent sources. |
dens |
The initial density level (between 0 and 1) of the latent sources. |
ker_par |
2-dimensional vector (a,b) with a>0, b>0, specifing the parameters in the modified exponetial squared kernel. |
num_eigen |
Number of eigen functions. |
noise |
Gaussian noise added to the initial latent sources, with mean 0 and standard deviation being noise * sd(S0), where sd(S0) is the standard deviation of the initial latent sources. |
List containing initial values, priors and eigen functions/eigen values of the kernel of the Gaussian process.
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6) ini = init_bspbss(sim$X, sim$coords, q = 3, ker_par = c(0.1,50), num_eigen = 50)
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6) ini = init_bspbss(sim$X, sim$coords, q = 3, ker_par = c(0.1,50), num_eigen = 50)
The function plots 2D images for a data matrix.
levelplot2D( S, coords, lim = c(min(S), max(S)), xlim = c(0, max(coords[, 1])), ylim = c(0, max(coords[, 2])), color = bluered(100), layout = c(1, nrow(S)), file = NULL )
levelplot2D( S, coords, lim = c(min(S), max(S)), xlim = c(0, max(coords[, 1])), ylim = c(0, max(coords[, 2])), color = bluered(100), layout = c(1, nrow(S)), file = NULL )
S |
Data matrix with q rows (sample) and p colums (pixel). |
coords |
Coordinates matrix with p rows (pixel) and 2 columns (dimension), specifying the coordinates of the data points. |
lim |
2-dimensional numeric vector, specifying the limits for the data. |
xlim |
2-dimensional numeric vector, specifying the lower and upper limits of |
ylim |
2-dimensional numeric vector, specifying the lower and upper limits of |
color |
Colorbar. |
layout |
2-dimensional numeric vector, specifying the number of rows and number of columns for the layout of components. |
file |
Name of the file to be saved. |
No return value.
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6) levelplot2D(sim$S,lim = c(-0.04,0.04), sim$coords)
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6) levelplot2D(sim$S,lim = c(-0.04,0.04), sim$coords)
Performan MCMC algorithm to draw samples from a Bayesian spatial blind source separation model.
mcmc_bspbss( X, init, prior, kernel, n.iter, n.burn_in, thin = 1, show_step, ep = 0.01, lr = 0.01, decay = 0.01, num_leapfrog = 5, subsample_n = 0.5, subsample_p = 0.5 )
mcmc_bspbss( X, init, prior, kernel, n.iter, n.burn_in, thin = 1, show_step, ep = 0.01, lr = 0.01, decay = 0.01, num_leapfrog = 5, subsample_n = 0.5, subsample_p = 0.5 )
X |
Data matrix with n rows (sample) and p columns (voxel). |
init |
List of initial values, see |
prior |
List of priors, see |
kernel |
List including eigenvalues and eigenfunctions of the kernel, see |
n.iter |
Total iterations in MCMC. |
n.burn_in |
Number of burn-in. |
thin |
Thining interval. |
show_step |
Frequency for printing the current number of iterations. |
ep |
Approximation parameter. |
lr |
Per-batch learning rate in SGHMC. |
decay |
Decay parameter in SGHMC. |
num_leapfrog |
Number of leapfrog steps in SGHMC. |
subsample_n |
Mini-batch size of samples. |
subsample_p |
Mini-batch size of voxels. |
List containing MCMC samples of: A, b, sigma, and zeta.
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6) ini = init_bspbss(sim$X, sim$coords, q = 3, ker_par = c(0.1,50), num_eigen = 50) res = mcmc_bspbss(ini$X,ini$init, ini$prior,ini$kernel, n.iter=200,n.burn_in=100, thin=10,show_step=50)
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6) ini = init_bspbss(sim$X, sim$coords, q = 3, ker_par = c(0.1,50), num_eigen = 50) res = mcmc_bspbss(ini$X,ini$init, ini$prior,ini$kernel, n.iter=200,n.burn_in=100, thin=10,show_step=50)
This function saves a data matrix into a NIfTI file.
output_nii(X, nii, xgrid, file = NULL, std = TRUE, thres = 0)
output_nii(X, nii, xgrid, file = NULL, std = TRUE, thres = 0)
X |
Data matrix with n rows (sample) and p colums (pixel). |
nii |
a reference NIfTI-class object, representing a image with p voxels. |
xgrid |
Cordinate matrix with p rows (voxel) and d columns (dimension). |
file |
The name of the file to be saved. |
std |
If TRUE, standarize each row of X. |
thres |
Quantile to threshold each row of X. |
NIfTI-class object.
This function transforms a NIfTI-class object into a matrix.
pre_nii(nii, mask)
pre_nii(nii, mask)
nii |
4D NIfTI-class object with dimensions x,y,z and t. Can be read from NIfTI file with |
mask |
Mask variable, also in NIfTI format. |
List containing the data matrix with t rows and x*y*z colums (voxels), and the coordinates of the voxels.
The function simulates image data using a probabilistic ICA model whose latent components have specific spatial patterns.
sim_2Dimage(length = 20, n = 50, sigma = 0.002, smooth = 6)
sim_2Dimage(length = 20, n = 50, sigma = 0.002, smooth = 6)
length |
The length of the image. |
n |
sample size. |
sigma |
variance of the noise. |
smooth |
smoothness of the latent components. |
The observations are generated using probabilistic ICA:
where are the latent components,
is
the mixing coeffecient and
is the noise term.
Specifically, the number of components in this function is
,
with each of them being a specific geometric shape. The mixing coefficient matrix
is generated with a von Mises-Fisher distribution with the concentration parameter
being zero, which means it is uniformly distributed on the sphere.
is a i.i.d. Gaussian noise term with 0 mean and user-specified variance.
List that contains the following terms:
Data matrix with n rows (sample) and p columns (pixel).
Cordinate matrix with p rows (pixel) and d columns (dimension)
Latent components.
Mixing coefficent matrix.
Signal-to-noise ratio.
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6)
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6)
The function summarizes the MCMC results obtained from mcmc_bspbss
.
sum_mcmc_bspbss(res, X, kernel, start = 1, end = 100, select_prob = 0.8)
sum_mcmc_bspbss(res, X, kernel, start = 1, end = 100, select_prob = 0.8)
res |
List including MCMC samples, which can be obtained from function |
X |
Original data matrix. |
kernel |
List including eigenvalues and eigenfunctions of the kernel, see |
start |
Start point of the iterations being summarized. |
end |
End point of the iterations being summarized. |
select_prob |
Lower bound of the posterior inclusion probability required when summarizing the samples of latent sources. |
List that contains the following terms:
Estimated latent sources.
Voxel-wise posterior inclusion probability for the latent sources.
Estimated mixing coefficent matrix.
Estimated zeta.
Estimated sigma.
Trace of log-likelihood.
MCMC samples of S.
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6) ini = init_bspbss(sim$X, sim$coords, q = 3, ker_par = c(0.1,50), num_eigen = 50) res = mcmc_bspbss(ini$X,ini$init,ini$prior,ini$kernel,n.iter=200,n.burn_in=100,thin=10,show_step=50) res_sum = sum_mcmc_bspbss(res, ini$X, ini$kernel, start = 11, end = 20, select_p = 0.5)
sim = sim_2Dimage(length = 30, sigma = 5e-4, n = 30, smooth = 6) ini = init_bspbss(sim$X, sim$coords, q = 3, ker_par = c(0.1,50), num_eigen = 50) res = mcmc_bspbss(ini$X,ini$init,ini$prior,ini$kernel,n.iter=200,n.burn_in=100,thin=10,show_step=50) res_sum = sum_mcmc_bspbss(res, ini$X, ini$kernel, start = 11, end = 20, select_p = 0.5)