Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Statistics/Distribution/Poisson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@
import Data.Binary (Binary(..))
import Data.Data (Data, Typeable)
import GHC.Generics (Generic)

import qualified System.Random.MWC.Distributions as MWC

import Numeric.SpecFunctions (incompleteGamma,logFactorial)
import Numeric.MathFunctions.Constants (m_neg_inf)


import qualified Statistics.Distribution as D
import qualified Statistics.Distribution.Poisson.Internal as I
import Statistics.Internal



newtype PoissonDistribution = PD {
poissonLambda :: Double
} deriving (Eq, Typeable, Data, Generic)

Check warning on line 48 in Statistics/Distribution/Poisson.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.12.2

• Deriving ‘Typeable’ has no effect: all types now auto-derive Typeable

Check warning on line 48 in Statistics/Distribution/Poisson.hs

View workflow job for this annotation

GitHub Actions / macos-latest / ghc 9.12.2

• Deriving ‘Typeable’ has no effect: all types now auto-derive Typeable

instance Show PoissonDistribution where
showsPrec i (PD l) = defaultShow1 "poisson" l i
Expand Down Expand Up @@ -93,6 +96,14 @@
instance D.MaybeEntropy PoissonDistribution where
maybeEntropy = Just . D.entropy

-- | @since 0.16.5.0
instance D.DiscreteGen PoissonDistribution where
genDiscreteVar (PD lambda) = MWC.poisson lambda

-- | @since 0.16.5.0
instance D.ContGen PoissonDistribution where
genContVar (PD lambda) gen = fromIntegral <$> MWC.poisson lambda gen

Comment on lines +104 to +106
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop ContGen instance. It is discrete distribution after all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Shimuuar , i am not able to drop ContGen:

class (DiscreteDistr d, ContGen d) => DiscreteGen d where
  genDiscreteVar :: (StatefulGen g m) => d -> g -> m Int

class (DiscreteDistr d, ContGen d) => DiscreteGen d where

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Sorry I forgot about it

-- | Create Poisson distribution.
poisson :: Double -> PoissonDistribution
poisson l = maybe (error $ errMsg l) id $ poissonE l
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Changes in 0.16.5.0 [2026.01.09]

* `ContGen` and `DiscreteGen` instances for `Poisson` distributions are added.


## Changes in 0.16.4.0 [2025.10.23]

* Bartlett's test (`Statistics.Test.Bartlett`) and Levene's test
Expand Down
4 changes: 2 additions & 2 deletions statistics.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: 3.0
build-type: Simple

name: statistics
version: 0.16.4.0
version: 0.16.5.0
synopsis: A library of statistical types, data, and functions
description:
This library provides a number of common functions and types useful
Expand Down Expand Up @@ -128,7 +128,7 @@ library
build-depends: base >= 4.9 && < 5
--
, math-functions >= 0.3.4.1
, mwc-random >= 0.15.0.0
, mwc-random >= 0.15.3.0
, random >= 1.2
--
, aeson >= 0.6.0.0
Expand Down
Loading