knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(SDA4D)
An R package providing an implementation of a variational Bayes algorithm for four dimensional Parallel Factor Analysis.
You can install the released version of SDA4D from the marchinilab github with
install.packages('devtools') devtools::install_github("marchinilab/SDA4D")
We provide a function to generate a data tensor similar to those we used in simulations, named generate_example_data
which also returns a list of the matrices used to generate it.
library(SDA4D) set.seed(42) generatedData <- generate_example_data() lapply(generatedData,dim)
Now, setting stopping=FALSE
to ignore the stopping criterion we run the tensor decomposition with the function RunSDA4D
for 100 iterations as follows:
res<-RunSDA4D(data_tensor = generatedData$dataTensor, dimn_vector = c(200,500,16,3), max_iters = 100, num_components = 8, stopping=FALSE)
Note that we have suppressed the console output from this run in the file here.
In the output we have the evidence lower bound (ELBO, also sometimes referred to as the negative free energy), recorded at each iteration, the maximum number of iterations, and a number of other parameters. Note that in the code we have omitted constant terms from the ELBO.
#res<-list(Neg_FE=exp(rnorm(100))) # plot(-log(-res$Neg_FE[-1]),col='red',pch=4,xlab='Iteration',main='log(ELBO) over 100 iterations') # lines(-log(-res$Neg_FE[-1]),col='red')
library(ggplot2) startfrom=5 ELBO_plot<- qplot(x=c(startfrom:length(res$ELBO)), y=res$ELBO[-c(1:(startfrom-1))], geom=c("point", "line") )+ ylab('ELBO')+ xlab('Iteration')+ ggtitle('ELBO over 100 iterations') suppressWarnings(print(ELBO_plot))
The output of the main function is a list of a number of components:
The main RunSDA4D provides an interface to an implementation of a Bayesian sparse parallel factor analysis model for four-dimensional tensor decomposition. The output therefore consists of a list of the approximate posterior distributions of the main parameters, in the form of their parameters, or point estimates where these were calculated instead.
names(res) res$maximumiteration length(res$ELBO)
See the vignette in the doc directory for a description of the output.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.