Encode data with a fitted decomposition and decode it back, giving the
rank-k approximation of the input in its original units and column layout.
Arguments
- decom
Decompositionobject.- x
Tabular data (data.frame, data.table, or tibble): Data to reconstruct. Its columns must match those
decomwas fitted on.- execution_config
Optional
ExecutionConfigobject: Threads for encodingx, as in apply_decomp.NULLuses the host's default worker count.- verbosity
Integer: Verbosity level.
Value
A data.frame with the same columns as x, holding the
reconstruction of the decomposed features.
Details
The round trip apply_decomp leaves half-done. The reconstruction is x
with everything outside the first k components removed, i.e. a denoised
x. The residual, x - reconstruct(decom, x), is what the decomposition
could not represent: rowMeans(residual^2) scores how anomalous each case
is, and colMeans(residual^2) shows which variables the decomposition fails
to capture.
Available for algorithms whose invertible trait is TRUE; see
decomposition_traits. tSNE, UMAP and Isomap embed without an inverse, so
there is no map back for them at all.
The reconstruction is in the units of the data as it was passed to decomp,
with any centering or scaling the backend applied internally undone, so it
can be compared with x directly. Columns the fit did not decompose (when
decom@config@features is set) pass through unchanged and column order is
preserved, so the result lines up cell for cell with x.
Examples
#> 2026-10-20 09:08:00
#> ▶
#> [decomp]
#> 2026-10-20 09:08:00
#> Input: 150 cases x 4 features.
#> [summarize_unsupervised]
#> 2026-10-20 09:08:00
#> // CPU | future (mirai_multisession) | 7 workers: algorithm 1 thread
#> [msg_resources]
#> 2026-10-20 09:08:00
#> Decomposing with PCA...
#> [decomp]
#> 2026-10-20 09:08:00
#> Done in 2e-03 seconds.
#> [decomp]reconstructed <- reconstruct(iris_pca, x)
# What the two components could not represent, per case:
head(rowMeans((as.matrix(x) - as.matrix(reconstructed))^2))#> [1] 0.0034608746 0.0184488525 0.0005789659 0.0046475724 0.0008325144
#> [6] 0.0001174715