Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@cchatzis
Copy link
Contributor

@cchatzis cchatzis commented Jul 2, 2024

Enable missing data imputation via the mask argument as done in CP, as brought up in #543 .

The changes are outlined as follows (all lines refer to _parafac2.py):

  1. Added new argument mask to the parafac2 function.
  2. Initial slice-wise missing data imputation (lines 480-501)
  3. Norm tensor is adjusted to include only the non-missing entries in the presence of missing data (lines 510-523)
  4. Update imputation after a full factor update circle (lines 601-611)
  5. Adjusted _parafac2_reconstruction_error to include the mask argument in case norm_matrices is not given (lines 260, 297-306)
  6. Adjusted _BroThesisLineSearch to include mask, required when computing the reconstruction error.
  7. Added the mask docstring whenever required.

@MarieRoald
Copy link
Contributor

Hi @cchatzis Great! I have my hands full with a paper deadline right now, but I can take a look when my plate clears a little 🙂

@JeanKossaifi
Copy link
Member

JeanKossaifi commented Jul 8, 2024

Thanks @cchatzis for opening the PR, this will be great to have!

For the failing tests, you can also try to run the tests locally using pytest to check things work as expected and quick debugging.

Regarding the masking, it would be more efficient to do the computation in a vectorized way, e.g. you can first multiply the who slice by the mask array of 0 and 1 and then take the mean over the resulting array rather than loop over individual elements.

Thanks @MarieRoald, will be great to get your feedback too!

Copy link
Contributor

@cohenjer cohenjer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cchatzis for this PR !
Looks correct to me, I have few minor comments.

@cchatzis
Copy link
Contributor Author

cchatzis commented Jul 19, 2024

Thanks again everyone for taking the time to look and review this.

In the latest commits, I updated the code to include your feedback. Relevant tests are passing now - I will create a small test for the _update_imputed function in the near future.

@cohenjer
Copy link
Contributor

Thanks @cchatzis for the updates, this version looks good to me.

Copy link
Contributor

@MarieRoald MarieRoald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Only a couple of minor comments on my end :)

Copy link
Contributor

@yngvem yngvem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding a couple of minor suggestions here :)

Copy link
Contributor

@yngvem yngvem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks very good! Just a couple of more changes and I think it's good to go :)

@cchatzis
Copy link
Contributor Author

Hi everyone and thank you very much for your kind feedback and help!

Maybe I am missing something but I cannot seem to reproduce the issue with the paddle backend because when i try to set it I set it for pytest (i.e. : TENSORLY_BACKEND=paddle pytest ...) I get:

UserWarning: TENSORLY_BACKEND should be one of 'numpy''pytorch''tensorflow''cupy''jax', got paddle. Defaulting to numpy'

I am sure I am missing something trivial here, any suggestion/help would be welcome :)

@cchatzis
Copy link
Contributor Author

cchatzis commented Oct 3, 2024

Hi, are there any updates on this?

Copy link
Contributor

@yngvem yngvem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost at the finish line now! I just have a small comment :)

Regarding the paddle trouble, I think that will sort itself out if you merge main into your feature branch (run git merge main from your feature branch)

@JeanKossaifi
Copy link
Member

@cchatzis thanks for the changes, feel free to mark the changes requested as done when it's ready!

@cchatzis cchatzis requested a review from yngvem November 4, 2024 10:11
@aarmey aarmey changed the title Parafac2 als em Parafac2 ALS EM May 3, 2025
Copy link
Contributor

@aarmey aarmey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together, @cchatzis! As this has been sitting, there are a few minor adjustments to make it consistent with code changes on main. Please also run the black formatter so that test passes. Everything else looks good to me, so I can merge it if you ping me after these edits.

@cchatzis
Copy link
Contributor Author

cchatzis commented May 5, 2025

Thank you for looking into this @aarmey! I added your suggestions and also made a small change for the paddle backend. Something in the lines of tl.nanmean is not available to compare the results with - I used the numpy version in the test_impute_results() test. Would that be acceptable?

@cchatzis cchatzis requested a review from aarmey May 5, 2025 18:08
@cchatzis
Copy link
Contributor Author

cchatzis commented May 5, 2025

The test results with black don't seem to make sense, two-line comments are marked as problematic:

--- /home/runner/work/tensorly/tensorly/tensorly/tenalg/__init__.py	2025-05-05 19:11:01.364542+00:00
+++ /home/runner/work/tensorly/tensorly/tensorly/tenalg/__init__.py	2025-05-05 19:11:08.018732+00:00
@@ -1,7 +1,7 @@
-""" 
would reformat /home/runner/work/tensorly/tensorly/tensorly/tenalg/__init__.py
-The :mod:`tensorly.tenalg` module contains utilities for Tensor Algebra 
+"""
+The :mod:`tensorly.tenalg` module contains utilities for Tensor Algebra
 operations such as khatri-rao or kronecker product, n-mode product, etc.
 """

[...]

  from .... import backend as tl
 
 import pytest
 import numpy as np
--- /home/runner/work/tensorly/tensorly/tensorly/decomposition/__init__.py	2025-05-05 19:11:01.360542+00:00
+++ /home/runner/work/tensorly/tensorly/tensorly/decomposition/__init__.py	2025-05-05 19:11:07.181622+00:00
@@ -1,8 +1,8 @@
 """
 The :mod:`tensorly.decomposition` module includes utilities for performing
-tensor decomposition such as CANDECOMP-PARAFAC and Tucker.                                                                                               
+tensor decomposition such as CANDECOMP-PARAFAC and Tucker.
 """

@aarmey
Copy link
Contributor

aarmey commented May 5, 2025

We can ignore those errors, since they don't involve the code here. Also, yes, use of np.nanmean is reasonable within the tests. This all looks to be in order, so I'll merge. Thanks again for implementing this!

@aarmey aarmey merged commit 3912bb9 into tensorly:main May 5, 2025
9 of 10 checks passed
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

Successfully merging this pull request may close these issues.

6 participants