Skip to content

Investigate suspicious implementation of Poisson.logpdf #251

@fsaad

Description

@fsaad

Specifically the following lines

@staticmethod
def calc_predictive_logp(x, N, sum_x, a, b):
an, bn = Poisson.posterior_hypers(N, sum_x, a, b)
am, bm = Poisson.posterior_hypers(N+1, sum_x+x, a, b)
ZN = Poisson.calc_log_Z(an, bn)
ZM = Poisson.calc_log_Z(am, bm)
return ZM - ZN - gammaln(x+1)
@staticmethod
def calc_logpdf_marginal(N, sum_x, sum_log_fact_x, a, b):
an, bn = Poisson.posterior_hypers(N, sum_x, a, b)
Z0 = Poisson.calc_log_Z(a, b)
ZN = Poisson.calc_log_Z(an, bn)
return ZN - Z0 - sum_log_fact_x
@staticmethod
def posterior_hypers(N, sum_x, a, b):
an = a + sum_x
bn = b + N
return an, bn
@staticmethod
def calc_log_Z(a, b):
Z = gammaln(a) - a*log(b)
return Z

The posterior predictive distribution should be a negative binomial with n = a' and p = 1 / (1 + b'), or possibly p = 1 - 1/(1+b'), depending on the parameterization. From a cursory test the values returned by Poisson.calc_predictive_logp do not correspond to the negative binomial probabilities from scipy.stats.nbinom.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions