Skip to content

REF: Refactor PET estimator#203

Open
jhlegarreta wants to merge 1 commit intonipreps:mainfrom
jhlegarreta:ref/refactor-pet-estimator
Open

REF: Refactor PET estimator#203
jhlegarreta wants to merge 1 commit intonipreps:mainfrom
jhlegarreta:ref/refactor-pet-estimator

Conversation

@jhlegarreta
Copy link
Contributor

@jhlegarreta jhlegarreta commented Aug 9, 2025

Refactor PET estimator so that it is more closely aligned with the Estimator class, and in order to eventually merge them.

@jhlegarreta jhlegarreta force-pushed the ref/refactor-pet-estimator branch from 8c7d13a to f0862e6 Compare August 13, 2025 23:05
@jhlegarreta
Copy link
Contributor Author

jhlegarreta commented Aug 13, 2025

I think this is close enough to the general estimator class.

I compared the current version and the one in the patch set:

  • The one in the patch set is 6x faster (5:26 vs 32:10).
  • Results are different, though.

Version the PETEstimator in main:

pet_estimated_motion_main pet_fd_main

Note that the increase in error towards the end of the sequence is expected as the signal available in the final frames is low, and thus, estimates are expected to be less good.

Using the PETEstimator in this patch set:

pet_estimated_motion_ps pet_fd_ps

And none seems to be doing a good job: I have plot the ground truth:

pet_sub02_groundtruth

Given that none is doing a good job, and unless you clearly see the fix for the original PETEstimator @mnoergaard, my opinion is that this should be merged so that we invest our time better fixing a version that is closer to the Estimator class so that merging both is eventually easier.

This was referenced Aug 15, 2025
@jhlegarreta jhlegarreta force-pushed the ref/refactor-pet-estimator branch 5 times, most recently from 0813f9a to c112c87 Compare August 21, 2025 23:46
@codecov
Copy link

codecov bot commented Aug 22, 2025

Codecov Report

❌ Patch coverage is 76.92308% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.24%. Comparing base (e1b70cd) to head (6a1f5af).

Files with missing lines Patch % Lines
src/nifreeze/estimator.py 76.92% 7 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #203      +/-   ##
==========================================
- Coverage   82.29%   82.24%   -0.06%     
==========================================
  Files          37       37              
  Lines        2056     2044      -12     
  Branches      227      226       -1     
==========================================
- Hits         1692     1681      -11     
+ Misses        319      318       -1     
  Partials       45       45              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhlegarreta jhlegarreta force-pushed the ref/refactor-pet-estimator branch 4 times, most recently from 2848477 to c49905a Compare September 28, 2025 01:21
@jhlegarreta jhlegarreta force-pushed the ref/refactor-pet-estimator branch 4 times, most recently from 8b955c4 to 8aac2fd Compare October 28, 2025 10:39
pbar.set_description_str(f"{FIT_MSG: <16} vol. <{i}>")

# Fit the model once on the training dataset
model.fit_predict(None)
Copy link
Member

Choose a reason for hiding this comment

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

@mnoergaard is this really what we want?

It can be done, but calling fit_predict(None) is meant to be done outside the iteration loop (i.e., fit only once in all data and after that fit_predict is only "predict").

Is there a reason to fit everytime (btw, in the case of diffusion models, if fit once with all data then the object is locked and doesn't fit again).

Copy link
Member

Choose a reason for hiding this comment

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

Let's discuss this tomorrow @jhlegarreta

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related to my question in #197 (comment). Removing that from the estimator allows the notebook to run and generate the results in #203 (comment), but removing it from the notebook without removing the immediate cell on predicting the given index results in an error: https://github.com/jhlegarreta/nifreeze/blob/9b36f58075eeea6b8234274f0ecdfe0d015f94c2/src/nifreeze/model/pet.py#L184. Removing the 2 calls to fit_predict(None) (notebook and the pointed location in the estimator), as well as the explicit call to fit_predict in the notebook, allows the notebook to run. Results are still the same as in #203 (comment). So I would suggest that @mnoergaard has a look at the related issues.

@oesteban oesteban linked an issue Nov 21, 2025 that may be closed by this pull request
@jhlegarreta jhlegarreta force-pushed the ref/refactor-pet-estimator branch from 8aac2fd to 873fbc3 Compare December 11, 2025 03:53
@jhlegarreta jhlegarreta force-pushed the ref/refactor-pet-estimator branch 4 times, most recently from 4975830 to cb16dc1 Compare December 21, 2025 03:34
@jhlegarreta jhlegarreta marked this pull request as ready for review December 21, 2025 03:45
@jhlegarreta
Copy link
Contributor Author

The execution of the notebook with the current patch set gives the following results:

Ground truth motion
gt_motion

Estimated motion (the range is different, but differences are notable wrt the ground truht)
estimated_motion

FD
fd

So, not working. But such was the case previously as well (#203 (comment)). So the underlying issues is probably elsewhere, whether in the model or the test data, rather than the estimator.

I think that this is ready to be merged; the idea is to bring the PETMotionEstimator class closer to the Estimator class to eventually remove the former.

@jhlegarreta jhlegarreta force-pushed the ref/refactor-pet-estimator branch 4 times, most recently from 6051d9e to dc7fe14 Compare December 28, 2025 03:52
Refactor PET estimator so that it is more closely aligned with the
`Estimator` class, and in order to eventually merge them.

Most notably, avoid creating train, test splits inside the estimator and
delegate the task of walking the sequence to the existing iterators.
This removes the need for the `lofo_split` method.
@jhlegarreta jhlegarreta force-pushed the ref/refactor-pet-estimator branch from dc7fe14 to 6a1f5af Compare January 2, 2026 23:44
@jhlegarreta jhlegarreta requested a review from mnoergaard January 3, 2026 15:45
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.

Revert unfolding of a PET-specific estimator

2 participants