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

Add DictionaryMatchingOp #509

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

Add DictionaryMatchingOp #509

wants to merge 31 commits into from

Conversation

fzimmermann89
Copy link
Member

Draft of dictionary matching function

Does only non-differentiable argmax matching, but good enough for now.
Needs tests, example, docstrings etc..

Related #465

Copy link
Contributor

github-actions bot commented Nov 11, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/mrpro/algorithms/csm
   inati.py24196%44
   walsh.py16194%34
src/mrpro/algorithms/dcf
   dcf_voronoi.py53492%15, 48–49, 76
src/mrpro/algorithms/optimizers
   adam.py20195%69
   pdhg.py79396%177–178, 184
src/mrpro/algorithms/reconstruction
   DirectReconstruction.py281643%51–71, 85
   IterativeSENSEReconstruction.py13192%76
   Reconstruction.py502256%42, 54–56, 80–87, 104–113
   RegularizedIterativeSENSEReconstruction.py411759%96–100, 114–139
src/mrpro/data
   AcqInfo.py128398%26, 169, 207
   CsmData.py29390%15, 82–84
   DcfData.py45882%18, 66, 78–83
   IData.py67987%119, 125, 129, 159–167
   IHeader.py75791%75, 109, 127–131
   KData.py2142588%111–112, 127, 134, 144, 152, 206–207, 245, 250–251, 270–281, 435, 437, 500, 515, 552, 583, 592
   KHeader.py1531789%25, 119–123, 150, 199, 210, 217–218, 221, 228, 260–271
   KNoise.py311552%39–52, 56–61
   KTrajectory.py811285%108–113, 116–118, 203–207
   MoveDataMixin.py1401887%15, 113, 129, 143–145, 207, 323–325, 338, 417, 437–438, 440, 455–456, 458
   QData.py39782%42, 65–73
   Rotation.py6743595%100, 198, 335, 433, 477, 495, 581, 583, 592, 626, 628, 691, 768, 773, 776, 791, 808, 813, 889, 1077, 1082, 1085, 1109, 1113, 1240, 1242, 1250–1251, 1315, 1397, 1690, 1846, 1881, 1885, 1996
   SpatialDimension.py2322191%34, 104, 141, 148, 154, 274–276, 289–291, 325, 343, 356, 369, 382, 395, 404–405, 420, 429
   acq_filters.py12192%47
src/mrpro/data/traj_calculators
   KTrajectoryCalculator.py25292%23, 45
   KTrajectoryIsmrmrd.py13285%41, 50
   KTrajectoryPulseq.py23196%55
src/mrpro/operators
   CartesianSamplingOp.py89397%118, 157, 280
   ConstraintsOp.py60297%46, 48
   DictionaryMatchOp.py312132%36–39, 55–65, 84–89
   EndomorphOperator.py65297%228, 234
   FiniteDifferenceOp.py27293%40, 105
   FourierOp.py158398%263, 381, 386
   Functional.py71593%20–22, 117, 119
   GridSamplingOp.py136993%72–73, 82–83, 90–91, 94, 96, 98
   LinearOperator.py168995%55, 91, 190, 220, 261, 270, 278, 295, 320
   LinearOperatorMatrix.py1581690%82, 119, 152, 161, 166, 175–178, 191–194, 203, 215, 304, 331, 359
   MultiIdentityOp.py13285%43, 48
   Operator.py78297%25, 74
   ProximableFunctionalSeparableSum.py39392%50, 103, 110
   SliceProjectionOp.py173895%44, 61, 63, 69, 206, 227, 260, 300
   WaveletOp.py119596%151, 169, 204, 209, 232
   ZeroPadOp.py16194%30
src/mrpro/utils
   filters.py62297%44, 49
   reshape.py60198%191
   slice_profiles.py46687%20, 36, 113–116, 149
   sliding_window.py34197%34
   split_idx.py10280%43, 47
   summarize_tensorvalues.py11918%20–29
   typing.py181139%8–23
   zero_pad_or_crop.py31681%26, 30, 54, 57, 60, 63
