MAINT: Merge some 1D and 2D methods into ND mixin methods#73
MAINT: Merge some 1D and 2D methods into ND mixin methods#73derb12 merged 35 commits intodevelopmentfrom
Conversation
Initial look at dimension-agnostic implementations.
This way, the 2D classes don't need to have the method at all, keeping the number of docstrings I'll need to maintain the same.
1d methods converted to nd are no longer wrapped since they just call their super method internally.
All 1D and 2D penalized objects now use solve and direct_solve in a consistent way.
Easier to inherit methods now that 1d and 2d penalized objects have same attributes and call signatures.
Now handles setting up lhs and rhs internally, matching how PSpline and the 2D implementations do it.
Will allow a single call to setup Whittaker or PSpline setups for 1D and 2D.
Now one method is used for both asls and pspline_asls in both 1D and 2D.
Otherwise, the P-spline methods implemented as PLS mixins would do Whittaker smoothing.
Also update nightly tests to use 3.14
Logic is changed to ensure only one wrapper is applied between the method and its potential ND implementation.
|
Not related to the changes in this PR, but I'm noticing the test |
|
Looking at the docs build, my local integration tests should've been for all methods rather than just the ones converted to ND... In commit cd0bd07, CI won't detect the fix, so I'll just merge this and make the change in the dev branch. Also unrelated to this PR, but |
As pointed out in #73, multiplying by weights really screws up the std calc if weights >> 1. Instead just mask out values with weights ~ 0.
Description
Internally refactored the
_Algorithmand_Algorithm2D_register(now_handle_io) wrappers and_setup_*methods to have the same signatures so that the simpler 1D and 2D methods could be generalized into ND mixin classes. This allows having just one canonical method for an algorithm rather than 2. The ND mixins are simply inherited to provide the methods to the appropriate_Algorithm[2D]subclasses.Also refactored the
PenalizedSystem,PSpline,WhittakerSystem2DandPSpline2Dclasses to have the same method calls so that Whittaker smoothing and P-spline smoothing could be generalized under a common penalized least squares (pls) setup. Combined with the above, this allows one method to handle 1D and 2D Whittaker smoothing and P-spline implementations, ie. one method instead of four methods.With the above changes, this PR condenses 48 separate methods into just 17. This will be a huge help for future maintenance or changes, such as adding masking in #72, since only one code path needs updated rather than 2 or 4 for a method. Note that most of the smoothing and morphological algorithms are also low hanging fruit for this ND generalization, but the use of padded convolution in 1D makes it a bit harder to generalize (and seems quite excessive upon review). In the future, I need to see how bad edge effects are if I replace the padded convolution with just a convolution; or add a 2D padded convolution.
Tests should pick up if I screwed up majorly somewhere (eg. 2D input gets called to 1D method or a Whittaker method uses p-splines). I also generated local integration test data using this gist based on the
developmentbranch and ran the comparison tests in this gist with this PR's changes as a sanity check to ensure the 1D and 2D methods retained their output, at least against changing their main input parameters.Type of Pull Request
Pull Request Checklist
if applicable.
viewcodelinks no longer get generated for the 2D methods that directly inherit from the ND mixins. Will see if it's fixable in a follow up, but it's not a big issue if not.