|
28 | 28 | 'Laplace', 'StudentT', 'Cauchy', 'HalfCauchy', 'Gamma', 'Weibull',
|
29 | 29 | 'HalfStudentT', 'StudentTpos', 'Lognormal', 'ChiSquared',
|
30 | 30 | 'HalfNormal', 'Wald', 'Pareto', 'InverseGamma', 'ExGaussian',
|
31 |
| - 'VonMises', 'SkewNormal', 'Interpolated'] |
| 31 | + 'VonMises', 'SkewNormal', 'Logistic', 'Interpolated'] |
32 | 32 |
|
33 | 33 |
|
34 | 34 | class PositiveContinuous(Continuous):
|
@@ -1931,6 +1931,83 @@ def _repr_latex_(self, name=None, dist=None):
|
1931 | 1931 | get_variable_name(beta))
|
1932 | 1932 |
|
1933 | 1933 |
|
| 1934 | +class Logistic(Continuous): |
| 1935 | + R""" |
| 1936 | + Logistic log-likelihood. |
| 1937 | +
|
| 1938 | + .. math:: |
| 1939 | +
|
| 1940 | + f(x \mid \mu, s) = |
| 1941 | + \frac{\exp\left(-\frac{x - \mu}{s}\right)}{s \left(1 + \exp\left(-\frac{x - \mu}{s}\right)\right)^2} |
| 1942 | +
|
| 1943 | + ======== ========================================== |
| 1944 | + Support :math:`x \in \mathbb{R}` |
| 1945 | + Mean :math:`\mu` |
| 1946 | + Variance :math:`\frac{s^2 \pi^2}{3}` |
| 1947 | + ======== ========================================== |
| 1948 | +
|
| 1949 | + .. plot:: |
| 1950 | +
|
| 1951 | + import matplotlib.pyplot as plt |
| 1952 | + import numpy as np |
| 1953 | + import scipy.stats as st |
| 1954 | + x = np.linspace(-5.0, 5.0, 1000) |
| 1955 | + fig, ax = plt.subplots() |
| 1956 | + f = lambda mu, s : st.logistic.pdf(x, loc=mu, scale=s) |
| 1957 | + plot_pdf = lambda a, b : ax.plot(x, f(a,b), label=r'$\mu$={0}, $s$={1}'.format(a,b)) |
| 1958 | + plot_pdf(0.0, 0.4) |
| 1959 | + plot_pdf(0.0, 1.0) |
| 1960 | + plot_pdf(0.0, 2.0) |
| 1961 | + plot_pdf(-2.0, 0.4) |
| 1962 | + plt.legend(loc='upper right', frameon=False) |
| 1963 | + ax.set(xlim=[-5,5], ylim=[0,1.2], xlabel='x', ylabel='f(x)') |
| 1964 | + plt.show() |
| 1965 | +
|
| 1966 | + Parameters |
| 1967 | + ---------- |
| 1968 | + mu : float |
| 1969 | + Mean. |
| 1970 | + s : float |
| 1971 | + Scale (s > 0). |
| 1972 | + """ |
| 1973 | + def __init__(self, mu=0., s=1., *args, **kwargs): |
| 1974 | + super(Logistic, self).__init__(*args, **kwargs) |
| 1975 | + |
| 1976 | + self.mu = tt.as_tensor_variable(mu) |
| 1977 | + self.s = tt.as_tensor_variable(s) |
| 1978 | + |
| 1979 | + self.mean = self.mode = mu |
| 1980 | + self.variance = s**2 * np.pi**2 / 3. |
| 1981 | + |
| 1982 | + def logp(self, value): |
| 1983 | + mu = self.mu |
| 1984 | + s = self.s |
| 1985 | + |
| 1986 | + return bound( |
| 1987 | + -(value - mu) / s - tt.log(s) - 2 * tt.log1p(tt.exp(-(value - mu) / s)), |
| 1988 | + s > 0 |
| 1989 | + ) |
| 1990 | + |
| 1991 | + def random(self, point=None, size=None, repeat=None): |
| 1992 | + mu, s = draw_values([self.mu, self.s], point=point) |
| 1993 | + |
| 1994 | + return generate_samples( |
| 1995 | + stats.logistic.rvs, |
| 1996 | + loc=mu, scale=s, |
| 1997 | + dist_shape=self.shape, |
| 1998 | + size=size |
| 1999 | + ) |
| 2000 | + |
| 2001 | + def _repr_latex_(self, name=None, dist=None): |
| 2002 | + if dist is None: |
| 2003 | + dist = self |
| 2004 | + mu = dist.mu |
| 2005 | + s = dist.s |
| 2006 | + return r'${} \sim \text{{Logistic}}(\mathit{{mu}}={}, \mathit{{s}}={})$'.format(name, |
| 2007 | + get_variable_name(mu), |
| 2008 | + get_variable_name(s)) |
| 2009 | + |
| 2010 | + |
1934 | 2011 | class Interpolated(Continuous):
|
1935 | 2012 | R"""
|
1936 | 2013 | Univariate probability distribution defined as a linear interpolation
|
|
0 commit comments