Ejemplo n.º 1
0
    def set_dist(self, dist='uniform', kwds=None, dim=None):
        r"""
        TODO: Add this.
        """
        distribution = dist
        if (kwds is not None) and (dim is not None):
            self.dist.set_dist(distribution, kwds, dim)
        elif (kwds is None) and (dim is not None):
            self.dist.set_dist(dist=distribution, dim=dim)

        # Here we override the default errors printed by scipy.stats with our own.
        elif (kwds is None) and (
                distributions.supported_distributions(distribution) is 'chi2'):
            raise (AttributeError(
                "If you are using a chi2 distribution, please pass `df` as a key-value pair in a dictionary. Ex: {'df': 20}."
            ))
        elif (kwds is None) and (
                distributions.supported_distributions(distribution) is 'beta'):
            raise (AttributeError(
                "If you are using a Beta dist, please pass `a` and `b` as key-value pairs in a dictionary. Ex: {'a': 1, 'b': 1}"
            ))
        # the following allows for manual overrides not using the parametric object.
        # e.g. kwds = {'loc': [1,2,3]}
        elif dim is None:
            # print("INPUT: No dimension specified. You will be using `scipy.stats` for your distributions instead of the parametric object. Be warned that functions like `.pdf` may not work as expected.")
            if kwds is not None:
                self.dist = distributions.assign_dist(distribution, **kwds)
            else:
                self.dist = distributions.assign_dist(distribution)
        pass
Ejemplo n.º 2
0
    def set_observed_dist(self, distribution=None, kwds=None, dim=None):
        r"""
        TODO: Add this.
        """
        # If `distribution = None`, we query the pushforward density for the top 5% to get a MAP estimate
        # TODO print warning about the aforementioned.
        # TODO check sizes, ensure dimension agreement

        if distribution is not None:
            if (kwds is not None) and (dim is not None):
                self.observed_dist.set_dist(dim, distribution, kwds)
            elif (kwds is None) and (dim is not None):
                self.observed_dist.set_dist(dim, distribution)

            # Here we override the default errors printed by scipy.stats with our own.
            elif (kwds is None) and (
                    distributions.supported_distributions(distribution) is
                    'chi2'):
                raise (AttributeError(
                    "If you are using a chi2 distribution, please pass `df` as a key-value pair in a dictionary. Ex: {'df': 20}."
                ))
            elif (kwds is None) and (
                    distributions.supported_distributions(distribution) is
                    'beta'):
                raise (AttributeError(
                    "If you are using a Beta dist, please pass `a` and `b` as key-value pairs in a dictionary. Ex: {'a': 1, 'b': 1}"
                ))
            # the following allows for manual overrides not using the parametric object.
            # e.g. kwds = {'loc': [1,2,3]}
            elif dim is None:
                logging.warn(
                    "OBS: No dimension specified. You will be using `scipy.stats` for your distributions instead of the parametric object. Be warned that functions like `.pdf` may not work as expected."
                )
                if kwds is not None:
                    self.observed_dist = distributions.assign_dist(
                        distribution, **kwds)
                else:
                    self.observed_dist = distributions.assign_dist(
                        distribution)

        else:
            logging.warn("""No distribution specified. 
            Defaulting to normal around data_means with 0.5*data_standard_deviation"""
                         )
            loc = np.mean(self.output.samples, axis=0)
            scale = 0.5 * np.std(self.output.samples, axis=0)
            self.observed_dist = distributions.assign_dist(
                'normal', **{
                    'loc': loc,
                    'scale': scale
                })
        pass