neurostatslab / tensortools

A very simple and barebones tensor decomposition library for CP decomposition a.k.a. PARAFAC a.k.a. TCA
MIT License
160 stars 65 forks source link

Variance explained by the factors #34

Open yoga-varatha opened 2 years ago

yoga-varatha commented 2 years ago

Could someone please clarify how I can calculate the total variance explained by the factors after decomposing?

I am currently using the following code: ` U = tt.ncp_hals(my_data, rank=6, verbose=False)

factors = U.factors.factors `

my data is a 3-dimensional tensor.

ahwillia commented 2 years ago

U.obj gives the final objective value, norm(residuals) / norm(my_data). If you square this quantity, it is more-or-less one minus the variance explained. (Note, however, that the data aren't mean-centered, so this is like the uncentered variance explained.)

Unlike PCA, there is no good way to quantify the variance explained on a factor-by-factor basis, because the factors aren't orthogonal to each other.

yoga-varatha commented 2 years ago

Excellent. Thank you so much.

yoga-varatha commented 2 years ago

Hello, another quick question. How can I use the factors I obtained above to project a new tensor onto the space spanned by the factors? Basically, I want to find the weight vector for a new set of inputs. Is there a function implemented for this purpose? Thank you in advance.

ahwillia commented 2 years ago

My advice would be to refit the model, unlike PCA there isn't a simple projection operation that gives the optimal low-D factors. The reasons are similar to the answer above -- the factors you extract aren't orthogonal so instead of projecting you need to solve the alternating least-squares problem. The review paper on tensor decompositions by Kolda & Bader 2009 may help provide some insight.

On Tue, Nov 23, 2021 at 11:45 AM theesan16 @.***> wrote:

Hello, another quick question. How can I use the factors I obtained above to project a new tensor onto the space spanned by the factors? Basically, I want to find the weight vector for a new set of inputs. Is there a function implemented for this purpose? Thank you in advance.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ahwillia/tensortools/issues/34#issuecomment-977082317, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE3NUPY3L3YAH662LEY2PLUNPVL5ANCNFSM5GCJ6WBQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

yoga-varatha commented 2 years ago

I see, thanks.