Repository navigation
Fix single-column inputs in tpls() and facewise products - #12
Open
kimanh-lecao wants to merge 2 commits into
Open
kimanh-lecao wants to merge 2 commits into
kimanh-lecao wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #11; only the last commit is new.
When a response has one column (q = 1), R's
[drops the length-1 dimension and several stepsbreak. This PR keeps those dimensions in four places.
1.
tpls(), regression and canonical modes (R/tens.tpls.R)yhat[, , f]becomes a length-n vector andcurr_y_loadingsa length-1 vector, which%*%rejects. Fixed by keeping the face as
matrix(yhat[, , f], nrow = n).2. Facewise product,
%fp%/facewise_product()(.binary_facewise()inR/tens.mproduct.R)a[, , i] %*% b[, , i]has the same problem whenever a face has a single row or column:tpls(mode = "tsvdm")fails for q = 1;length-n vectors, so
%*%computes their inner product, and that single number is recycledacross the n x n face instead of the outer product.
Fixed by wrapping both faces in
matrix(..., nrow, ncol), in the for-loop and the BiocParallelbranch. None of the package's own functions produce the silently wrong shape: in 13 typical calls
to
tpca(),tpls()(all modes),tplsda(),block_tpls()andblock_tplsda(), no facewiseproduct had a length-1 face dimension. It affects direct calls to
%fp%andfacewise_product().3. BiocParallel branch of the facewise product (same function)
simplify2array()flattens the result to a plain vector when every face is 1 x 1. The branch nowbuilds the array from the known dimensions instead.
4.
.extract_tensor_columns()(R/tens.tpca.R)apply()returns a vector instead of a matrix when the tensor has one row, so with q = 1tpls(mode = "tsvdm")returnedy_loadingsas a vector rather than a 1 x ncomp matrix as theother modes do. The matrix shape is now restored only in that case; other output is unchanged.
Checks.
identical()results before and after: 18tpls()fits(q = 2, q = 3 and a subject-fixed q = 2; all three modes; with and without centring) and 7 results
from
tpca(),tplsda(),block_tpls(),block_tplsda()and a cumulativefacewise_product().test-tens.mproduct.R, n x 1 by 1 x 1, n x 1 by 1 x n and 1 x p by p x 1 facesagainst a direct per-face product, on both branches; in
test-tens.tpls.R, q = 1 runs in allthree modes with the expected dimensions and finite output. Both fail on the current main, and
reverting any one of the four changes makes at least one of them fail.
Closes #2.