Exemplo n.º 1
0
 def prior(self) -> Gamma:
     """
     Return a Gamma distribution reflecting the prior belief about the
     distribution of the parameter λ, before seeing any data.
     """
     return Gamma(alpha=self._alpha, beta=self._beta).with_y_label(
         '$P(λ_{Poi}=x|'
         'α_{Gam},'
         'β_{Gam})$').prepend_to_label('Prior: ')
Exemplo n.º 2
0
 def posterior(self) -> Gamma:
     """
     Return a Gamma distribution reflecting the posterior belief about the
     distribution of the parameter λ, after observing the data.
     """
     return Gamma(alpha=self.alpha_prime,
                  beta=self.beta_prime).with_y_label(
                      r'$P(λ_{Poi}=x|'
                      r'α_{Gam}+k_{Obs},'
                      r'β_{Gam}+n_{Obs})$').prepend_to_label('Posterior: ')
Exemplo n.º 3
0
 def prior(self) -> Gamma:
     return Gamma(
         alpha=self._alpha,
         beta=self._beta).with_x_label('λ').prepend_to_label('Prior: ')
Exemplo n.º 4
0
    def posterior(self) -> Gamma:

        return Gamma(alpha=self.alpha_prime,
                     beta=self.beta_prime).with_x_label('λ').prepend_to_label(
                         'Posterior: ')
Exemplo n.º 5
0
def plot_wikipedia_cdfs():
    """
    https://en.wikipedia.org/wiki/Gamma_distribution#/media/File:Gamma_distribution_cdf.svg
    """
    ax = new_axes()
    Gamma.from_k_theta(k=1, theta=2).cdf().plot(x=x, color='red', ax=ax)
    Gamma.from_k_theta(k=2, theta=2).cdf().plot(x=x, color='orange', ax=ax)
    Gamma.from_k_theta(k=3, theta=2).cdf().plot(x=x, color='yellow', ax=ax)
    Gamma.from_k_theta(k=5, theta=1).cdf().plot(x=x, color='green', ax=ax)
    Gamma.from_k_theta(k=9, theta=0.5).cdf().plot(x=x, color='black', ax=ax)
    Gamma.from_k_theta(k=7.5, theta=1).cdf().plot(x=x, color='blue', ax=ax)
    Gamma.from_k_theta(k=0.5, theta=1).cdf().plot(x=x, color='purple', ax=ax)
    ax.set_ylim(0, 1)
    ax.legend(loc='lower right')
    plt.show()