@@ -3959,6 +3959,21 @@ def _distr_parameters_for_repr(self):
3959
3959
return []
3960
3960
3961
3961
3962
+ class MoyalRV (RandomVariable ):
3963
+ name = "moyal"
3964
+ ndim_supp = 0
3965
+ ndims_params = [0 , 0 ]
3966
+ dtype = "floatX"
3967
+ _print_name = ("Moyal" , "\\ operatorname{Moyal}" )
3968
+
3969
+ @classmethod
3970
+ def rng_fn (cls , rng , mu , sigma , size = None ):
3971
+ return stats .moyal .rvs (mu , sigma , size = size , random_state = rng )
3972
+
3973
+
3974
+ moyal = MoyalRV ()
3975
+
3976
+
3962
3977
class Moyal (Continuous ):
3963
3978
r"""
3964
3979
Moyal log-likelihood.
@@ -4006,43 +4021,18 @@ class Moyal(Continuous):
4006
4021
sigma: float
4007
4022
Scale parameter (sigma > 0).
4008
4023
"""
4024
+ rv_op = moyal
4009
4025
4010
- def __init__ (self , mu = 0 , sigma = 1.0 , * args , ** kwargs ):
4011
- self .mu = at .as_tensor_variable (floatX (mu ))
4012
- self .sigma = at .as_tensor_variable (floatX (sigma ))
4026
+ @classmethod
4027
+ def dist (cls , mu = 0 , sigma = 1.0 , * args , ** kwargs ):
4028
+ mu = at .as_tensor_variable (floatX (mu ))
4029
+ sigma = at .as_tensor_variable (floatX (sigma ))
4013
4030
4014
4031
assert_negative_support (sigma , "sigma" , "Moyal" )
4015
4032
4016
- self .mean = self .mu + self .sigma * (np .euler_gamma + at .log (2 ))
4017
- self .median = self .mu - self .sigma * at .log (2 * at .erfcinv (1 / 2 ) ** 2 )
4018
- self .mode = self .mu
4019
- self .variance = (np .pi ** 2 / 2.0 ) * self .sigma ** 2
4020
-
4021
- super ().__init__ (* args , ** kwargs )
4022
-
4023
- def random (self , point = None , size = None ):
4024
- """
4025
- Draw random values from Moyal distribution.
4026
-
4027
- Parameters
4028
- ----------
4029
- point: dict, optional
4030
- Dict of variable values on which random values are to be
4031
- conditioned (uses default point if not specified).
4032
- size: int, optional
4033
- Desired size of random sample (returns one sample if not
4034
- specified).
4035
-
4036
- Returns
4037
- -------
4038
- array
4039
- """
4040
- # mu, sigma = draw_values([self.mu, self.sigma], point=point, size=size)
4041
- # return generate_samples(
4042
- # stats.moyal.rvs, loc=mu, scale=sigma, dist_shape=self.shape, size=size
4043
- # )
4033
+ return super ().dist ([mu , sigma ], * args , ** kwargs )
4044
4034
4045
- def logp (self , value ):
4035
+ def logp (value , mu , sigma ):
4046
4036
"""
4047
4037
Calculate log-probability of Moyal distribution at specified value.
4048
4038
@@ -4056,15 +4046,13 @@ def logp(self, value):
4056
4046
-------
4057
4047
TensorVariable
4058
4048
"""
4059
- mu = self .mu
4060
- sigma = self .sigma
4061
4049
scaled = (value - mu ) / sigma
4062
4050
return bound (
4063
4051
(- (1 / 2 ) * (scaled + at .exp (- scaled )) - at .log (sigma ) - (1 / 2 ) * at .log (2 * np .pi )),
4064
4052
0 < sigma ,
4065
4053
)
4066
4054
4067
- def logcdf (self , value ):
4055
+ def logcdf (value , mu , sigma ):
4068
4056
"""
4069
4057
Compute the log of the cumulative distribution function for Moyal distribution
4070
4058
at the specified value.
@@ -4079,9 +4067,6 @@ def logcdf(self, value):
4079
4067
-------
4080
4068
TensorVariable
4081
4069
"""
4082
- mu = self .mu
4083
- sigma = self .sigma
4084
-
4085
4070
scaled = (value - mu ) / sigma
4086
4071
return bound (
4087
4072
at .log (at .erfc (at .exp (- scaled / 2 ) * (2 ** - 0.5 ))),
0 commit comments