Exemplo n.º 1
0
    def __display_and_normalization(self, display_type, normalization):

        if not self.list_of_samples:
            raise ValueError(
                'Empty attribute `list_of_samples`, sample first!')
        else:
            points = self.list_of_samples[-1].copy()  # Pick last sample

        N, M_1, M_2 = [
            self.params[key] for key in ['size_N', 'size_M1', 'size_M2']
        ]

        fig, ax = plt.subplots(1, 1)
        # Title
        str_ratio = r'with ratios $M_1/N \approx {:.3f}, M_2/N \approx {:.3f}$'.format(
            M_1 / N, M_2 / N)  # Answers Issue #33 raised by @adrienhardy
        str_beta = '' if self.beta > 0 else 'with i.i.d. draws'
        title = '\n'.join([self._str_title(), ' '.join([str_ratio, str_beta])])
        plt.title(title)

        if self.beta == 0:
            if normalization:
                # Display Beta(a,b) reference measure
                a, b = [self.params[key] for key in ['a', 'b']]
                x = np.linspace(0, 1, 100)
                ax.plot(x,
                        sp_beta.pdf(x, a=a, b=b),
                        'r-',
                        lw=2,
                        alpha=0.6,
                        label=r'$\operatorname{{Beta}}({},{})$'.format(a, b))
        else:  # self.beta > 0
            if normalization:
                # Display the limiting distribution: Wachter law
                eps = 5e-3
                x = np.linspace(eps, 1.0 - eps, 500)
                ax.plot(x,
                        rm.wachter_law(x, M_1, M_2, N),
                        'r-',
                        lw=2,
                        alpha=0.6,
                        label=r'$f_{Wachter}$')

        if display_type == 'scatter':
            ax.scatter(points,
                       np.zeros(points.shape[0]),
                       c='blue',
                       label='sample')

        elif display_type == 'hist':
            ax.hist(points,
                    bins=30,
                    density=1,
                    facecolor='blue',
                    alpha=0.5,
                    label='hist')
        else:
            pass

        plt.legend(loc='best', frameon=False)
Exemplo n.º 2
0
    def test_wachter_for_jacobi_ensemble_banded_model(self):
        """
        """

        M_1, M_2 = 2 * self.N, 4 * self.N
        a, b = M_1 / self.N, M_2 / self.N
        supp = ((np.sqrt(a * (a + b - 1)) + np.array([-1, 1]) * np.sqrt(b)) /
                (a + b))**2

        tol = 1e-2
        bins = np.linspace(supp[0] + tol, supp[1] - tol, 20)

        f_theo = [
            quad(lambda x: rm.wachter_law(x, M_1, M_2, self.N), a, b)[0]
            for a, b in zip(bins[:-1], bins[1:])
        ]

        for beta in (1, 2, 4):

            je = be.JacobiEnsemble(beta)

            for _ in range(self.nb_samples):
                je.sample_banded_model(size_N=self.N, size_M1=M_1, size_M2=M_2)

                vals, _ =\
                    np.histogram(je.list_of_samples[-1],
                                 bins=bins,
                                 density=True)

                f_emp = vals * np.diff(bins)
                print(f_emp)

                self.assertTrue(self.adequation(f_emp, f_theo))
Exemplo n.º 3
0
 def limiting_distribution(x):
     return rm.wachter_law(x, M_1, M_2, N)