Пример #1
0
 def __call__(self, key, E, P):
     k, ko, faus = key
     ax = self.ax
     if self.init_incomplete:
         if self.plot_u or 'f' == faus:
             self.init_incomplete = False
             msft = abs(self.msft[key])
             sprd = self.sprd[key]
             if np.any(np.isinf(msft)):
                 not_available_text(ax, "Spectral stats not finite")
                 self.is_active = False
             else:
                 self.line_msft, = ax.plot(msft, 'k', lw=2, label='Error')
                 self.line_sprd, = ax.plot(sprd,
                                           'b',
                                           lw=2,
                                           label='Spread',
                                           alpha=0.9)
                 ax.get_xaxis().set_major_locator(MaxNLocator(integer=True))
                 ax.legend()
     else:
         msft = abs(self.msft[key])
         sprd = self.sprd[key]
         self.line_sprd.set_ydata(sprd)
         self.line_msft.set_ydata(msft)
     # ax.set_ylim(*d_ylim(msft))
     # ax.set_ylim(bottom=1e-5)
     ax.set_ylim([1e-3, 1e1])
Пример #2
0
    def __init__(self, fignum, stats, key0, plot_u, E, P, **kwargs):
        fig, ax = place.freshfig(fignum, figsize=(6, 3))
        ax.set_xlabel('Sing. value index')
        ax.set_yscale('log')
        self.init_incomplete = True
        self.ax = ax
        self.plot_u = plot_u

        try:
            self.msft = stats.umisf
            self.sprd = stats.svals
        except AttributeError:
            self.is_active = False
            not_available_text(ax, "Spectral stats not being computed")
Пример #3
0
    def __call__(self, key, E, P):
        k, ko, faus = key
        if 'a' == faus:
            w = self.stats.w[key]
            N = len(w)
            ax = self.ax

            self.is_active = N < 10001
            if not self.is_active:
                not_available_text(ax, 'Not computed (N > threshold)')
                return

            counted = w > self.bins[0]
            _ = [b.remove() for b in self.hist]
            nn, _, self.hist = ax.hist(w[counted], bins=self.bins, color='b')
            ax.set_ylim(top=max(nn))

            ax.set_title(
                'N: {:d}.   N_eff: {:.4g}.   Not shown: {:d}. '.format(
                    N, 1 / (w @ w), N - np.sum(counted)))
Пример #4
0
    def __init__(self, fignum, stats, key0, plot_u, E, P, **kwargs):

        GS = {'height_ratios': [4, 1], 'hspace': 0.09, 'top': 0.95}
        fig, (ax, ax2) = place.freshfig(fignum,
                                        figsize=(5, 6),
                                        nrows=2,
                                        gridspec_kw=GS)

        if E is None and np.isnan(
                P.diag if isinstance(P, CovMat) else P).all():
            not_available_text(ax, ('Not available in replays'
                                    '\ncoz full Ens/Cov not stored.'))
            self.is_active = False
            return

        Nx = len(stats.mu[key0])
        if Nx <= 1003:
            C = np.eye(Nx)
            # Mask half
            mask = np.zeros_like(C, dtype=np.bool)
            mask[np.tril_indices_from(mask)] = True
            # Make colormap. Log-transform cmap,
            # but not internally in matplotlib,
            # so as to avoid transforming the colorbar too.
            cmap = plt.get_cmap('RdBu_r')
            trfm = mpl.colors.SymLogNorm(linthresh=0.2,
                                         linscale=0.2,
                                         base=np.e,
                                         vmin=-1,
                                         vmax=1)
            cmap = cmap(trfm(np.linspace(-0.6, 0.6, cmap.N)))
            cmap = mpl.colors.ListedColormap(cmap)
            #
            VM = 1.0  # abs(np.percentile(C,[1,99])).max()
            im = ax.imshow(C, cmap=cmap, vmin=-VM, vmax=VM)
            # Colorbar
            _ = ax.figure.colorbar(im, ax=ax, shrink=0.8)
            # Tune plot
            plt.box(False)
            ax.set_facecolor('w')
            ax.grid(False)
            ax.set_title("State correlation matrix:", y=1.07)
            ax.xaxis.tick_top()

            # ax2 = inset_axes(ax,width="30%",height="60%",loc=3)
            line_AC, = ax2.plot(arange(Nx), ones(Nx), label='Correlation')
            line_AA, = ax2.plot(arange(Nx), ones(Nx), label='Abs. corr.')
            _ = ax2.hlines(0, 0, Nx - 1, 'k', 'dotted', lw=1)
            # Align ax2 with ax
            bb_AC = ax2.get_position()
            bb_C = ax.get_position()
            ax2.set_position([bb_C.x0, bb_AC.y0, bb_C.width, bb_AC.height])
            # Tune plot
            ax2.set_title("Auto-correlation:")
            ax2.set_ylabel("Mean value")
            ax2.set_xlabel("Distance (in state indices)")
            ax2.set_xticklabels([])
            ax2.set_yticks([0, 1] + list(ax2.get_yticks()[[0, -1]]))
            ax2.set_ylim(top=1)
            ax2.legend(frameon=True,
                       facecolor='w',
                       bbox_to_anchor=(1, 1),
                       loc='upper left',
                       borderaxespad=0.02)

            self.ax = ax
            self.ax2 = ax2
            self.im = im
            self.line_AC = line_AC
            self.line_AA = line_AA
            self.mask = mask
            if hasattr(stats, 'w'):
                self.w = stats.w
        else:
            not_available_text(ax)