Esempio n. 1
0
    def compile_operation(state):
        """Compile a callable operation that samples the associated distribution.

        Parameters
        ----------
        state : dict

        """
        size = state['size']
        distribution = state['distribution']
        if not (size is None or isinstance(size, tuple)):
            size = (size, )

        # Note: sending the scipy distribution object also pickles the global numpy random
        # state with it. If this needs to be avoided, the object needs to be constructed
        # on the worker.
        if isinstance(distribution, str):
            distribution = scipy_from_str(distribution)

        if not hasattr(distribution, 'rvs'):
            raise ValueError(
                "Distribution {} "
                "must implement a rvs method".format(distribution))

        op = partial(rvs_from_distribution,
                     distribution=distribution,
                     size=size)
        return op
Esempio n. 2
0
 def distribution(self):
     """Return the distribution object."""
     distribution = self['distribution']
     if isinstance(distribution, str):
         distribution = scipy_from_str(distribution)
     return distribution