TOTAL500138392% 

Tests Skipped Failures Errors Time
2300 0 💤 0 ❌ 0 🔥 1m 11s ⏱️

Copy link
Contributor

github-actions bot commented Nov 11, 2024

📚 Documentation

📁 Download as zip
🔍 View online

@fzimmermann89
Copy link
Member Author

@rkcatarina : If you join this weeks hackathon, would you be interested to work on this?

@fzimmermann89
Copy link
Member Author

This already looks promising :)

Why did you change from the list of x values (in the initial commit here) to only supporting a single T1?

It would be great if the matching op can be used with multiple parameters (fingerprinting for example)

Copy link
Contributor

github-actions bot commented Feb 18, 2025

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/mrpro
   _version.py6267%7–8
src/mrpro/algorithms/csm
   inati.py24196%44
   walsh.py16194%53
src/mrpro/algorithms/dcf
   dcf_voronoi.py55493%15, 55–56, 89
src/mrpro/algorithms/optimizers
   adam.py20195%101
   pdhg.py79396%177–178, 184
   pgd.py51492%106, 151–154
src/mrpro/algorithms/reconstruction
   DirectReconstruction.py281643%59–79, 93
   IterativeSENSEReconstruction.py13192%79
   Reconstruction.py502256%42, 54–56, 80–87, 108–117
   RegularizedIterativeSENSEReconstruction.py411759%97–101, 115–140
src/mrpro/data
   AcqInfo.py145597%42, 121–122, 124, 233
   CsmData.py29390%15, 84–86
   DcfData.py45882%18, 66, 78–83
   EncodingLimits.py73396%33, 123, 126
   IData.py59886%118, 132, 159–167
   IHeader.py1361291%69–72, 253, 257, 261, 265, 299–303
   KData.py2012986%113–114, 129, 136, 147–157, 166, 174, 183, 217, 239–241, 277–278, 333–344, 473, 475, 545
   KHeader.py1412185%24, 109–115, 142, 190, 197–198, 201, 208, 225–232, 240–251
   KNoise.py311552%39–52, 56–61
   KTrajectory.py108397%166, 168, 188
   MoveDataMixin.py1401887%28, 126, 142, 156–158, 220, 336–338, 351, 430, 450–451, 453, 468–469, 471
   QData.py39782%42, 65–73
   Rotation.py7193595%101, 199, 336, 434, 478, 496, 583, 585, 594, 628, 630, 693, 770, 775, 778, 793, 810, 815, 891, 1079, 1084, 1087, 1111, 1115, 1243, 1245, 1253–1254, 1318, 1400, 1703, 1855, 1890, 1894, 2084
   SpatialDimension.py2322091%34, 104, 148, 154, 274–276, 289–291, 325, 343, 356, 369, 382, 395, 404–405, 420, 429
   acq_filters.py12192%47
src/mrpro/data/traj_calculators
   KTrajectoryCalculator.py27196%84
   KTrajectoryIsmrmrd.py19195%57
src/mrpro/operators
   CartesianSamplingOp.py96496%124, 163, 238, 305
   ConstraintsOp.py60297%46, 48
   EndomorphOperator.py32294%52, 58
   FiniteDifferenceOp.py27293%40, 105
   FourierOp.py90397%185, 257, 262
   Functional.py77988%20–22, 117, 119, 226–228, 242
   GridSamplingOp.py136993%72–73, 82–83, 90–91, 94, 96, 98
   LinearOperator.py201996%48, 107, 217, 244, 251, 292, 301, 309, 326
   LinearOperatorMatrix.py1621988%82, 119, 152, 161, 166, 175–178, 191–194, 202–203, 208–209, 221, 310, 337, 364
   MultiIdentityOp.py13285%43, 48
   NonUniformFastFourierOp.py1881095%69, 96, 206, 208, 241, 243, 319, 373, 423, 428
   Operator.py79297%32, 88
   ProximableFunctionalSeparableSum.py39392%50, 103, 110
   SliceProjectionOp.py174895%45, 62, 64, 70, 206, 227, 260, 300
   WaveletOp.py119596%151, 169, 204, 209, 232
   ZeroPadOp.py16194%30
