Skip to content

Kspace admom - #271

Open
esheldon wants to merge 48 commits into
masterfrom
kspace-admom
Open

Kspace admom#271
esheldon wants to merge 48 commits into
masterfrom
kspace-admom

Conversation

@esheldon

Copy link
Copy Markdown
Owner

K space adaptive moments.

Works across multiple bands/epochs.

Produces prepsfmom like results, as it is inspired by that work.

Can fit gauss, which uses exactly adaptive moments, or exp/dev/bdf which use a trick to make the fixed point method work for the "family" of fixed relative gaussians.

This also includes a fix that was needed along the way, non-square support

esheldon added 30 commits July 16, 2026 09:29
The idea is to merge the nice features of pgauss with adaptive moments,
so we get a shape for metacal and nice matched aperture colors

This is not optimized at all.
numba kernels
cache grids
use the half-plane symmetry folding
single pass rather than separate center moment pass.  Use cen update
  approximation that converges at the fixed point
lookups to avoid sin/cos every pass

Also refactored into new subdir
Internally they are still padded to square.
Apodization still works correctly.
The power spectrum of this field can be used to estimate
errors even when the noise is correlated.
This is exactly a sqrt(2) for a round gaussian
Measure weighted moments and apply a modified adaptive step that works
for a fixed mixture.  Only tested for exp so far, and not optimized.
Errors still not corrected

Add a star type as well, which is similar to a template fit.
If this damping is repeatedlyh failing then it might look like
it converged.
Also keep full e covariance for both mixture and gauss
Also more shared public for a deblender
To be consistent with PGauss
This speed increase means that for the deblender
we are dominated by number of iters, which is currently
higher for the exp adaptive-like updates
This greatly reduces the number of iterations needed, puts it
on par with single gauss adaptive moments.  References in
the code
There were cases in the deblender where we were going
outside the lookup table with chi2 < 0
shape_ok = Tgal > 0 and det2(Sgal) > 0
still need to clean up the exp specific names
It is equivalent, just changed so they don't look different
at a quick glance
this is verified to be byte identical to pre-refactor
also save deweighted moment shapes in all cases.
this is tricky due to the strong anti correlation of the flux split with
T.  a covariance term needed to be calculated.
The full covariance of the per band fluxes.  The off diagonal is
generated by the shared family response (the band sum noises are
independent across bands) and is what color errors require
Unlike model_sandwich this stays calibrated under model
mismatch, where the sandwich under-predicts T errors by ~17
percent and flux errors by ~11 percent for dev truth fit
with exp

However, it costs a factor of 3 for the gauss fit, so pull
it out only when you need it.
esheldon added 12 commits July 30, 2026 20:38
Using threadpoolctl to force blas onto one core
the scalar half of prep_epoch, computable without any FFTs:
dims, pad phase centers, weights and jacobian factors.  Used
by prep_epoch itself and by device-prep paths that compute
the k arrays elsewhere and only need the epoch scalars on the
host (the array entries of the returned epoch are None).
memory is leaking when i raise from within jitted functions.

create non-raising version of some numba functions to avoid
this. If a fix go in we can remove these
The fit uses all bands at once and structure is common.

take this into account in S/N
@esheldon

Copy link
Copy Markdown
Owner Author

the new numba *_status functions are to deal with the numba bug reported here: numba/numba#10783

@beckermr

Copy link
Copy Markdown
Collaborator

@esheldon if you'd like code review here, it'd be very helpful to break this up into smaller PRs.

@esheldon
esheldon requested a review from beckermr August 19, 2026 20:56
@esheldon

Copy link
Copy Markdown
Owner Author

I hear you and I'll give it a try. But it all flows together, and a lot of it won't work without the other parts.

@beckermr

Copy link
Copy Markdown
Collaborator

I will take a quick look later and see if I can find some ways to help break it up.

@beckermr

Copy link
Copy Markdown
Collaborator

For sure the _status stuff can be broken into its own PR. That won't help a ton, but it will break off a few hundred lines.

@beckermr

Copy link
Copy Markdown
Collaborator

The change to allow normal prePSF moments to use non-square images can also be its own PR.

@beckermr

Copy link
Copy Markdown
Collaborator

I'd also break out the Gaussian models from support for the exp/dev/bdf models.

beckermr and others added 2 commits August 25, 2026 15:27
In extremely rare cases the determinant check was within
precision of zero and caused an exception.  Put in
an explicity tolerance based on products
@esheldon

Copy link
Copy Markdown
Owner Author

this is the same test failure with too tight a tolerance that failed in PR #272

will wait and merge that in

@beckermr beckermr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is still way too much code here for me to review.

There are a few options:

  1. We can break up the code further by separating out each of the models or the models versus the Gaussian into their own PRs

  2. I can only look at the tests, which is still a lot, but is more manageable.

  3. We can go without code review. I don't like this option, but at the end of the day this is your repo and I won't insist on code review.

I'm happy to work on 1), but my time is limited, and I have not gotten to it yet. It'd be helpful if you can turn on the setting that offers to update PR branches in the repo settings on github.

A small observation from my brief look already. Many of the doc strings are unintelligible (at least to me, but probably others). I get that there is some non-trivial math happening here, but I think they could be better.

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.

2 participants