generateme / fastmath

Fast primitive based math library
MIT License
225 stars 11 forks source link

add ZAGA distribution #18

Closed aaelony closed 1 year ago

aaelony commented 2 years ago

As per discussion on Slack, useful distributions might be added to the already available list.

A somewhat exhaustive list for implementation might be here as described in the gamlss.dist R package, including the ZAGA (Zero Adjusted Gamma) distribution.

Thanks for this excellent library!

genmeblog commented 2 years ago

Thanks! Huge list :) Maybe you want to select some most important ones?

genmeblog commented 2 years ago

ZAGA is implemented now in the latest snapshot. Verified against R.

(def zaga (distribution :zaga {:nu 0.2 :mu 1.0 :sigma 2.0}))

(pdf zaga 2.0) ;; dZAGA
;; => 0.056269645152636466
(cdf zaga 2.0) ;; pZAGA
;; => 0.877189123353342
(icdf zaga 0.877189) ;; qZAGA
;; => 1.999997808161464
(->seq zaga 5) ;; random sampling
;; => (5.018629710149659 2.940219706530564E-5 0.03546063560460525 7.729955570235061 0.0)
(take 5 (->seq zaga))
;; => (0.05492161982459712 0.3927129129794207 0.0 0.006807764778811914 1.2644121020499126)
(->seq zaga 5 :uniform) ;; uniform sampling
;; => (0.0 0.0 2.0009003090803393E-4 0.05294466738236345 0.1262474855337676)
(->seq zaga 5 :systematic) ;; systematic sampling
;; => (0.0 2.3302775737303754E-4 0.039172264996012 0.3671356567919316 1.998563228048098)
(->seq zaga 5 :stratified) ;; stratified sampling
;; => (0.0 0.0018150201315259252 0.0782555215113504 0.5767730810426407 3.294239644450976)

Please list a couple more to be implemented or propose a PR (here is how ZAGA is implemented: https://github.com/generateme/fastmath/blob/master/src/fastmath/random.clj#L1570-L1628)

aaelony commented 2 years ago

Wow! Thanks for tackling ZAGA so quickly.

The main ones from my perspective are:

Thanks again!

genmeblog commented 2 years ago

Roughly tested, can you verify them on your side @aaelony ?

aaelony commented 2 years ago

Very nice. I'll try to look at these this week.

On Sep 11, 2022, at 15:59, genmeblog @.***> wrote:

 new distributions (based on R package gamlss.dist): :zaga - zero adjusted gamma distribution :nbi - negative binomial type I :zinbi - zero inflated negative binomial type I :zanbi - zero altered negative binomial type I :zip - poisson zero inflated :zip2 - zero inflated poisson 2 :exgaus - ex-Gaussian :zabi - zero adjusted binomial :zibi - binomial zero inflated :bb - beta binomial :zabb - zero adjusted beta binomial :zibb - zero inflated beta binomial Roughly tested, can you verify them on your side @aaelony ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

genmeblog commented 2 years ago

Cool. Some of them can be added to the fitdistr if you're interesting in distribution fitting.

genmeblog commented 1 year ago

ZAGA and some others are added, please open new issue if you need anything more.

aaelony commented 1 year ago

Thank-you, this is fantastic.