-
Notifications
You must be signed in to change notification settings - Fork 4
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
Document/Unit Test gempyor.statistics
#304
Conversation
* Wrote draft documentation for the `statistics` module in Google style guide.
* Added missing type annotations and corrected already existing ones. * Applied black formatter to the file, including manually correcting some line-length issues. * Rearranged dunder methods.
…docs Merging the 'unit-test-gempyor-parameters' branch into 'GH-300/statistics-unit-tests-docs' to get the confuse related testing utilities.
* Created initial unit testing infrastructure for the `Statistic` class from `gempyor.statistics`, starting with invalid regularization name value error. * Added default to `getattr` call to make unsupported regularization value error reachable. Should obsolete with better documentation.
* Added a test fixture to test the attributes of the `Statistic` class. * Removed unnecessary `tmp_path` pytest fixture dependency. * Improved documentation on the `Statistic` class' attributes and added a raises section for the constructor.
Added a test fixture for the result of calling `str` and `repr` on an instance of the `Statistic` class.
The return of `Statistic.llik` is actually an xarray DataArray instead of a float, but summed along the date dimension.
In particular see #300 (comment).
Added the initial unit tests for the regularization methods, `_forecast_regularize` and `_allsubpop_regularize`, of the `Statistic` class. The tests are general and do not make claims about correctness for now.
Added unit tests for the `apply_resample` method, including creating a new factory, `simple_valid_resample_factory`, which hits the "resample config present" of the code path.
Added unit tests for `apply_scale` method including a new factory that produces an input set with a 'scale' config. Fixed a bug where the scale function was not applied even if provided. This is a *breaking* change, but doesn't affect currently existing test suite, need to see if this affects any currently existing config files.
Added unit tests for the `apply_transforms` method of `Statistic`, including making a new factory that includes both resampling and scaling configuration.
Created global `all_valid_factories` that can be passed directly to the `pytest.mark.parametrize` decorator to test methods of the `Statistic` class against many configurations.
Added unit tests for the `llik` method of the `Statistic` class. Had to change factories to use RMSE by default for likelihood distribution since the poisson distribution only has integer support.
Was previously using `xarray.DataArray` for `model_data` and `gt_data` in unit testing the `Statistic` class since that is what many methods expect. It seems though the main entry to the class, `compute_logloss` takes an `xarray.DataSet` that the class splices into `xarray.DataArray`s. The unit tests now more accurately reflect this.
* Created initial unit tests on the `compute_logloss` method of `Statistic`, checking for structure but not correctness. * Updated documentation for `compute_logloss` to reflect the possible `ValueError` and the correct input types expected. * Changed internal variable of that method to a float to get a consistent float return for the second tuple entry from `compute_logloss`.
Added a test fixture that confirms the `ValueError` raised when model data and ground truth data do not have the same shapes in `Statistic.compute_logloss`.
There were entries in the mock configs, modeled on existing configs, that are not considered by the `Statistic` class at all. Removed for clarity.
The merge-base changed after approval.
I think this got lost at some point after GH-277 was merged in, but this should be ready to review. I will address these issues from GH-300 in a follow-up PR after this one (want to establish a baseline of testing for the class first):
likelihood = xr.DataArray(likelihood, coords=gt_data.coords, dims=gt_data.dims)
# TODO: check the order of the arguments
return likelihood
and
|
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.
All look good to me as a new baseline. The bug you've found for the llik is fixed in emcee_batch (which contains also the most recent "statistics" code) in case.
Would you mind referencing that commit on the main issue so that fact doesn't get lost? Thanks! |
isn't it already cause it contains the issue number ? I'll add a comment in case |
Ah, you're right, I missed that. |
This PR:
gempyor.statistics
module and its only classStatistic
,Statistic
class,gempyor.statistics
using the__all__
dunder, andThis PR does not:
In the process of this PR come across some issues that I've noted on the main issue, GH-300.
This PR derives from the branch in GH-277 because I needed the confuse related testing utilities, so it would be much easier to review this PR after reviewing/merging GH-277.