Skip to content

Logit-normal distribution #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
48 changes: 45 additions & 3 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
import warnings

from pymc3.theanof import floatX
from pymc3.math import logit
from . import transforms

from .dist_math import bound, logpow, gammaln, betaln, std_cdf, i0, i1, alltrue_elemwise
from .distribution import Continuous, draw_values, generate_samples, Bound

__all__ = ['Uniform', 'Flat', 'Normal', 'Beta', 'Exponential', 'Laplace',
'StudentT', 'Cauchy', 'HalfCauchy', 'Gamma', 'Weibull',
'HalfStudentT', 'StudentTpos', 'Lognormal', 'ChiSquared',
'HalfNormal', 'Wald', 'Pareto', 'InverseGamma', 'ExGaussian',
'VonMises', 'SkewNormal']
'HalfStudentT', 'StudentTpos', 'Lognormal', 'Logitnormal',
'ChiSquared', 'HalfNormal', 'Wald', 'Pareto', 'InverseGamma',
'ExGaussian', 'VonMises', 'SkewNormal']


class PositiveContinuous(Continuous):
Expand Down Expand Up @@ -643,6 +644,47 @@ def logp(self, value):
tau > 0)


class Logitnormal(PositiveContinuous):
Copy link
Member

Choose a reason for hiding this comment

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

I suppose it is unit continuous

R"""
Logit-normal log-likelihood.

.. math::

f(x \mid \mu, \tau) =
\frac{1}{x(1-x)} \sqrt{\frac{\tau}{2\pi}}
\exp\left\{ -\frac{\tau}{2} (logit(x)-\mu)^2 \right\}

======== =========================================================================
Support :math:`x \in (0, 1)`
Mean no analytical solution
Variance no analytical solution
======== =========================================================================

Parameters
----------
mu : float
Location parameter.
tau : float
Scale parameter (tau > 0).
"""

def __init__(self, mu=0.5, tau=None, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

We switched to parameterize by default using the sd.

super(Logitnormal, self).__init__(*args, **kwargs)

self.mu = mu = tt.as_tensor_variable(mu)
self.tau = tau = tt.as_tensor_variable(tau)

self.median = logit(mu)
assert_negative_support(tau, 'tau', 'Logitnormal')

def logp(self, value):
mu = self.mu
tau = self.tau
return bound(-0.5 * tau * (logit(value) - mu) ** 2
+ 0.5 * tt.log(tau / (2. * np.pi))
- tt.log(value * (1 - value)), value > 0, value < 1, tau > 0)


class StudentT(Continuous):
R"""
Non-central Student's T log-likelihood.
Expand Down