src/mrpro/phantoms
   brainweb.py2752691%325–335, 371, 427–430, 452–453, 458–459, 474, 520, 586–587, 606–609, 620, 622, 657–658, 671
src/mrpro/utils
   filters.py62297%44, 49
   reshape.py95298%110, 301
   slice_profiles.py47687%21, 37, 116–119, 152
   sliding_window.py34197%34
   split_idx.py10280%43, 47
   summarize_tensorvalues.py12375%23, 25, 27
   typing.py695520%9–235
   unit_conversion.py601477%32, 40, 42, 49, 51, 58, 60, 69, 80, 82, 101, 103, 124, 126
   zero_pad_or_crop.py31681%26, 30, 55, 58, 61, 64
TOTAL574846992% 

Tests Skipped Failures Errors Time
2478 0 💤 0 ❌ 0 🔥 1m 55s ⏱️

@fzimmermann89
Copy link
Member Author

@rkcatarina
I f'ed up git a bit. So this was force pushed.
When pulling in the changes, make sure to either use git pull --rebase --autostash if you have useful changes locally.
If you don't have useful local changes in the branch, do

git fetch
git reset --hard origin/dict

to reset your local state to what is on github

torch.testing.assert_close(t1_matched, t1, atol=1e-4, rtol=0.0)


# TODO:
Copy link
Member Author

Choose a reason for hiding this comment

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

Some todos

@fzimmermann89 fzimmermann89 marked this pull request as ready for review February 27, 2025 23:10
m0_1 = rng_1.rand_tensor(shape, dtype=dtype, low=0.2, high=1.0)
t1_1 = rng_1.rand_tensor(shape, dtype=dtype.to_real(), low=0.1, high=1.0)

rng_2 = RandomGenerator(3)
Copy link
Member Author

Choose a reason for hiding this comment

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

you can reuse the same rng

t1_2 = rng_2.rand_tensor(shape, dtype=dtype.to_real(), low=0.1, high=1.0)

#concatenation of the tensors
m0_cat = torch.cat((m0_1, m0_2))
Copy link
Member Author

Choose a reason for hiding this comment

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

move this to the #dictionary matching when appending the individual tensors section

operator = DictionaryMatchOp(model, index_of_scaling_parameter=index_of_scaling_parameter)
operator.append(m0, t1)

if index_of_scaling_parameter is not None:
Copy link
Member Author

Choose a reason for hiding this comment

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

just remove this test.

Copy link
Member Author

Choose a reason for hiding this comment

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

the cutrrent version does not actually test behavior of the operator.

and in the operator we actually currently seem to support any value for the index, and just wrap it around.
so even for a two parameter model, you could set it to 1000.
there is no really nice way to check it when creating the operator, only later on...

from tests import RandomGenerator


@pytest.mark.parametrize('dtype', [torch.float32, torch.complex64], ids=['float32', 'complex64'])
Copy link
Member Author

@fzimmermann89 fzimmermann89 Mar 5, 2025

Choose a reason for hiding this comment

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

add here a "-2" case for index_of_scaling_parameter , name it predict_scale_negative_index

Copy link
Member Author

@fzimmermann89 fzimmermann89 left a comment

Choose a reason for hiding this comment

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

some comments

@fzimmermann89 fzimmermann89 added the pre-commit.ci autofix run autofix in this PR label Mar 5, 2025
@pre-commit-ci pre-commit-ci bot removed the pre-commit.ci autofix run autofix in this PR label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants