Beispiel #1
0
def plot_wikipedia_pdfs():
    """
    https://en.wikipedia.org/wiki/Normal_distribution#/media/File:Normal_Distribution_PDF.svg
    """
    ax = new_axes()
    Normal(mu=0, sigma_sq=0.2).plot(x=x, color='blue', ax=ax)
    Normal(mu=0, sigma_sq=1.0).plot(x=x, color='red', ax=ax)
    Normal(mu=0, sigma_sq=5.0).plot(x=x, color='orange', ax=ax)
    Normal(mu=-2, sigma_sq=0.5).plot(x=x, color='green', ax=ax)
    ax.legend(loc='upper right')
    plt.show()
Beispiel #2
0
 def likelihood(self, **kwargs) -> Normal:
     """
     Return a distribution reflecting the likelihood of observing
     the data, under a Normal model, independent of the prior belief
     about the distribution of parameter μ.
     """
     return Normal(mu=self._x_sum / self._n, sigma_sq=self._sigma_sq)
Beispiel #3
0
 def prior_predictive(self) -> Normal:
     """
     Return a Normal describing the expected distribution of future
     values based on the prior parameter estimates.
     """
     return Normal(mu=self.mu_0, sigma_sq=self.sigma_0_sq +
                   self.sigma_sq).with_y_label(r'$P(\tilde{X}=x|'
                                               r'μ_{Norm}=μ_{0, Norm},'
                                               r'σ²=σ²_{0, Norm}+σ²)$')
Beispiel #4
0
 def prior(self) -> Normal:
     """
     Return a Normal distribution reflecting the prior belief about the
     distribution of the parameter μ, before seeing any data.
     """
     if self._parameterization == 'σ²':
         y_label = ('$P(μ_{Norm}=x|' 'μ_{0, Norm},' 'σ²_{0, Norm})$')
     else:
         y_label = ('$P(μ_{Norm}=x|' 'μ_{0, Norm},' 'τ_{0, Norm})$')
     return Normal(mu=self.mu_0, sigma_sq=self.sigma_0_sq).with_x_label(
         'μ').with_y_label(y_label).prepend_to_label('Prior: ')
Beispiel #5
0
    def posterior(self) -> Normal:
        """
        Return a Normal distribution reflecting the posterior belief about the
        distribution of the parameter μ, after observing the data.
        """
        if self._parameterization == 'σ²':
            y_label = ('$P(μ_{Norm}=x|' 'μ_{0, Norm}′,' 'σ²_{0, Norm}′)$')
        else:
            y_label = ('$P(μ_{Norm}=x|' 'μ_{0, Norm}′,' 'τ_{0, Norm}′)$')

        return Normal(
            mu=self.mu_0_prime, sigma_sq=self.sigma_0_sq_prime).with_x_label(
                'μ').with_y_label(y_label).prepend_to_label('Posterior: ')
Beispiel #6
0
 def posterior(self) -> Normal:
     return Normal(mu=self.mu_0_prime,
                   sigma_sq=self.sigma_sq_0_prime).with_x_label(
                       'μ').prepend_to_label('Posterior: ')
Beispiel #7
0
 def prior(self) -> Normal:
     return Normal(mu=self.mu_0, sigma_sq=self.sigma_sq_0).with_x_label(
         'μ').prepend_to_label('Prior: ')