Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error per context? #64

Open
lkmartin90 opened this issue Nov 20, 2024 · 3 comments
Open

Error per context? #64

lkmartin90 opened this issue Nov 20, 2024 · 3 comments

Comments

@lkmartin90
Copy link

Hi,
Thanks for the great package. I just wondered if there's an easy way to return the error in the factorisation per context. If my understanding of the method is correct, there's a chance that the factors could fit (N-1)/N contexts very well while describing the Nth context very badly, but still be the best fit for the tensor as a whole. I just wanted to check that this wasn't the case.

@earmingol
Copy link
Owner

earmingol commented Nov 20, 2024

This is a great and interesting question indeed! It is possible that some contexts have more error than others, but we do not evaluate that.

What I could think of an easy way of doing it by context is using your original tensor, subset by the context you are interested in and then do the same for the reconstructed tensor, subset it by the same context and compute the error. A quick pseudocode would be:

context_tensor = interaction_tensor.tensor[1, :, :, :] # where 1 could be another number depending on your context index
context_rec_tensor = interaction_tensor.tl_object.cp_to_tensor() [1, :, :, :] # where 1 could be another number depending on your context index
err = cell2cell.tensor.factorization.normalized_error(context_tensor, context_rec_tensor)

Let me know if this works or you have any questions

@lkmartin90
Copy link
Author

lkmartin90 commented Nov 20, 2024

Thanks for such a quick reply! I changed it slightly to get it to work for me, although I was expecting an error between 0 and 1 and actually get 2.something - but I'll read the c2c.tensor.factorization code to get my head around that.

import tensorly as tl

context_tensor = tensor_final.tensor[1, :, :, :] # Adjust index as needed

context_rec_tensor = tl.cp_to_tensor(tensor_final.tl_object)[1, :, :, :] # Adjust index as needed

err = c2c.tensor.factorization.normalized_error(context_tensor, context_rec_tensor)

Edit: stupid mistake, the last line should be err = c2c.tensor.factorization.normalized_error(context_rec_tensor, context_tensor) for sensible values

@lkmartin90
Copy link
Author

Sorry to add to this further - the method gives much higher error than expected from the elbow plot output, even when the full tensor is used rather than a slice. My understanding of the tensor package isn't good enough to work out what is going wrong.
Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants