MastodonC / kixi.stats

A library of statistical distribution sampling and transducing functions
https://cljdoc.xyz/d/kixi/stats
Eclipse Public License 1.0
355 stars 17 forks source link

Add min, max, share, and monoid #16

Closed sbelak closed 6 years ago

sbelak commented 6 years ago

This adds a couple more reducing functions that I always end up writing (min, max, share), and a version of monoid that works with transducers.

I'm not entirely sure it is correct for min to return Double/POSITIVE_INFINITY. It is an identity wrt to min, but can mess up other math operations if you don't expect it (or just look weird). An alternative would be to return nil, which is consistent with behaviour elsewhere when working with empty datasets.

henrygarner commented 6 years ago

@sbelak this is excellent, thank you. My preference would be for min and max to return nil in the degenerate case. You're right that this seems more consistent with the rest of the API (for better or worse...).

If you could update the PR I'll merge it in.

sbelak commented 6 years ago

Changed to a hybrid version. I wanted to avoid another nil check at each step, but it might be better to do the straightforward version. Your call.

Also changed share to return a double to me more consistent as we work with and coerce to double everywhere else.

sbelak commented 6 years ago

Any chance you can publish to Clojars. We're just about to release 0.30 of Metabase and I'd love to switch over.

henrygarner commented 6 years ago

Done, just released v0.4.1 🎉