45
45
)
46
46
from pymc3 .distributions .distribution import Continuous , draw_values , generate_samples
47
47
from pymc3 .distributions .special import log_i0
48
- from pymc3 .math import invlogit , log1mexp , logdiffexp , logit
48
+ from pymc3 .math import invlogit , log1mexp , log1pexp , logdiffexp , logit
49
49
from pymc3 .theanof import floatX
50
50
51
51
__all__ = [
@@ -3887,25 +3887,6 @@ def __init__(self, mu=0.0, s=1.0, *args, **kwargs):
3887
3887
self .mean = self .mode = mu
3888
3888
self .variance = s ** 2 * np .pi ** 2 / 3.0
3889
3889
3890
- def logp (self , value ):
3891
- """
3892
- Calculate log-probability of Logistic distribution at specified value.
3893
-
3894
- Parameters
3895
- ----------
3896
- value: numeric
3897
- Value(s) for which log-probability is calculated. If the log probabilities for multiple
3898
- values are desired the values must be provided in a numpy array or theano tensor
3899
-
3900
- Returns
3901
- -------
3902
- TensorVariable
3903
- """
3904
- mu = self .mu
3905
- s = self .s
3906
-
3907
- return bound (- (value - mu ) / s - tt .log (s ) - 2 * tt .log1p (tt .exp (- (value - mu ) / s )), s > 0 )
3908
-
3909
3890
def random (self , point = None , size = None ):
3910
3891
"""
3911
3892
Draw random values from Logistic distribution.
@@ -3929,17 +3910,33 @@ def random(self, point=None, size=None):
3929
3910
stats .logistic .rvs , loc = mu , scale = s , dist_shape = self .shape , size = size
3930
3911
)
3931
3912
3913
+ def logp (self , value ):
3914
+ """
3915
+ Calculate log-probability of Logistic distribution at specified value.
3916
+
3917
+ Parameters
3918
+ ----------
3919
+ value: numeric
3920
+ Value(s) for which log-probability is calculated. If the log probabilities for multiple
3921
+ values are desired the values must be provided in a numpy array or theano tensor
3922
+
3923
+ Returns
3924
+ -------
3925
+ TensorVariable
3926
+ """
3927
+ mu = self .mu
3928
+ s = self .s
3929
+
3930
+ return bound (
3931
+ - (value - mu ) / s - tt .log (s ) - 2 * tt .log1p (tt .exp (- (value - mu ) / s )),
3932
+ s > 0 ,
3933
+ )
3934
+
3932
3935
def logcdf (self , value ):
3933
3936
r"""
3934
3937
Compute the log of the cumulative distribution function for Logistic distribution
3935
3938
at the specified value.
3936
3939
3937
- References
3938
- ----------
3939
- .. [Machler2012] Martin Mächler (2012).
3940
- "Accurately computing :math: `\log(1-\exp(- \mid a \mid<))` Assessed by the Rmpfr
3941
- package"
3942
-
3943
3940
Parameters
3944
3941
----------
3945
3942
value: numeric or np.ndarray or theano.tensor
@@ -3952,14 +3949,7 @@ def logcdf(self, value):
3952
3949
"""
3953
3950
mu = self .mu
3954
3951
s = self .s
3955
- a = - (value - mu ) / s
3956
- return - tt .switch (
3957
- tt .le (a , - 37 ),
3958
- tt .exp (a ),
3959
- tt .switch (
3960
- tt .le (a , 18 ), tt .log1p (tt .exp (a )), tt .switch (tt .le (a , 33.3 ), tt .exp (- a ) + a , a )
3961
- ),
3962
- )
3952
+ return - log1pexp (- (value - mu ) / s )
3963
3953
3964
3954
3965
3955
class LogitNormal (UnitContinuous ):
0 commit comments