How this calculation works
Fit a small three-way tensor with a chosen number of CP outer-product components and inspect reconstruction, factor weights and convergence status.
T_ijk≈Σ_(r=1)^R λr A_ir B_jr C_kr; minimize½||T−Tfit||F² by alternating least squares. Displayed factor columns have norm1 and weights carry scale.A worked example
A2×2×2 tensor with T000=1, T111=2 and every other entry zero equals e0⊗e0⊗e0+2e1⊗e1⊗e1. Two components give residual zero. A one-component fit leaves squared residual1, so its objective is½.
Good to know
Three dimensions1–5;≤125finite real entries within±10^6; rank≤3 and no more than the smallest pair-dimension product. Six deterministic ALS starts;10–3000sweeps. Singular starts discarded, diverging weights rejected. Approximate local fit; no CP-rank, uniqueness or global optimum certificate.
Reference: TensorLy CP ALS source and API (opens in a new tab) ↗
A three-way tensor keeps three indexing modes
A CP model approximates each tensor entry by a sum of products a_ir b_jr c_kr. Unlike flattening the tensor into a matrix, the factors preserve a separate loading for each of the three modes.
The input values use row-major index order with the last index changing fastest. Dimensions must multiply to the number of entered values; a wrong ordering can fit a mathematically different tensor while still producing a small residual.
Compare this with the Tensor mode unfolding and multilinear rank calculator. Mode ranks and matricizations do not supply a CP factorization or establish CP rank.
Requested components are not a computed tensor rank
The rank control supplies the number of outer-product terms to fit. The calculator does not search all exact decompositions and does not certify the smallest possible CP rank of the data.
Tensor rank behaves differently from matrix rank. Some approximation problems can have degenerating component sequences, so a large factor weight is not automatically evidence of a meaningful high-amplitude signal.
Alternating least squares updates one mode at a time
With two factor matrices fixed, the remaining mode enters a linear least-squares problem. The solver cycles through the three modes, normalizes component factors and compares several deterministic initializations.
Each accepted finite least-squares update should improve or preserve the objective. Singular normal systems and excessively diverging weights are rejected. The multistart search reduces sensitivity to one initialization without proving a global minimum.
The diagonal default has two explicit components
The two-by-two-by-two default has value1 at index(0,0,0), value2 at(1,1,1) and zeros elsewhere. Two coordinate outer products reproduce it exactly with component weights1 and2.
The recovered factors may swap order or signs while preserving the reconstructed tensor. Comparing the eight reconstructed entries verifies the example more reliably than matching an individual factor column to a preferred presentation.
Separate residual size from convergence evidence
The Frobenius residual measures the distance between the entered tensor and the reconstructed values. Relative residual divides by the input norm, while the half-squared residual is the optimized objective.
Objective stability indicates that recent ALS sweeps changed little. It is not a full stationarity proof and cannot establish uniqueness. Read start statuses and factor weights alongside residuals, especially when the fit is weak or components nearly cancel.
Respect finite scope and numerical degeneracy
This bounded implementation accepts three dimensions with each size at most five and at most three requested components. It is intended for inspecting small tensors and independently checkable examples.
A singular factor update, nonfinite reconstruction or unresolved component divergence produces an error rather than a fictitious rank certificate. Missing entries, weighted observations, nonnegative CP and arbitrary-order tensors are outside this objective.
Interpret components with independent knowledge
Mode factors can summarize repeated patterns across subjects, conditions or time, but numerical decomposition alone does not assign those patterns a causal meaning. Scale, sign and component order require an explicit convention before comparison.
Use a sensible data normalization and compare reconstructions on controlled examples. A good fit should lead to further validation, not an unsupported claim that the latent components are uniquely identified or that the requested rank is scientifically correct.
A few questions, answered
Does this calculate exact CP rank?
No. It fits the number of components you request.
How are tensor values ordered?
The last index changes fastest in row-major order.
Can factors change sign?
Yes. Matched sign changes can preserve a CP component.
Does objective stability prove a global minimum?
No. It only describes recent numerical progress of an ALS run.