-
Notifications
You must be signed in to change notification settings - Fork 58
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
Simplify organization of base classes #675
Conversation
All it had was an abstract method that was always overridden.
Codecov Report
@@ Coverage Diff @@
## main #675 +/- ##
==========================================
+ Coverage 85.28% 85.31% +0.02%
==========================================
Files 40 41 +1
Lines 4513 4528 +15
==========================================
+ Hits 3849 3863 +14
- Misses 664 665 +1
Continue to review full report at Codecov.
|
I will take a look as soon as I get good chance! |
My only concern about separating CBMA and IBMA estimators so much is SDM, but we can always circle back to that when we start working on implementing SDM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
- +1 on moving
_check_ncores
toutils
- I'm on the fence about removing the
Transformer
class since it does serve the purpose of enforcing thetransform
method is implemented by all children. It does add one more layer of abstraction but it sort of makes sense to me to keep this one. I could go either way honestly, maybe we can err on the side of removing it since it doesn't add much. - +1 on moving
Decoder
- +1 on separating CBMA and IBMA. If there is a concern that there is common logic that could crop up, we could always add add the
MetaEstimator
class back in, and use that to control common logic. But if it as its stands there's almost none, then I think its more parsimonious to remove. - Should
_preprocess_input
be an abstractmethod inEstimator
? It seems like all children implement it, and probably should. I suppose there could be an instance of an estimator that doesn't, but since they all do lets enforce it.
An observation:
What simplifies understanding Estimators
to me is that they all have a fit
method which calls: _validate_input
, then _preprocess_input
, and then _fit
-- in this order. These methods must always be implemented.
To further simplify reading the code, lets make sure all children implement them in this order (i.e. in CBMAEstimator
_fit
comes before _preprocess_input
, so let's reverse that), and that these three functions are the top three after __init__
.
This at least makes the major code flow easier to read.
The other issue for me is that CBMAEstimator
implements so many other methods that are called within _fit
and other "primary" methods. It's possible we could pull some of these out of the class entirely if they can be defined as pure functions (i.e. don't need access to that many class internals), or otherwise simplified. Let's hold off for another PR until we profile though since it has implications for that.
Specifically, CBMAEstimator._compute_summarystat_est and Estimator._preprocess_input.
I think that's reasonable. Estimator don't necessarily need to have
I believe I've done that in this PR.
+1 on this. All of the obvious ones have now been moved out, so I think it's going to be a matter of determining how many class internals (and how big) we should consider "too many". |
Great. LGTM then! |
Closes None, but does touch on #671.
Changes proposed in this pull request:
_check_ncores
a function innimare.utils
(see RF Suggestion: Instance methods vs helper functions #671).Transformer
base class.transform
abstract method.Decoder
base class tonimare.decode.base
.IBMAEstimator
base class, and move all IBMA-related code fromMetaEstimator
into that new class.MetaEstimator
intoCBMAEstimator
.MetaEstimator
._validate_input
method to_collect_inputs
.CBMAEstimator
andIBMAEstimator
into actual keyword arguments, and raise a warning for any extraneous kwargs.