@@ -3959,6 +3959,21 @@ def _distr_parameters_for_repr(self):
39593959 return []
39603960
39613961
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+
39623977class Moyal (Continuous ):
39633978 r"""
39643979 Moyal log-likelihood.
@@ -4006,43 +4021,18 @@ class Moyal(Continuous):
40064021 sigma: float
40074022 Scale parameter (sigma > 0).
40084023 """
4024+ rv_op = moyal
40094025
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 ))
40134030
40144031 assert_negative_support (sigma , "sigma" , "Moyal" )
40154032
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 )
40444034
4045- def logp (self , value ):
4035+ def logp (value , mu , sigma ):
40464036 """
40474037 Calculate log-probability of Moyal distribution at specified value.
40484038
@@ -4056,15 +4046,13 @@ def logp(self, value):
40564046 -------
40574047 TensorVariable
40584048 """
4059- mu = self .mu
4060- sigma = self .sigma
40614049 scaled = (value - mu ) / sigma
40624050 return bound (
40634051 (- (1 / 2 ) * (scaled + at .exp (- scaled )) - at .log (sigma ) - (1 / 2 ) * at .log (2 * np .pi )),
40644052 0 < sigma ,
40654053 )
40664054
4067- def logcdf (self , value ):
4055+ def logcdf (value , mu , sigma ):
40684056 """
40694057 Compute the log of the cumulative distribution function for Moyal distribution
40704058 at the specified value.
@@ -4079,9 +4067,6 @@ def logcdf(self, value):
40794067 -------
40804068 TensorVariable
40814069 """
4082- mu = self .mu
4083- sigma = self .sigma
4084-
40854070 scaled = (value - mu ) / sigma
40864071 return bound (
40874072 at .log (at .erfc (at .exp (- scaled / 2 ) * (2 ** - 0.5 ))),
0 commit comments