Skip to content

Commit

Permalink
Add new KDE function. (#1284)
Browse files Browse the repository at this point in the history
* New KDE function.
Added a new KDE function that can be used to estimate linear and circular data.
Decided to put everything in a new file (instead of numeric_utils) because these functions
required many utilities themselves.
Also, updated all functions that used the old  function.
The circular option is not yet passed to higher level functions. That is something to be done.

* Update according to requests

* Fix how circular data is handled and listed changes in CHANGELOG.
* In the previous version the function  tried to normalize
the angles to [-pi, pi) but it was not correct.
This commit includes a function  that works appropiately.

* Update according to required changes.

* Several changes according to the PR discussion and other suggestions received.
* Functions _circular_mean() and normalize_angle() now are in numeric_utils.py.
* If the array has more than 1 dimension, _check_type() tries to flatten it silenty. If it is not possible, an error is raised.
* Improved how bw_fct type and value are checked and reported.
* All functions now start with _ because they are all internals.
* _select_bw_method() no longer exists. Its functionality is now incorporated into _get_bw().
* Changed internal _bw_* functions to a common signature.
* Added DeprecationWarning to _fast_kde() and now it calls _kde().
* Added tests for _normalize_angle() and _circular_mean().
The following functions and their backends have been modified to incorporate the circular argument that is passed to _kde() as well as the new meaning of the argument bw (see below):
* plot_density()
* plot_kde()
* plot_dist()
* plot_posterior()
* plot_violion()
* calculate_point_estimate()
In addition, plot_kde() gained a new argument, adaptive, which is used to determine if the bandwidth is adaptive or not.
Finally, note the meaning of the argument bw has changed. It used to be a bandwidth multiplication factor Now it can be either a string indicating the bandwidth method or the bandwidth itself. The internal function _kde() has an argument bw_fct which is the multiplicative factor.

* DeprecationWarning replaced by FutureWarning

* Minor fixes
* custom_lims in _kde() can be a tuple but then it tried to modify an inmutable object. Now it is converted to a list internally.
* test_kde_scipy() had a slicing step that was not necessary an caused an error when unpacking
* No error is raised when the data passed has lenght of 0 or 1. It raises a warning and returns np.nan

* Minor modifications regarding last PR comments

* Update arviz/kde_utils.py

Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>

* Minor fixes

* fix docstrings

Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>
Co-authored-by: Ari Hartikainen <ahartikainen@users.noreply.github.com>
Co-authored-by: ahartikainen <ahartikainen@github.com>
  • Loading branch information
4 people authored Aug 5, 2020
1 parent 0a1f548 commit 74b332a
Show file tree
Hide file tree
Showing 30 changed files with 1,163 additions and 199 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
* update `radon` example dataset to current InferenceData schema specification (#1320)
* update `from_cmdstan` functionality and add warmup groups (#1330)
* restructure plotting code to be compatible with mpl>=3.3 (#1312)
* Replaced `_fast_kde()` with `kde()` which now also supports circular variables
via the argument `circular` (#1284).
* Replaced `_fast_kde()` with `kde()` which now also supports circular variables via the argument `circular` (#1284).

### Maintenance and fixes
* plot_posterior: fix overlap of hdi and rope (#1263)
* All the functions that used to call `_fast_kde`() now use `kde()` and have been updated to handle the new types returned (#1284).

### Deprecation

Expand Down
Loading

0 comments on commit 74b332a

Please sign in to comment.