samplePosteriorLGLFM: Sample from the Posterior Distribution of the Linear Gaussian...

Description Usage Arguments Details Examples

View source: R/samplePosteriorLGLFM.R

Description

This function samples from the posterior distribution of the linear Gaussian latent feature model (LGLFM) using an Indian buffet process (IBP) or an Attraction Indian Buffet Distribution (AIBD) prior over possible feature allocations.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
samplePosteriorLGLFM(
  featureAllocation,
  distribution,
  X,
  precisionX,
  precisionA,
  sdX = 1/sqrt(precisionX),
  sdA = 1/sqrt(precisionA),
  massPriorShape = -1,
  massPriorRate = -1,
  nPerShuffle = 0L,
  temperaturePriorShape = -1,
  temperaturePriorRate = -1,
  maxStandardDeviationX = sd(X),
  maxStandardDeviationA = maxStandardDeviationX,
  sdProposedTemperature = -1,
  sdProposedStandardDeviationX = -1,
  sdProposedStandardDeviationA = -1,
  corProposedSdXSdA = 0,
  newFeaturesTruncationDivisor = 1000,
  nOtherUpdatesPerAllocationUpdate = 10L,
  nSamples = 1L,
  thin = 1L,
  rankOneUpdates = FALSE,
  verbose = TRUE
)

Arguments

featureAllocation

An N-by-K binary feature allocation matrix.

distribution

A prior distribution of feature allocations, i.e., a result from ibp or aibd.

X

An N-by-D matrix of observed data.

precisionX

The scalar precision of the data error variance. This must be specified if sdX is missing.

precisionA

The scalar precision of a latent feature. This must be specified if sdA is missing.

sdX

The scalar standard deviation of the data error variance. This must be specified if precisionX is missing.

sdA

The scalar precision of a latent feature. This must be specified if precisionA is missing.

massPriorShape

Shape parameter of the gamma prior on the mass parameter, where the prior expected value is massPriorShape/massPriorRate. If either massPriorShape or massPriorRate is set to -1, then the mass parameter is assumed to be fixed (as defined in the aibd object).

massPriorRate

Rate parameter of the gamma prior on the mass parameter, where the expected value if massPriorShape/massPriorRate.

nPerShuffle

Number of items to randomly select and permute when proposing an update to the permutation associated with the attraction Indian buffet distribution (AIBD). The prior on the permutation is the discrete uniform, but one can set nPerShuffle to an integer less than 2 to effectively fix the permutation.

temperaturePriorShape

Shape parameter of the gamma prior on the temperature parameter, where the prior expected value is temperaturePriorShape/temperaturePriorRate. If either temperaturePriorShape or temperaturePriorRate is set to -1, then the temperature parameter is assumed to be fixed (as defined in the aibd object).

temperaturePriorRate

Rate parameter of the gamma prior on the temperature parameter, where the prior expected value is temperaturePriorShape/temperaturePriorRate.

maxStandardDeviationX

Maximum value parameter of the uniform prior distribution on the standard deviation of X.

maxStandardDeviationA

Maximum value parameter of the uniform prior distribution on the standard deviation of A.

sdProposedTemperature

Standard deviation of the Gaussian random walk update for the standard deviation of the temperature.

sdProposedStandardDeviationX

Standard deviation of the Gaussian random walk update for the standard deviation of X.

sdProposedStandardDeviationA

Standard deviation of the Gaussian random walk update for the standard deviation of A.

corProposedSdXSdA

Correlation of the multivariate Gaussian random walk updates for the standard deviations of X and A.

newFeaturesTruncationDivisor

While in theory a countable infinite number of new features may be allocated to an item, the posterior simulation needs to limit the number of new features that are considered. The value of this argument controls when to stop considering additional features. Starting with 0 and 1 new features, the posterior probabilities are computed. Additional new features are considered but the algorithm stops when the posterior probabilities of the current number of new features is less than the maximum posterior probability (among the previous number of new features) divided by newFeaturesTruncationDivisior.

nOtherUpdatesPerAllocationUpdate

This parameter controls how many additional MCMC updates occur for all other random model parameters for one update of the featureAllocation matrix. Using values of nOtherUpdatesPerAllocationUpdate > 1 will presumably improving the mixing of the MCMC with relatively minimal computational cost.

nSamples

Number of feature allocations to return. The actual number of iterations of the algorithm is thin*nSamples.

thin

Only save 1 in thin feature allocations.

rankOneUpdates

Should rank one updates for the inverse and determinant be used? In some cases, this may be faster.

verbose

Should a progress bar and information regarding lapse time and acceptance rates be displayed?

Details

The default values for some of the tuning parameters governing the MCMC updates of the various parameters are -1, which effectively leaves those parameters fixed. These default values for the tuning parameters can be changed to treat the associated parameters as random. Likewise, nPerShuffle=0 implies a fixed permutation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 # Regardless of size, the initial warmup can exceed CRAN's 5 seconds threshold
mass <- 1
sigx <- 0.1
siga <- 1.0
dimA <- 1
nItems <- 8
dist <- ibp(mass, nItems)
Z <- matrix(c(1,0,1,1,0,1,0,0),byrow=TRUE,nrow=nItems,ncol=2)
A <- matrix(rnorm(ncol(Z)*dimA,sd=siga),nrow=ncol(Z),ncol=dimA)
e <- rnorm(nrow(Z)*ncol(A),0,sd=sigx)
X <- Z %*% A + e
samples <- samplePosteriorLGLFM(Z, dist, X, sdX=sigx, sdA=siga, nSamples=1000, thin=1)

aibd documentation built on June 5, 2021, 1:06 a.m.