Ejemplo 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
            if normalization:
                points = self.normalize_points(points)

        N, M = [self.params[key] for key in ['size_N', 'size_M']]

        fig, ax = plt.subplots(1, 1)
        # Title
        str_ratio = r'with ratio $M/N \approx {:.3f}$'.format(M / 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 Gamma(k,2) reference measure of the full matrix model
                k, theta = self.params['shape'], 2
                x = np.linspace(0, np.max(points) + 4, 100)
                ax.plot(x,
                        sp_gamma.pdf(x, a=k, loc=0.0, scale=theta),
                        'r-',
                        lw=2,
                        alpha=0.6,
                        label=r'$\Gamma({},{})$'.format(k, theta))

        else:  # self.beta > 0
            if normalization:
                # Display the limiting distribution: Marcenko Pastur
                x = np.linspace(1e-2, np.max(points) + 0.3, 100)
                ax.plot(x,
                        rm.marcenko_pastur_law(x, M, N),
                        'r-',
                        lw=2,
                        alpha=0.6,
                        label=r'$f_{Marcenko-Pastur}$')

        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)
Ejemplo n.º 2
0
    def test_marcenko_pastur_for_laguerre_ensemble_full_model(self):
        """
        """

        M = 2 * self.N
        supp = (1 + np.array([-1, 1]) * np.sqrt(self.N / M))**2

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

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

        for beta in (1, 2, 4):

            le = be.LaguerreEnsemble(beta)

            for _ in range(self.nb_samples):
                le.sample_full_model(size_N=self.N, size_M=M)

                vals, _ =\
                    np.histogram(le.normalize_points(le.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))
Ejemplo n.º 3
0
 def limiting_distribution(x):
     return rm.marcenko_pastur_law(x, M, N)