Пример #1
0
def plot_mixture(dists, weights, hi=1, lo=-1, support_thresh=0.1):
    """

    """
    fig = plt.figure()
    ax = fig.add_subplot(111)

    def mix_pdf(x):
        tot = 0

        for name, dist in dists.iteritems():
            tot += weights[name] * dist.pdf(x)

        return tot

    # plot mixture
    mix = plotting.plot_support(mix_pdf,
                                lo,
                                hi,
                                thresh=support_thresh,
                                style='k',
                                ax=ax)

    for _, dist in dists.iteritems():
        comp = plotting.plot_support(dist.pdf,
                                     lo,
                                     hi,
                                     thresh=support_thresh,
                                     style='k--',
                                     ax=ax)

    ax.legend((mix, comp), ('Mixture', 'Component'))
Пример #2
0
    def plot_forecast(self, x, ax=None, label=None, **kwds):
        """
        Plot posterior predictive distribution for input predictor values

        y ~ N(Xb, s^2)

        Parameters
        ----------
        x : 1d
        """
        if ax is None:
            ax = plt.gca()

        mode, scale = self.beta_post_params

        s2 = self.sigma2
        # forecast variance
        rQ = np.sqrt(s2 * (np.dot(x, np.dot(scale, x)) + 1))
        m = np.dot(x, self.params)

        dist = stats.norm(m, scale=rQ)

        plotting.plot_support(dist.pdf, m - 5 * rQ, m + 5 * rQ, ax=ax)

        if label is not None:
            y = dist.pdf(m)
            x = m
            ax.text(x, y, label, **kwds)
Пример #3
0
def plot_mixture(dists, weights, hi=1, lo=-1, support_thresh=0.1):
    """

    """
    fig = plt.figure()
    ax = fig.add_subplot(111)

    def mix_pdf(x):
        tot = 0

        for name, dist in dists.iteritems():
            tot += weights[name] * dist.pdf(x)

        return tot

    # plot mixture
    mix = plotting.plot_support(mix_pdf, lo, hi,
                                thresh=support_thresh,
                                style='k',
                                ax=ax)

    for _, dist in dists.iteritems():
        comp = plotting.plot_support(dist.pdf, lo, hi,
                                     thresh=support_thresh,
                                     style='k--',
                                     ax=ax)

    ax.legend((mix, comp), ('Mixture', 'Component'))
Пример #4
0
    def plot_forecast(self, x, ax=None, label=None, **kwds):
        """
        Plot posterior predictive distribution for input predictor values

        y ~ N(Xb, s^2)

        Parameters
        ----------
        x : 1d
        """
        if ax is None:
            ax = plt.gca()

        mode, scale = self.beta_post_params

        s2 = self.sigma2
        # forecast variance
        rQ = np.sqrt(s2 * (np.dot(x, np.dot(scale, x)) + 1))
        m = np.dot(x, self.params)

        dist = stats.norm(m, scale=rQ)

        plotting.plot_support(dist.pdf, m - 5 * rQ, m + 5 * rQ, ax=ax)

        if label is not None:
            y = dist.pdf(m)
            x = m
            ax.text(x, y, label, **kwds)
Пример #5
0
    def plot(self, style='k', ax=None, **plot_kwds):

        max_sd = np.sqrt(self.variances.max())

        # overkill perhaps
        lo = self.means.min() - 4 * max_sd
        hi = self.means.max() + 4 * max_sd

        if ax is None:
            ax = plt.gca()

        plotting.plot_support(self.pdf, lo, hi, style=style, **plot_kwds)
Пример #6
0
    def plot(self, style='k', ax=None, **plot_kwds):

        max_sd = np.sqrt(self.variances.max())

        # overkill perhaps
        lo = self.means.min() - 4 * max_sd
        hi = self.means.max() + 4 * max_sd

        if ax is None:
            ax = plt.gca()

        plotting.plot_support(self.pdf, lo, hi, style=style,
                              **plot_kwds)