Examples of random() in custom distribution?

I am trying to implement the random method for DensityDist, but I do not understand how the function should be implemented. I would like to get a template to follow.

For example, for the logp function this information (from this post) is very useful (we should include it in the documentation):

# Log likelihood function
def logp_function(parameters):
    def logp(observed):
        _logp = some_function(parameters, observed)
        return _logp 

    return logp # returns a function

Is there anything similar for random?
The example you provided in the post above uses normal_dist.random. The random method is:

def random(self, point=None, size=None):
        """
        Draw random values from Normal distribution.
        Parameters
        ----------
        point : dict, optional
            Dict of variable values on which random values are to be
            conditioned (uses default point if not specified).
        size : int, optional
            Desired size of random sample (returns one sample if not
            specified).
        Returns
        -------
        array
        """
        mu, tau, _ = draw_values([self.mu, self.tau, self.sd],
                                 point=point, size=size)
        return generate_samples(stats.norm.rvs, loc=mu, scale=tau**-0.5,
                                dist_shape=self.shape,
                                size=size)

but I have difficulties to create a standalone function from the method in the class. For example, how do I pass the parameters for my function? Do I need to use draw_values and generate_samples? If so, how to pass the parameter point and shape?

1 Like