Overview
GCPDecompositions — ModuleGeneralized CP Decomposition module. Provides approximate CP tensor decomposition with respect to general losses.
GCPDecompositions.gcp — Functiongcp(X, r;
loss = GCPLosses.LeastSquares(),
constraints = default_gcp_constraints(X, r, loss),
algorithm = default_gcp_algorithm(X, r, loss, constraints),
init = default_gcp_init(X, r, loss, constraints, algorithm))Compute an approximate rank-r CP decomposition of the data tensor X with respect to the loss function loss and return a CPD object.
Keyword arguments:
loss: loss function of typeGCPLosses.AbstractLossconstraints: aTupleof constraints of typeGCPConstraints.AbstractConstraintalgorithm: algorithm of typeGCPAlgorithms.AbstractAlgorithm
Conventional CP corresponds to the default GCPLosses.LeastSquares() loss with the default of no constraints (i.e., constraints = ()).
If the LossFunctions.jl package is also loaded, loss can also be a DistanceLoss or MarginLoss from that package; gcp will automatically wrap it into a GCPLosses.Wrapped loss.
See also: CPD, GCPLosses, GCPConstraints, GCPAlgorithms.
GCPDecompositions.CPD — TypeCPDTensor decomposition type for the canonical polyadic decompositions (CPD) of a tensor (i.e., a multi-dimensional array) A. This is the return type of gcp(_), the corresponding tensor decomposition function.
If M::CPD is the decomposition object, the weights λ and the factor matrices U = (U[1],...,U[N]) can be obtained via M.λ and M.U, such that A = Σ_j λ[j] U[1][:,j] ∘ ⋯ ∘ U[N][:,j].
Base.permutedims — Functionpermutedims(M::CPD, perm)Permute the dimensions (axes) of M. perm is a vector or a tuple of length ndims(M) specifying the permutation.
The permuted CPD object returned by this function is formed without copying (the output shares storage with the input M).
GCPDecompositions.ncomps — Functionncomps(M::CPD)Return the number of components in M.
See also: ndims, size.
GCPDecompositions.normalizecomps — Functionnormalizecomps(M::CPD, p::Real = 2)Normalize the components of M so that the columns of all its factor matrices all have p-norm equal to unity, i.e., norm(M.U[k][:, j], p) == 1 for all k ∈ 1:ndims(M) and j ∈ 1:ncomps(M). The excess weight is absorbed into M.λ. Norms equal to zero are ignored (i.e., treated as though they were equal to one).
The following keyword arguments can be used to modify this behavior:
dimsspecifies what to normalize (default:[:λ; 1:ndims(M)])distribute_tospecifies where to distribute the excess weight (default::λ)
Valid options for these arguments are the symbol :λ, an integer in 1:ndims(M), or a collection of these.
See also: normalizecomps!, norm.
GCPDecompositions.normalizecomps! — Functionnormalizecomps!(M::CPD, p::Real = 2)Normalize the components of M in-place so that the columns of all its factor matrices all have p-norm equal to unity, i.e., norm(M.U[k][:, j], p) == 1 for all k ∈ 1:ndims(M) and j ∈ 1:ncomps(M). The excess weight is absorbed into M.λ. Norms equal to zero are ignored (i.e., treated as though they were equal to one).
The following keyword arguments can be used to modify this behavior:
dimsspecifies what to normalize (default:[:λ; 1:ndims(M)])distribute_tospecifies where to distribute the excess weight (default::λ)
Valid options for these arguments are the symbol :λ, an integer in 1:ndims(M), or a collection of these.
See also: normalizecomps, norm.
GCPDecompositions.permutecomps — Functionpermutecomps(M::CPD, perm)Permute the components of M. perm is a vector or a tuple of length ncomps(M) specifying the permutation.
See also: permutecomps!, sortcomps, sortcomps!.
GCPDecompositions.permutecomps! — Functionpermutecomps!(M::CPD, perm)Permute the components of M in-place. perm is a vector or a tuple of length ncomps(M) specifying the permutation.
See also: permutecomps, sortcomps, sortcomps!.
GCPDecompositions.sortcomps — Functionsortcomps(M::CPD; dims=:λ, alg::Algorithm=DEFAULT_UNSTABLE, lt=isless, by=identity, rev::Bool=false, order::Ordering=Reverse)Sort the components of M. dims specifies what part to sort by; it must be the symbol :λ, an integer in 1:ndims(M), or a collection of these.
For the remaining keyword arguments, see the documentation of sort!.
See also: permutecomps, permutecomps!, sortcomps!, sort, sort!.
GCPDecompositions.sortcomps! — Functionsortcomps!(M::CPD; dims=:λ, alg::Algorithm=DEFAULT_UNSTABLE, lt=isless, by=identity, rev::Bool=false, order::Ordering=Reverse)Sort the components of M in-place. dims specifies what part to sort by; it must be the symbol :λ, an integer in 1:ndims(M), or a collection of these.
For the remaining keyword arguments, see the documentation of sort!.
See also: permutecomps, permutecomps!, sortcomps, sort, sort!.
GCPDecompositions.default_gcp_constraints — Functiondefault_gcp_constraints(X, r, loss)Return a default tuple of constraints for the data tensor X, rank r, and loss function loss.
See also: gcp.
GCPDecompositions.default_gcp_algorithm — Functiondefault_gcp_algorithm(X, r, loss, constraints)Return a default algorithm for the data tensor X, rank r, loss function loss, and tuple of constraints constraints.
See also: gcp.
GCPDecompositions.default_gcp_init — Functiondefault_gcp_init([rng=default_rng()], X, r, loss, constraints, algorithm)Return a default initialization for the data tensor X, rank r, loss function loss, tuple of constraints constraints, and algorithm algorithm, using the random number generator rng if needed.
See also: gcp.