-
Notifications
You must be signed in to change notification settings - Fork 280
Implement base objective function classes as abstract ones #1335
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
base: main
Are you sure you want to change the base?
Conversation
The mapping is only used by regularizations. Data misfits rely on the simulation to handle the mapping.
Also add methods for testing their implementations in a quick way. They still need to be polished.
The implementation of weights should be handled by the child classes.
Remove old bits from the class and incorporate the new ones from the drafted ObjectiveFunction abstract class.
Remove this class since it was only use to create the `BaseDataMisfit` class, forcing it to be only an L2 class. Moreover, most of its methods were being overwritten by the `BaseDataMisfit` and `L2DataMisfit`, so it didn't have a clear purpose.
Don't rely on every objective function to have a `has_fields` argument, instead check if the object has it and it's True. Also, pass fields in case the objective function is a ComboObjectiveFunction, so we can pass fields down the tree.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1335 +/- ##
==========================================
+ Coverage 86.23% 86.26% +0.03%
==========================================
Files 396 396
Lines 50366 50364 -2
Branches 5309 5306 -3
==========================================
+ Hits 43431 43446 +15
+ Misses 5483 5472 -11
+ Partials 1452 1446 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Define a mock objective function class that is used only for running tests.
Since the `BaseRegularization` is now an abstract class, we don't need to test if the `f_m` and `f_m_deriv` methods raise a NotImplemented error.
|
I noticed by running some tests on the drafted code that some regularization classes like I think we should revisit the design of these classes so we avoid violating Liskov substitution principle.
|
|
After discussing with @lheagy, we decided not to touch the |
Revert the changes made to the `BaseRegularization` class so it goes back at being a non-abstract class. It still inherits from the `ObjectiveFunction` abstract class, but it implements all abstract methods and properties. Restore tests for error when trying to call `f_m` and `f_m_deriv` in `BaseRegularization`.
Restore the docstrings for the `deriv` and `deriv2` abstract methods.
Update tests for objective functions to the new interface. Fully replace uniitest with pytest in them.
In these tests `reg` was a `ComboObjectiveFunction` and they don't necessarily have a `mapping` attribute. Use their `nP` instead.
Compare outputs of the smallness with expected values calculated inplace.
Summary
Draft for redesigning base classes for objective functions, data misfits and
regularizations as abstract
classes.
PR Checklist
expect style.
to a Pull Request
@simpeg/simpeg-developerswhen ready for review.Reference issue
What does this implement/fix?
Simplify the
BaseObjectiveFunction:__init__,__call__,derivandderiv2asabstractmethods.nPasabstractproperty.mapping. Only regularizations needs it. Data misfits rely onthe simulation to handle mapping operations.
Simplify the
ComboObjectiveFunction:W, it was overwritten by child classes, and the implementationonly applied when the objective functions used and L2 norm.
fieldsin their methods or not. Don't rely on every objective function to have
has_fields(it doesn't make sense for regularization to have thisattribute).
Remove
L2ObjectiveFunction. It was only use to create theBaseDataMisfitclass, forcing it to be only an L2 class. Moreover, most of its methods were
being overwritten by the
BaseDataMisfitandL2DataMisfit, so it didn't havea clear purpose.
Make
BaseDataMisfitandBaseRegularizationabstract classes:BaseDataMisfitrequire children to implement__call__,derivandderiv2.BaseRegularizationrequire children to implementf_mandf_m_derivAdditional information