Skip to content

Commit fafc732

Browse files
aseyboldttwiecki
authored andcommitted
Fix some whitespace issues in discrete.py
1 parent a7ed257 commit fafc732

File tree

1 file changed

+54
-27
lines changed

1 file changed

+54
-27
lines changed

pymc3/distributions/discrete.py

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,13 @@ def logp(self, value):
632632
psi = self.psi
633633
theta = self.theta
634634

635-
logp_val = tt.switch(tt.gt(value, 0),
636-
tt.log(psi) + self.pois.logp(value),
637-
logaddexp(tt.log1p(-psi), tt.log(psi) - theta))
635+
logp_val = tt.switch(
636+
tt.gt(value, 0),
637+
tt.log(psi) + self.pois.logp(value),
638+
logaddexp(tt.log1p(-psi), tt.log(psi) - theta))
638639

639-
return bound(logp_val,
640+
return bound(
641+
logp_val,
640642
0 <= value,
641643
0 <= psi, psi <= 1,
642644
0 <= theta)
@@ -700,11 +702,13 @@ def logp(self, value):
700702
p = self.p
701703
n = self.n
702704

703-
logp_val = tt.switch(tt.gt(value, 0),
704-
tt.log(psi) + self.bin.logp(value),
705-
logaddexp(tt.log1p(-psi), tt.log(psi) + n * tt.log1p(-p)))
705+
logp_val = tt.switch(
706+
tt.gt(value, 0),
707+
tt.log(psi) + self.bin.logp(value),
708+
logaddexp(tt.log1p(-psi), tt.log(psi) + n * tt.log1p(-p)))
706709

707-
return bound(logp_val,
710+
return bound(
711+
logp_val,
708712
0 <= value, value <= n,
709713
0 <= psi, psi <= 1,
710714
0 <= p, p <= 1)
@@ -715,10 +719,14 @@ def _repr_latex_(self, name=None, dist=None):
715719
n = dist.n
716720
p = dist.p
717721
psi = dist.psi
718-
return r'${} \sim \text{{ZeroInflatedBinomial}}(\mathit{{n}}={}, \mathit{{p}}={}, \mathit{{psi}}={})$'.format(name,
719-
get_variable_name(n),
720-
get_variable_name(p),
721-
get_variable_name(psi))
722+
723+
name_n = get_variable_name(n)
724+
name_p = get_variable_name(p)
725+
name_psi = get_variable_name(psi)
726+
return (r'${} \sim \text{{ZeroInflatedBinomial}}'
727+
r'(\mathit{{n}}={}, \mathit{{p}}={}, '
728+
r'\mathit{{psi}}={})$'
729+
.format(name, name_n, name_p, name_psi))
722730

723731

724732
class ZeroInflatedNegativeBinomial(Discrete):
@@ -731,10 +739,18 @@ class ZeroInflatedNegativeBinomial(Discrete):
731739
732740
.. math::
733741
734-
f(x \mid \psi, \mu, \alpha) = \left\{ \begin{array}{l}
735-
(1-\psi) + \psi \left (\frac{\alpha}{\alpha+\mu} \right) ^\alpha, \text{if } x = 0 \\
736-
\psi \frac{\Gamma(x+\alpha)}{x! \Gamma(\alpha)} \left (\frac{\alpha}{\mu+\alpha} \right)^\alpha \left( \frac{\mu}{\mu+\alpha} \right)^x, \text{if } x=1,2,3,\ldots
737-
\end{array} \right.
742+
f(x \mid \psi, \mu, \alpha) = \left\{
743+
\begin{array}{l}
744+
(1-\psi) + \psi \left (
745+
\frac{\alpha}{\alpha+\mu}
746+
\right) ^\alpha, \text{if } x = 0 \\
747+
\psi \frac{\Gamma(x+\alpha)}{x! \Gamma(\alpha)} \left (
748+
\frac{\alpha}{\mu+\alpha}
749+
\right)^\alpha \left(
750+
\frac{\mu}{\mu+\alpha}
751+
\right)^x, \text{if } x=1,2,3,\ldots
752+
\end{array}
753+
\right.
738754
739755
======== ==========================
740756
Support :math:`x \in \mathbb{N}_0`
@@ -776,22 +792,33 @@ def logp(self, value):
776792
mu = self.mu
777793
psi = self.psi
778794

779-
logp_val = tt.switch(tt.gt(value, 0),
780-
tt.log(psi) + self.nb.logp(value),
781-
logaddexp(tt.log1p(-psi), tt.log(psi) + alpha * (tt.log(alpha) - tt.log(alpha + mu))))
795+
logp_other = tt.log(psi) + self.nb.logp(value)
796+
logp_0 = logaddexp(
797+
tt.log1p(-psi),
798+
tt.log(psi) + alpha * (tt.log(alpha) - tt.log(alpha + mu)))
799+
800+
logp_val = tt.switch(
801+
tt.gt(value, 0),
802+
logp_other,
803+
logp_0)
782804

783-
return bound(logp_val,
784-
0 <= value,
785-
0 <= psi, psi <= 1,
786-
mu > 0, alpha > 0)
805+
return bound(
806+
logp_val,
807+
0 <= value,
808+
0 <= psi, psi <= 1,
809+
mu > 0, alpha > 0)
787810

788811
def _repr_latex_(self, name=None, dist=None):
789812
if dist is None:
790813
dist = self
791814
mu = dist.mu
792815
alpha = dist.alpha
793816
psi = dist.psi
794-
return r'${} \sim \text{{ZeroInflatedNegativeBinomial}}(\mathit{{mu}}={}, \mathit{{alpha}}={}, \mathit{{psi}}={})$'.format(name,
795-
get_variable_name(mu),
796-
get_variable_name(alpha),
797-
get_variable_name(psi))
817+
818+
name_mu = get_variable_name(mu)
819+
name_alpha = get_variable_name(alpha)
820+
name_psi = get_variable_name(psi)
821+
return (r'${} \sim \text{{ZeroInflatedNegativeBinomial}}'
822+
r'(\mathit{{mu}}={}, \mathit{{alpha}}={}, '
823+
r'\mathit{{psi}}={})$'
824+
.format(name, name_mu, name_alpha, name_psi))

0 commit comments

Comments
 (0)