% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rTensor_Decomp.R
\name{parafac2}
\alias{parafac2}
\title{PARAFAC2 Decomposition}
\usage{
parafac2(tnsr, num_components = NULL, max_iter = 25, tol = 1e-05)
}
\arguments{
\item{tnsr}{3-Tensor to decompose}

\item{num_components}{the number of components for the decomposition}

\item{max_iter}{maximum number of iterations if error stays above \code{tol}}

\item{tol}{relative Frobenius norm error tolerance}
}
\value{
a list containing the following:\describe{
\item{\code{H}}{a list of orthogonal matrices (one per frontal slice), each of size \code{mode1} by \code{num_components}}
\item{\code{B}}{the shared profile matrix of size \code{num_components} by \code{num_components}}
\item{\code{C}}{the mode-3 factor matrix of size \code{mode2} by \code{num_components}}
\item{\code{D}}{a list of diagonal weight matrices, one for each frontal slice}
\item{\code{conv}}{whether or not \code{resid} < \code{tol} by the last iteration}
\item{\code{est}}{estimate of \code{tnsr} after decomposition}
\item{\code{norm_percent}}{the percent of Frobenius norm explained by the approximation}
\item{\code{fnorm_resid}}{the Frobenius norm of the error \code{fnorm(est-tnsr)}}
\item{\code{all_resids}}{vector containing the Frobenius norm of error for all the iterations}
}
}
\description{
PARAFAC2 decomposition of a 3-Tensor. Decomposes a 3-Tensor into slice-specific orthogonal matrices \code{H_k}, a shared profile matrix \code{B}, a mode-3 factor matrix \code{C}, and slice-specific diagonal weight matrices \code{D_k} such that each frontal slice \code{X_k = H_k \%*\% B \%*\% D_k \%*\% t(C)}. The key PARAFAC2 constraint is that \code{t(H_k) \%*\% H_k} is constant across all slices. Uses the ALS estimation procedure of Kiers et al. (1999). For more details on PARAFAC2, consult Harshman (1972).
}
\details{
A progress bar is included to help monitor operations on large tensors. The input tensor must be 3-dimensional. Unlike \code{\link{cp}}, PARAFAC2 allows different row spaces per slice while constraining their cross-products to be equal.
}
\note{
The input tensor must be 3-dimensional.
}
\examples{
tnsr <- rand_tensor(c(6,5,4))
pf2D <- parafac2(tnsr, num_components=2)
pf2D$conv
pf2D$norm_percent
plot(pf2D$all_resids)
}
\references{
R. Harshman, "PARAFAC2: Mathematical and technical notes". UCLA Working Papers in Phonetics 1972.

H. Kiers, J. ten Berge, R. Bro, "PARAFAC2 - Part I. A direct fitting algorithm for the PARAFAC2 model". Journal of Chemometrics 1999.
}
\seealso{
\code{\link{cp}}, \code{\link{tucker}}
}
