Skip to content
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

Lens based API for statistics calculation (mean, stddev, etc) #162

Open
Shimuuar opened this issue Jan 5, 2020 · 0 comments
Open

Lens based API for statistics calculation (mean, stddev, etc) #162

Shimuuar opened this issue Jan 5, 2020 · 0 comments

Comments

@Shimuuar
Copy link
Collaborator

Shimuuar commented Jan 5, 2020

This is one way to resolve #146. All examples here will use mean but readily generalizes to all fold based estimators and with some problems to quantiles and like which will require building intermediate vector.

Current implementation of mean have following signature: mean :: (G.Vector v Double) => v Double -> Double and as such could only work with vectors. Which is very inconvenient. Proposal is to take Getting for data structure as parameter

meanOf :: Getting (Endo (Endo MeanKBN)) s Double -> s -> Double

This surprisingly powerful API. Here are examples

  1. meanOf each will compute mean of instance of Each type class that it will work for vector, lists, Maps and lot of other data structures
  2. meanof folded will work for any Foldable
  3. meanOf (each . each) will compute mean of nested containers
  4. meanOf (each . filtered (>0) . to log) will compute mean of logarithm of every positive number.

So this is very powerful and generic API. Preliminary benchmarks indicate that it's possible to get performance identical to current implementation. Only downside it requires use of lens but I think gained power worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant